简体   繁体   中英

passing arguments to funcyion in dll C++

Im getting garbage value in function in dll.

in FUNC1(int) im getting garbage value, any help??

.h of dll

class __declspec(dllexport) Class1
    {
    public:
          bool __stdcall FUNC1(int);
}

FUNC1 definition

bool Class1::FUNC1(int i)
{
//here im getting i as some garbage value
   (500==i) ? return true: return false;
}

this is how im calling FUNC1

FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),FUNC1); 
        if(lpfnGetProcessID == NULL) 
        {
            return false;
        }

        typedef int (__stdcall * pICFUNC)(int);
        pICFUNC dllFunc;
        dllFunc = pICFUNC(lpfnGetProcessID); 

        int op = dllFunc(500);

FUNC1 is declared as a function, but the definition is a method of "Class". Since they don't match, the implementation will expect to have a this pointer and a parameter on the stack. The caller is only pushing the i parameter, the implementation will be looking for it at the incorrect memory location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM