Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!
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. Why AfxGetInstanceHandle() return NULL? How to fix it?
vs2010_sp1, win7_x64
Posted
Updated 12-Dec-11 3:20am
v2
Comments
Albert Holguin 12-Dec-11 9:26am    
Weird thing is the function definition in MSDN doesn't say what a NULL return means... Have you tried GetLastError() to see if you're getting an error that makes some sort of sense?
JackDingler 12-Dec-11 11:44am    
Does your DLL Main derive from CWinApp or CWinAppEx?
2rock100 12-Dec-11 13:21pm    
CWinApp
JackDingler 12-Dec-11 13:58pm    
There's not much to go on there.

To solve issues with upgrades, I use the code wizard to generate the framework in a test directory, and then compare the code it generated against the original code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900