Changing a char pointer via DLL
I would like to pass 2 char pointers to my DLL (input_buffer,output_buffer) and obtain the output in my API via the output buffer.
Is this doable ? My working sample code below tells me otherwise. Is writing the output buffer to a file the only option.
Source code
---------------
[code]
/* filename: mock_test.c */
#include <stdio.h>
char *var1="Hello World";
int main()
{
int err = 0;
printf ("Original value of var1 : %s\n", var1);
err = DLL_API (var1);
printf ("Altered value of var1 : %s\n", var1);
return err;
}
[\code]
DLL:
Code:
/* Mock DLL to modify a char array */
/* filename: mock_dll.c*/
#include <stdio.h>
char *text="Ah.. Hey! there";
int
DLL_API(var1)
{
var1=text;
printf ("DLL: var1 : %s\n", var1);
return 0;
}
Output:
---------
$ gcc -c mock_dll.c -g && gcc -Wall -shared -g -o mock_dll.dll mock_dll.o && gc
c -o mock_test mock_test.c -g -L ./ -lmock_dll
mock_dll.c: In function `DLL_API':
mock_dll.c:9: warning: assignment makes integer from pointer without a cast
$ ./mock_test
Original value of var1 : Hello World
DLL: var1 : Ah.. Hey! there
Altered value of var1 : Hello World