下面的代码在Debug模式下正常工作,但是在Release中,GetProcAddress似乎返回NULL,但是我无法调试发布模式代码,为什么它不适用于Release模式?
SetString("Library Init Error");
if (_DllHandle == NULL)
{
_DllHandle = LoadLibrary("DogCheck.dll");
}
if (_CheckFunc == NULL && _DllHandle != NULL)
{
_CheckFunc = (CheckTheLicense)GetProcAddress(_DllHandle, "CheckTheLicense");
}
if (_CloseCheckFunc == NULL && _DllHandle != NULL)
{
_CloseCheckFunc = (CloseCheckTheLicense)GetProcAddress(_DllHandle, "CloseCheckTheLicense");
}
if (_CheckFunc != NULL && _CloseCheckFunc != NULL)
{
PCHAR result = _CheckFunc();
SetString(result);
_CloseCheckFunc(result);
}
else
{
if (_DllHandle == NULL)
{
SetString("DLL NULL");
}
else
{
if (_CheckFunc == NULL)
{
SetString("_CheckFunc NULL");
}
}
}
我也发现,下面的代码在Debug和Release模式下都有效:
HINSTANCE dllHandle = LoadLibrary("DogCheck.dll");
if (dllHandle != NULL)
{
CheckTheLicense func = (CheckTheLicense)GetProcAddress(dllHandle, "CheckTheLicense");
if (func != NULL)
{
PCHAR result = func();
SetString(result);
CloseCheckTheLicense funcClose = (CloseCheckTheLicense)GetProcAddress(dllHandle, "CloseCheckTheLicense");
if (funcClose != NULL)
{
funcClose(result);
}
}
FreeLibrary(dllHandle);
}