Reputation: 2155
I have a weird problem in building my debug project. I have searched the web but unfortunately I have not found any clue yet.
I'm trying to load a dll in my console application project. My dll has several functions and I just want to call FUNC1 to check if this function works properly.
The declaration of FUNC1 in my dl is :
int FUNC1 (char *inVal, int *retVal)
I have successfully loaded the dll in my console application and I call the FUNC1 with function pointer as below:
int main()
{
HINSTANCE testInstance;
testInstance = LoadLibrary("Path\\to\\my.dll");
typedef int (WINAPI *FUNC1Ptr)(char *inVal, int *retVal);
if(testInstance == NULL)
{
printf("The dll is not loaded, Please check the path!\n");
}
else
{
printf("The dll is loaded successfully!!");
}
FUNC1Ptr FUNC1Lnk = (FUNC1Ptr)GetProcAddress(testInstance,"FUNC1");
if (!FUNC1tLnk)
{
FreeLibrary(testInstance);
printf("Error in getting function address!!\n");
}
else
{
int *ret = 0;
char *PIN = NULL;
PIN = "test";
int retVal1 = FUNC1Lnk( PIN, ret );
}
return 0;
}
PS. The violation is referred to free.c file in:
retval = HeapFree(_crtheap, 0, pBlock);
if (retval == 0)
{
errno = _get_errno_from_oserr(GetLastError());
}
}
Upvotes: 0
Views: 7082
Reputation: 2532
How is FUNC1
using the pointers? It may not like that the int *
passed to it is null.
Try this (have an actual integer type - not pointer - and take its address):
int ret = 0;
char *PIN = NULL;
PIN = "test";
int retVal1 = FUNC1Lnk( PIN, &ret );
Upvotes: 1