CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 1999
    Location
    Roswell, GA
    Posts
    73

    The stack, AfxLoadLib and HWnd?



    Why can I not pass an HWND* just like any other pointer to my dll?

    Here is the guts of my dll, it does nothing with the HWND.

    extern "C" bool Func1(HWND* pMy)

    {

    bool bReturn = TRUE;

    AfxMessageBox("Func1 active"

    return bReturn;

    }//Is_RTF_Control_Available

    This is my one line def file entry

    EXPORTS

    Func1 @1

    As you can see from the code of my Func1 I allocate no memory and I do nothing with the HWND*.

    This is my calling function.

    void CTestExeDlg::OnOK()

    {

    typedef bool (CALLBACK* TestDll) (HWND*);//( );

    bool bResult;

    TestDll pFunc1 = NULL;

    HINSTANCE hInstance = LoadLibrary("TestDll.dll"

    if(hInstance) {

    pFunc1 = (TestDll) GetProcAddress(hInstance,"Func1"

    if(pFunc1)

    bResult = pFunc1(&m_hWnd);

    }

    AfxMessageBox("Returned"

    if(hInstance){

    AfxFreeLibrary(hInstance);

    AfxMessageBox("Frreed"

    }

    CDialog::OnOK();

    }

    This code works perfect in debug mode, but the stack gets corrupted in release mode. Does anybody know why?

    Thanks.





  2. #2
    Join Date
    Mar 1999
    Location
    Roswell, GA
    Posts
    73

    The stack, AfxLoadLib and HWnd?



    Why can I not pass an HWND* just like any other pointer to my dll?

    Here is the guts of my dll, it does nothing with the HWND.

    extern "C" bool Func1(HWND* pMy)

    {

    bool bReturn = TRUE;

    AfxMessageBox("Func1 active"

    return bReturn;

    }//Is_RTF_Control_Available

    This is my one line def file entry

    EXPORTS

    Func1 @1

    As you can see from the code of my Func1 I allocate no memory and I do nothing with the HWND*.

    This is my calling function.

    void CTestExeDlg::OnOK()

    {

    typedef bool (CALLBACK* TestDll) (HWND*);//( );

    bool bResult;

    TestDll pFunc1 = NULL;

    HINSTANCE hInstance = LoadLibrary("TestDll.dll"

    if(hInstance) {

    pFunc1 = (TestDll) GetProcAddress(hInstance,"Func1"

    if(pFunc1)

    bResult = pFunc1(&m_hWnd);

    }

    AfxMessageBox("Returned"

    if(hInstance){

    AfxFreeLibrary(hInstance);

    AfxMessageBox("Frreed"

    }

    CDialog::OnOK();

    }

    This code works perfect in debug mode, but the stack gets corrupted in release mode. Does anybody know why?

    Thanks.





  3. #3
    Join Date
    Mar 1999
    Posts
    6

    Re: The stack, AfxLoadLib and HWnd?





    The client an the server use different calling conventions. The server use __cdecl and the client use __stdcall. Remove "CALLBACK" in your typedef and your code should work.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured