0

below code works correctly in Debug mode, but in Release, the GetProcAddress seems return NULL, but I can't debug the release mode code, Why it doesn't work with Release mode?

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

I also find, below code works in both Debug and Release mode:

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);
}
frank
  • 1,252
  • 1
  • 12
  • 17
  • Verify that `DogCheck.dll` is actually loaded. Verify that `CheckTheLicense` function exists in release version of `DogCheck.dll`. Maybe there exists a function with similar name, but not identical? – Dialecticus Jun 18 '13 at 15:24
  • Did you try to step with debugger? – Roman R. Jun 18 '13 at 15:35
  • You're using [reserved identifiers](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier). – chris Jun 18 '13 at 15:36
  • Actually, The DogCheck.dll is developed with Delphi, so whatever the mode the current code use, the DogCheck.dll are always same. I just changed the build mode of my code, I did NO changes to the DogCheck.dll. That is to say, the same DogCheck.dll, but the code above is built with different mode. I also try to set break point to the code, but unfortunately, it is built with Release mode, so the break point is not hited. – frank Jun 18 '13 at 15:46
  • 1
    Is `_DllHandle` initialized to NULL before running this code? And same for the other pointers. – interjay Jun 18 '13 at 16:00
  • Yes, I initialize them as NULL at the constructor of the class – frank Jun 19 '13 at 02:18

0 Answers0