Problems calling a function in a DLL
I have writtin some code to call a function inside a DLL.
I use LoadLibrary to load the DLL, I call GetProcAddress to get the address
of the function, and then I call the function. The function returns with out
a problem, and it does all the work (one of the arguments is a buffer which
the function fills in, another is a pointer to an int which contains the
amount of data filled in).
How ever right after I step out of the function I get a "user breakpoint
called from code ...". What did I miss?
Below is the code:
#include <windows.h>
#include <stdio.h>
main()
{
HINSTANCE sdll = LoadLibrary("testme.dll");
if (sdll == 0) {
fprintf(stderr, "Failed to load password seed module\n");
exit(-1);
}
typedef DWORD (WINAPI *tfn) (unsigned char *, unsigned int, unsigned int *);
tfn tproc;
unsigned char *data;
unsigned int len = 0;
unsigned int status = 0;
if ((data = (unsigned char *) calloc(1024, sizeof(unsigned char))) ==
NULL) {
fprintf(stderr, "Out of memory");
exit(-1);
}
tproc = (tfn) GetProcAddress(sdll, "GetData");
if (tproc == NULL) {
fprintf(stderr, "failed to get address\n");
exit(-1);
}
status = tproc(data, 1024, &len);
if (status != 0) {
fprintf(stderr, "Failed to retrieve seed data, DLL Function returned %d",
status);
exit(-1);
}
return 0;
}
and the dll code:
#include <stdio.h>
#include <windows.h>
extern "C" {
__declspec(dllexport) DWORD GetData(unsigned char *data,
unsigned int dataSize,
unsigned int *dataLen)
{
if (dataSize > 8) {
memcpy(data, "foobar12", 8);
*dataLen = 8;
} else {
memcpy(data, "foobar12", dataSize);
*dataLen = dataSize;
}
return 0;
}
};
Thanks!
Mike