Originally Posted by
matsp
The above solution with passing the address will solve that problem [And of course, it has absolutely nothing to do with DLL's - it would be exactly the same problem if the function was in the same file or linked statically to the executable].
--
Mats
Thanks Mats. However, passing the address as "&var1" did not work either. This is a version that actually works
Solution:
Code:
/* file: mock_test.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
extern void changeBuff(char *, char *);
*/
int main() {
char *buffer;
buffer = malloc (sizeof(char)*4);
strcpy(buffer,"abc");
printf ("original buffer value: %p %s\n",buffer,buffer);
changeBuff(buffer,"DEFG");
printf ("buffer value has beed changed to: %s\n",buffer,buffer);
}
/* file: mock_dll.c */
#include <stdio.h>
#include <string.h>
void changeBuff(char *buf, const char* newbuf) {
printf ("changing buffer now %p %s\n",buf, buf);
buf = realloc(buf, sizeof(char) * strlen(newbuf));
strcpy (buf,newbuf);
}