Click to See Complete Forum and Search --> : The stack, AfxLoadLib and HWnd?


phil
March 29th, 1999, 08:00 PM
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.

Phil
March 29th, 1999, 08:00 PM
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.

Dieter Gollwitzer
March 30th, 1999, 06:03 AM
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.