GetProcAddress Issue
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: GetProcAddress Issue

  1. #1
    Join Date
    Nov 2010
    Posts
    4

    GetProcAddress Issue

    Hi All,
    I am getting an access violation when executing a function that was dynamically loaded from a dll. A pointer to std::map is passed as a parameter to the function, and when calling the map::find() method in the dll, there is a crash. I use visual studio 6.
    This is the code that loads the dll and execute the function:

    ###################################
    typedef BOOL (__cdecl *DllFunction)(LPVOID);
    typedef map<CL_STRING, CL_STRING> MAP_PARAMETER_VALUE;

    HMODULE hModule = LoadLibrary("GA.dll");
    if (hModule)
    {
    DllFunction pExecuteFunc = NULL;
    pExecuteFunc = (DllFunction)GetProcAddress(hModule, "GAFunc");
    if (pExecuteFunc)
    {
    MAP_PARAMETER_VALUE mapContextParams
    BOOL bRes = pExecuteFunc( &mapContextParams );
    }
    }
    ###################################

    In the dll project, I declared a .def file that looks like this:

    LIBRARY "GA"

    EXPORTS
    GAFunc
    ###################################

    The function in the dll is declared:

    #define DllExport __declspec( dllexport )

    DllExport BOOL __cdecl GAFunc(IN LPVOID contextParams)
    {
    MAP_PARAMETER_VALUE* pMapParams = (MAP_PARAMETER_VALUE*)contextParams;
    CL_STRING strParamName("SomeKey");

    // The following line causes the access violation!!!
    MAP_PARAMETER_VALUE::iterator paramFound = pMapParams->find(strParamName);
    return TRUE;
    }

    ####################################

    Class CL_STRING is declared and overrides operator <,>,<=,>=,==,=,!=. It also overrides copy constructor.

    If the GAFunc gets a parameter which is a pointer to char (LPSTR) it works fine.

    I look at the memory of contextParams before passing it to the dll, and after, and it points to the same memory address, but in the dll I see that _Nil filed is NULL, and that what eventually causes the crash.

    What am I missing here? Why is the _Nil field changing?
    Thanks,

    Adi

  2. #2
    Join Date
    Nov 2003
    Posts
    1,797

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center