I have a DLL which I wrote using C++. I'm loading this DLL in another C++ (console) project during runtime by the use of LoadLibrary()
, and then accessing the function within the DLL by GetProcAddress()
.
Here's the DLL code:
SHARED_CLASS string hill(string inmode, string inkey, string xinpassword, string outpword);
And here's how I load and call the function:
typedef string(_cdecl* MYPROC)(string inmode, string inkey, string xinpassword, string outpword);
HMODULE hInst = LoadLibrary(TEXT("Cipher.dll"));
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
if (hInst == NULL)
{
cout << "NOT LOADED";
cout << "\n";
}
else
{
cout << "LOADED";
cout << "\n";
ProcAdd = (MYPROC)GetProcAddress(hInst, "hill");
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
passwordmew = (ProcAdd)("-e", "xxxxxx", "lcgoanhoehfogjdclkmdmlmb", passwordmew);
}
else
{
DWORD dwError = 0;
dwError = GetLastError();
}
}
I have no problem with loading and calling the function (it is calling the correct function), the issue comes when passing the parameters to the function, the value that is passed on to the function is not the same as the value when I called the function.
Inside the DLL function, I have this condition, If you can see in my code when I called the function I passed on "-e"
for the first parameter, supposedly it should fall into the if
condition, but instead it is falling into the else
condition. I debugged it and found that this is the same for all of the parameter values.
if (inmode == "-e")
{
//it should go here
}
else
{
//instead it goes here
}
The values being passed in appear to be in an array or something:
Any idea why?