I am trying to use the srand and rand functions in a DLL, but for some reason I keep getting access violations (and this function worked before it was part of a DLL).
Here's a short example of my problem:
//this is the DLL
__declspec(dllexport) int Foo(char* str)
int len = strlen(str);
//if I change the following three lines to this:
//str = '^';
int num = rand()%len;
str[num] = '^';
I'm using VS.NET 2003 if that makes a difference.
typedef int (*MYDLLPROC)(char*);
char str = "Hello World!";
HMODULE hDLL = LoadLibrary("dllClassTest.dll");
Foo = (MYDLLPROC)GetProcAddress(hDLL,"Foo");
Foo(str); //access violation