Application loads the regular dll. Each function in this dll contains AFX_MANAGE_STATE(AfxGetStaticModuleState()). In the preprocessor definitions included macro _USRDLL and _AFXDLL. For example, export function from regular dll (mydll.dll):
BOOL RM_GetModule(IRMPage** ppInterface)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
HINSTANCE hInst = AfxGetInstanceHandle(); //**return NULL**
........
}
application:
BOOL CReMain2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
..........
HINSTANCE hmCurrentModule;
if((hmCurrentModule = AfxLoadLibrary("mydll.dll"))){
(FARPROC&)pPageItem->pfGetModule = GetProcAddress(
hmCurrentModule, "RM_GetModule");
pPageItem->pfGetModule(&(pPageItem->pPage)); //call
..........
}
}
The project was transferred out of 6 studios at 2010. At 6 AfxGetInstanceHandle() return correct value. GetLastError() return 0. Why AfxGetInstanceHandle() return NULL? How to fix it? vs2010_sp1, win7_x64
The best way is to store the handle you receive as parameter in DllMain in a global variable, or, in case it's an MFC dll, it should already be stored in CWinApp::m_hInstance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With