0

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());
    }

}

A23149577
  • 2,045
  • 2
  • 40
  • 74

1 Answers1

1

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 );
Christian Garbin
  • 2,512
  • 1
  • 23
  • 31
  • FUNC1 gets char * PIN input and return an integer to int *retVal, I changed the calling function as you mentioned and I encountered the error : The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. – A23149577 Feb 09 '13 at 13:10