Afxcurrentresourcehandle null error

afxcurrentresourcehandle null error

NULL); // here return afxCurrentResourceHandle; }. What's the problem with it? Still the error remains. windows mfc atl. inl: ASSERT(afxCurrentResourceHandle!= NULL);. I check and find afxCurrentResourceHandle is NULL. What is the problem and how to solve it? I encountered a problem when calling domodal In the DLL dialog box yesterday. The error is sprers.eu's 22 NULL); Return afxcurrentresourcehandle ;}. afxcurrentresourcehandle null error

watch the video

Cannot read property 'addEventListener' of null

Afxcurrentresourcehandle null error - apologise, but

All too often I see one of these asserts fire:

ASSERT(afxCurrentInstanceHandle != NULL) ASSERT(afxCurrentResourceHandle != NULL); ASSERT(afxCurrentAppName != NULL);

These are coded in sprers.eu, and are part of the MFC high level accessors:

AfxGetInstanceHandle() AfxGetResourceHandle() AfxGetAppName()

If these asserts fire for you too, there’s a good chance you’re missing some afx module state management code.

Module States – Purpose

Most Win32 GUI functionality accesses resources in one way or another, and thus requires a resource handle. For example, MFC’s CDialog::DoModal() includes essentially the following calls:

… hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG); HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG); hDialogTemplate = LoadResource(hInst, hResource); …

Where hInst is an HINSTANCE obtained from either the currently running exe or the currently running dll.

Which poses the problem: which one?

I.e., any binary in the address space can contain resources. Should the dialog-creation code search the dialog resource at the executable, or one of the dll’s? How would the code know?

A user of native Win32 API is on his own here, and must explicitly create resource handles from loaded binaries, manage their lifetime and choose the proper one when actual resources are required. MFC pioneers had the noble intention of masking this madness from their users, and thus the AFX_MODULE_STATE apparatus was born: a module state is &#; roughly put &#; a wrapper around all binary-specific-data (e.g. resource handle) that is to be switched upon any call from one binary into another.

Note that module states include much more than resource handles (check afxstate_.h and see), but resource management does seem to be the canonical usage – actually the only usage for me personally.

Module States – Basic Usage

Module-data management wasn’t thoroughly hidden away from the developer, but the coding involved was indeed reduced to a minimum. The most succinct description I know is part of the wizard-generated code for an MFC dll:

//TODO: If this DLL is dynamically linked against the MFC DLLs,
// any functions exported from this DLL which call into
// MFC
must have the AFX_MANAGE_STATE macro added at the
// very beginning of the function.
//
// For example:
//
// extern &#;C&#; BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.

So it boils down to a single declaration at the start of a function:

AFX_MANAGE_STATE(AfxGetStaticModuleState());

This is classical RAII usage: the macro generates an object, whose ctor and dtor perform substitution of the module state into a specified slot (more on this slot in later posts). The resulting code is not only compact &#; albeit admittedly cryptic &#; but also exception safe.

‘Functions which call into MFC’ is a bit of a broad phrasing (surely CString usage isn’t considered ‘calling into MFC’). I understand this wording as ‘functions which make GUI calls’.

This single line of code is the only documented way of managing state, which makes one wonder why AfxGetStaticModuleState wasn’t baked into the AFX_MANAGE_STATE macro in the first place. More on this – in the next post.

Like this:

LikeLoading

Related

This entry was posted in MFC. Bookmark the permalink.

Thread: afxCurrentResourceHandle == NULL

  1. August 8th, ,  PM#1

    afxCurrentResourceHandle == NULL

    I have a DLL that has a function which pops up a dialog. That function calls AFX_MANAGE_STATE(AfxGetStaticModuleState()) and it works fine when I am calling it from a different DLL.

    I created a new dialog-based application which also uses the DLL and tried to call the same function and the DoModal fails on ASSERT(afxCurrentResourceHandle != NULL)

    any ideas?


  2. August 8th, ,  PM#2

    Re: afxCurrentResourceHandle == NULL

    Are both DLLs used from the same program? In that case, the resource IDs may clash with each other. Try changing all resource IDs in your second DLL project (normally in resource.h).

    I'm not % sure of this, but give it a try!


  3. August 8th, ,  PM#3

    Re: afxCurrentResourceHandle == NULL

    no both DLL aren't called from the same program. We have a big program that calls the DLL which calls the DLL with the DoModal and that works fine.

    My little app calls only the DLL with the DoModal and that doesn't work


  4. August 8th, ,  PM#4

    Re: afxCurrentResourceHandle == NULL

    Ok, but isn't that the same thing:

    sprers.eu --> dll_sprers.eu --> dll_sprers.eu

    They (DLLs) both share the same process space (sprers.eu). Try changing the resource IDs in dll_sprers.eu





    * * *
    Please rate my answer!


  5. August 8th, ,  PM#5

    Re: afxCurrentResourceHandle == NULL

    sprers.eu --> dll_sprers.eu --> dll_sprers.eu

    is working

    sprers.eu --> dll_sprers.eu is not working

    It's not a matter of duplicate ID's if that was all it was afxCurrentResourceHandle wouldn't be NULL

    anyway, I check for duplicates in the resource.h files and that isn't the case

    Neil


  6. August 8th, ,  PM#6

    Re: afxCurrentResourceHandle == NULL

    call the following functions before the DoModal()
    HINSTANCE hPrevInstance = AfxGetResourceHandle();
    AfxSetResourceHandle(Dll2_InstanceHandle);

    //Call DoModal

    AfxSetResourceHandle(hPrevInstance);

    thanks,
    sprers.eu


  7. August 9th, ,  AM#7

    Re: afxCurrentResourceHandle == NULL

    where do I get Dll2_InstanceHandle?


  8. August 9th, ,  AM#8

    Re: afxCurrentResourceHandle == NULL

    shouldn't AFX_MANAGE_STATE(AfxGetStaticModuleState()) be taking care of that?


  9. August 9th, ,  PM#9

    Re: afxCurrentResourceHandle == NULL

    You can it from you DllMain(). the first parameter is the InstantHandle. store the handle to global variable. so that you can use the handle.

    thanks,
    sprers.eu


  10. August 9th, ,  PM#10

    Re: afxCurrentResourceHandle == NULL

    Actually what I originally posted wasn't correct.

    What I really am dealing with is a *.lib not a dll

    App1 uses Dll which links in LibWithDialog - works fine

    App2 links in LibWithDialog - this doesn't work, the dialog ASSERTs on afxCurrentResourceHandle != NULL


  11. August 9th, ,  PM#11

    Re: afxCurrentResourceHandle == NULL

    oops - Actually what I originally posted wasn't correct.

    What I really am dealing with is a *.lib not a dll

    App1 uses Dll which links in LibWithDialog - works fine

    App2 links in LibWithDialog - this doesn't work, the dialog ASSERTs on afxCurrentResourceHandle != NULL


  12. January 18th, ,  AM#12

    Exclamation Re: afxCurrentResourceHandle == NULL

    Check if the main program and library have same compile option.

    If the character set(multi-byte vs. unicode) does not match, this problem may happen.


  13. March 4th, ,  PM#13

    Re: afxCurrentResourceHandle == NULL

    This is a case of missing AFX_MANAGE_STATE statement.
    More details here:
    sprers.eu


Posting Permissions

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

Forum Rules




Speaking from AFX_MANAGE_STATE(AfxGetStaticModuleState())

When writing MFC DLL in the past, you would always see a prompt in the automatically generated code frame, and you need to add AFX_MANAGE_STATE(AfxGetStaticModuleState()) at the beginning of each output function. I have never understood the meaning of this, and have not done so, and the code works well, so it feels like a nonsense.
In recent projects, it is necessary to use MFC to generate the interface in the DLL. Only then I found that once the resources are placed in different dynamic libraries, and when they are mixed with multithreading, things become extremely complicated. Little knowledge is no longer enough to deal with. The program crashes inexplicably, the inexplicable ASSERT, the resources can not be loaded, why? Every time, always try, at the beginning of each thread, add AFX_MANAGE_STATE(AfxGetStaticModuleState()), or use AfxSetResourceHandler() in some places, and then the problem is solved, but I don’t really understand what it is. Anyway, I always feel that this solution is very uncomfortable, as if the problem will suddenly appear in the next second.
The day before yesterday, this problem was finally brought to its fullest. It took me several hours and no attempt was successful. This kind of thing happened at the critical time of the project, and I secretly vowed that I would never use MFC again. Just like in many movie plots, the matter was resolved in the end. This time I decided that I could no longer do that. I must understand this matter clearly.
Here, the question I encountered is how to make the interface code in the DLL use the resource of the DLL and how to load the dialog box with the IE control in the worker thread?
I asked my colleagues, how do they realize DLL resource switching? AFX_MANAGE_STATE(AfxGetStaticModuleState()) This is their answer. As recommended by Microsoft, it turns out to be that simple! Let's take a look, what does this code do?
#define AFX_MANAGE_STATE(p) AFX_MAINTAIN_STATE2 _ctlState(p);
AFX_MAINTAIN_STATEAFX_MAINTAIN_STATE2(AFX_MODULE_STATE* pNewState)
{
    m_pThreadState = _afxThreadState;
    m_pPrevModuleState = m_pThreadState->m_pModuleState;
    m_pThreadState->m_pModuleState = pNewState;
}
_AFXWIN_INLINE AFX_MAINTAIN_STATE~AFX_MAINTAIN_STATE2()
{  m_pThreadState->m_pModuleState = m_pPrevModuleState; }
It turns out that it is to define a local object, and use its structure and destructor to switch the State state at the entry and exit of the function. I guess AfxGetStaticModuleState() must be the DLL where the current code is obtained. State.
Sure enough, please see
static _AFX_DLL_MODULE_STATE afxModuleState;
AFX_MODULE_STATE* AFXAPI AfxGetStaticModuleState()
{
    AFX_MODULE_STATE* pModuleState = &afxModuleState;
    return pModuleState;
}
class _AFX_DLL_MODULE_STATE : public AFX_MODULE_STATE
//AFX_MODULE_STATE (global data for a module)
class AFX_MODULE_STATE : public CNoTrackObject
{

    CWinApp* m_pCurrentWinApp;
    HINSTANCE m_hCurrentInstanceHandle;
    HINSTANCE m_hCurrentResourceHandle;
    LPCTSTR m_lpszCurrentAppName;
    BYTE m_bDLL;   //TRUE if module is a DLL, FALSE if it is an EXE

    COccManager* m_pOccManager;

have to say here that MFC piles up a lot of data here, which is very complicated and has very poor structure .
}
afxModuleState is a static member of the dll. It can be accessed by the code in the same dll, but when is it initialized?
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID/*lpReserved*/)
{

        AfxWinInit(hInstance, NULL, _T(""), 0);

}
BOOL AFXAPI AfxWinInit(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine, int nCmdShow)
{
    ASSERT(hPrevInstance == NULL);
    //handle critical errors and avoid Windows message boxes
    SetErrorMode(SetErrorMode(0)

McNeel Forum

Thank you very much to both.
I’ll get inside the documentation by Microsoft and try some more code in order to solve the issue. I’ll be back after I will try. In the meantime some more info and considerations.

My MFC extension DLLs are liked between themselves and are usually linked by my main applications, which up to now have been Win32 MFC applications (exe).

Presently, Rhino loads the plugin, and the plugin calls some functions and uses some objects defined in the MFC extension DLLs. What is surprising is that the Plugin is loaded, and so the MFXEXT dlls (if some miss the plugin is not loaded by Rhino), and some part of the stuff is correctly done (for instance, serialization of CObject derived classes). It is not a crash from the start.
The problem, yes, seems to be related to dialog opening. However, the debugging behaviour of the program is different by the release behavior. In release a first dialog opens correctly and then I have the crash after pressing OK. When debugging the ASSERT is got before opening the dialog (sprers.eul() stuff).
I think that some sort of workaround must be found, because it’s too important to save and reuse already existing and quite much tested code.
For instance, my very first plug in would add to Rhino the ability to read a 18,+ cross section archive, also using filters and design criteria, and then to generate 3D members easily. Having in mind civil engineering issues (especially in the field of steel structures) this is a quite interesting Plugin. Isn’t it? I dare say it is.
If this works, then quite a number of interesting issues open. Really. I am thinking to steel connections issues, which I have so much worked about.

I’ll read, study and try, and later go back. Thank you everybody for your precious help.

Also, as it is the very first time I use 64 bit programming, I wonder if some 32 to 64 porting issue might be responsible. I don’t think so. My code should be relatively safe, I guess (but… I know that 32 to 64 is always a problem to be faced not just by a simple recompilation, perhaps I have been too optimistic).
Paolo

SEM_FAILCRITICALERRORS

The reason for this error is due to the use of certain resources in the MFC library, but MFC has not been initialized.

 This situation mostly occurs in atl and other non-MFC projects, and the additional MFC header file is partially supported.

Phenomenon: 1) Compilation can be passed 2) Some MFC classes can be used 3) ASSERT (afxCurrentResourceHandle! = NULL) error occurs when using CRectTracker, sprers.eunu

Solution:

After the module is initialized, add the following code before the MFC class to be used:

 // !!!! MFC initialization
   if(!AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0))
   {
     //??_sprers.eunt(_T("MFC initialization error! "), EVENTLOG_ERROR_TYPE);
     return 1;
   }

 

This article is from the CSDN blog, please indicate the source for reprint: sprers.eu

 

When using MFC in dll, afxCurrentResourceHandle = NULL will cause the dialog box to call AfxGetResourceHandle () method assertion failure when created. To solve this problem, you need to call the following method before the program uses the MFC class.

AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0);

sprers.eum/blog/static//

Hi, Orhun,

now I see what is going wrong 🙂

AfxGetModuleState()->m_hCurrentResourceHandle

usually, the ::Afx functions will return the handles (or whatever)
of the running MAIN task !
This means, from the sprers.eu task, not from your running Dll (arx).
Also, it might be possible, that
AfxGetModuleState()->m_hCurrentResourceHandle
needs the MANAGE_STATE macro

But forget about that

The only chance to get the real Resource Instance for a Dll/Arx is from the
DllMain call - the first parameter is your Resource Handle in fact.

That resource handle should be stored to a global variable,
and then you can use this saved resource handle in the given sequence :
(from the previous thread)

HINSTANCE hOldResource = ::AfxGetResourceHandle();
// the currently used Win Resource handle
// usually Acad's but not nessecarily !!
::AfxSetResourceHandle(myOwnResourceHandle);
// you must catch your resource handle from
//DllMain (hInstance, ), save the hInstance !
:
:
your declarations, code etc.


::AfxSetResourceHandle(hOldResource);

Don't worry - this code really works !
Please try this, I'm sure it will run fine

Greetings
Torsten

Failed to create window in MFC dynamic link library (DLL)

I wrote a project about the network in my graduation project. I encapsulated the WSAAsyncSelect network model in a dynamic link library on the client side. Clicked to run. It was found in the UI thread that the program reported an error when creating a CFrameWnd window. ASSERT(afxCurrentResourceHandle!= NULL) Assertion error.

I found a lot of information on the Internet, and I found the answer in the comments that came with MFC.

////TODO: If this DLL is dynamically linked with respect to the MFC DLL, afxcurrentresourcehandle null error, //any function called into the MFC exported from this DLL must add the AFX_MANAGE_STATE macro to the front of the//function. ////For example: ////extern "C" BOOL PASCAL EXPORT ExportedFunction() //{ //AFX_MANAGE_STATE(AfxGetStaticModuleState()); ////Here is the normal function body //} ////this It is important that macros appear in every function before any MFC call. This means that //it must appear as the first statement //in the functioneven before all object variable declarations, //this is because their constructor may generate MFC //DLL calls, afxcurrentresourcehandle null error. ////For additional details, //please refer to MFC Technical Notes 33 and //

Test it yourself

SEM_NOOPENFILEERRORBOX);// set resource handles AFX_MODULE_STATE* pModuleState = AfxGetModuleState(); pModuleState->m_hCurrentInstanceHandle = hInstance; pModuleState->m_hCurrentResourceHandle = hInstance; pModuleState->CreateActivationContext();//








fill in the initial state for the application
CWinApp* pApp = AfxGetApp();if (pApp != NULL) {// Windows specific initialization (not done if no CWinApp) pApp->m_hInstance = hInstance; hPrevInstance; // Obsolete. pApp->m_lpCmdLine afxcurrentresourcehandle null error lpCmdLine; pApp->m_nCmdShow = nCmdShow; pApp->SetCurrentHandles(); }// initialize thread specific data (for main thread)if (!afxContextIsDLL) AfxInitThread();// Initialize CWnd::m_pfnNotifyWinEvent













HMODULE hModule = ::GetModuleHandle(_T("userdll"));if (hModule != NULL) { CWnd::m_pfnNotifyWinEvent = (CWnd::PFNNOTIFYWINEVENT)::GetProcAddress(hModule, "NotifyWinEvent"); }return TRUE; }





it seems that the first time initializatio is called from the afxcurrentresourcehandle null error which maybe the core dll for mfc, and the second time initialization is called rom my mfc dll, in the project, it is called 'sprers.eu'. I remember that the mfc core dll should be an extension dll, as to some deeper details and thoughts, I haven't got much yet.

and i find when the first assertion 'ASSERT(AfxGetModuleState() != AfxGetAppModuleState())' occurs,

the AfxGetModuleState() returns:

_AFX_THREAD_STATE* pState = _afxThreadState;
ENSURE(pState);
AFX_MODULE_STATE* pResult;if else {// otherwise, use global app state pResult = _sprers.eua(); } ENSURE(pResult != NULL);return pResult;







value: m_pObject 0xd4a48

the AfxGetAppModuleState() returns

  return _sprers.eua();

and its value: m_pObject 0xe4a48

0xd4a48 and 0xe4a48, afxcurrentresourcehandle null error, a little different. 


in AfxWinInit,

AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
pModuleState->m_hCurrentInstanceHandle error con winavi stats file not found hInstance;
pModuleState->m_hCurrentResourceHandle = hInstance;
pModuleState->CreateActivationContext();

the pModuleState is 'pResult = _sprers.eua();', and the address is 0xd4a48, it seems that the initialization goes to the _afxBaseModuleState variable

 

===================================== seperate line =========================================

 

In a project that I made up my own with clean code just using the CString class in mfc (all the initialization and module state switch process is right without the problems mentioned), I find that in function 'BOOL AFXAPI AfxWinInit(HINSTANCE hInstance, HINSTANCE hPrevInstance, __in LPTSTR lpCmdLine, int nCmdShow)',
BOOL AFXAPI AfxWinInit(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    __in Afxcurrentresourcehandle null error lpCmdLine, int nCmdShow)
{
    
    //set resource handles
    AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
    pModuleState->m_hCurrentInstanceHandle = hInstance;
    pModuleState->m_hCurrentResourceHandle = hInstance;
    pModuleState->CreateActivationContext();
    
    return TRUE;
}
the line 'AFX_MODULE_STATE* pModuleState = AfxGetModuleState();' returns the moduleState member variable in threadState, which in the dll where problems occurred, the function returns '_sprers.eua();'. What's more, pModuleState value in the clean dll points right to the global variable afxModuleSatet! But why moduleState member variable in threadState differs in two dlls? WHEN IS THE MDDULESTATE MEMBER IN THREADSTATE SET? I didn't see any init code for the threadState in the 'dllmains' I thus far track. So I decided to track the init process for threadState.
Moreever, in 'InternalDllMain', pState get from the sentence '_AFX_THREAD_STATE* pState = AfxGetThreadState();' already holds a right moduleState.
extern "C"
BOOL WINAPI InternalDllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID/*lpReserved*/)
{
    if (dwReason == DLL_PROCESS_ATTACH)
    {
        BOOL bResult = FALSE;
#ifdef _AFXDLL
        //wire up resources from core DLL
        AfxCoreInitModule();
#endif
        _AFX_THREAD_STATE* pState = AfxGetThreadState();
        AFX_MODULE_STATE* pPrevModState = pState->m_pPrevModuleState;
        //Initialize DLL's instance(/module) not the app's
       afxcurrentresourcehandle null error (!AfxWinInit(hInstance, NULL, _T(""), 0))
        {
            AfxWinTerm();
            goto Cleanup;      //Init Failed
        }
        
        return bResult;
    }
    
}


===================================== seperate line =========================================


I may have found the cause. In blog about the mfc module state(sprers.eu), afxcurrentresourcehandle null error is such words:
'AfxGetModuleState first obtains the m_pModuleState of _afxThreadState, If the m_pModuleState of the current Thread State returns NULL, indicating that the current ThreadState is not properly initialized (the usual reason is afxcurrentresourcehandle null error the CreateThread function sql state 22018 native error called instead of AfxBeginThread when the thread is created), use _afxBaseModuleState. '
My main project is written in Qt, which in fact was purely C++ with some marcros, libs, dlls and the moc generator. I guess the thread is created with CreateThread instead of AfxBeginThread, so the afxcurrentresourcehandle null error is not properly initialized. Consider that the way of thread creating cannot be modified in Qt, I decided to manually set the resource handle in my Dll export function, afxcurrentresourcehandle null error. The thought came to me when I saw the function specification 'HMODULE GetModuleHandle(PCTSTR pszModule);' run time error 429 in zombie smashers 'Windows Via C/C++' which returns a base address a module is loaded in the memory by the module name specified. Afxcurrentresourcehandle null error call it and set the resource handle with AfxSetResourceHandle and it seems to me now it is right, all the MFC funcitons work properly. Though the initialzation assertions still hang unresolved, as least it can run now.

 

The referenced posts are as follows:

sprers.eu HOWTO: How to Provide Your Own DllMain in an MFC Regular DLL
sprers.eu MFC status
sprers.eu MFC module status
sprers.eu MFC initialization process
sprers.eu The same problem
sprers.eu If you don’t understand it, please Learning, windows programming
sprers.eu Debug Assertion failed error while using an mfc dll via import library in an managed console application
sprers.eu Hosting of MFC MDI Applications from Afxcurrentresourcehandle null error WinForms and WPF Applications
sprers.eu Re: [Threads-devel] link problem: _pRawDllMain conflict issue

The reason for this error is due to the use of certain resources in the MFC library, but MFC has not been initialized.

 This situation mostly occurs in atl and other non-MFC projects, and the additional MFC header file is partially supported.

Phenomenon: 1) Compilation can be passed 2) Some MFC classes can be used 3) ASSERT (afxCurrentResourceHandle! = NULL) error occurs when using CRectTracker, sprers.eunu

Solution:

After the module is initialized, afxcurrentresourcehandle null error, add the following code before the MFC class to be used:

 // !!!! MFC initialization
   if(!AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0))
   {
     //??_sprers.eunt(_T("MFC initialization error! "), EVENTLOG_ERROR_TYPE);
     return 1;
   }

 

This article is from the CSDN blog, afxcurrentresourcehandle null error, please indicate the source for reprint: sprers.eu

 

When using MFC in dll, afxCurrentResourceHandle = NULL will cause the dialog box to call AfxGetResourceHandle () method assertion failure when created. To solve this problem, you need to call the following method before the program uses the MFC class.

AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0);

sprers.eum/blog/static//

MFC dll initialization process and errors about the module status

In the process of making an mfc dll, I encountered a tricky module status setting error, afxcurrentresourcehandle null error. I followed it for a long time, read many posts and books and finally solved the problem.

Since the first post was posted on codeguru, afxcurrentresourcehandle null error, I simply kept recording the whole process in English. My question is recorded as follows:

 

===================================== seperate line =========================================

 

I'm working on a project that's using a mfc regular dll from a Qt gui project(yes, you don't see wrong), the mfc dll code afxcurrentresourcehandle null error extracted from some other projects build entirely in mfc. I build all the mfc code with a regular dll and run it, and it came to the debug assertion during the initialization at the code:

     ASSERT(AfxGetModuleState() != AfxGetAppModuleState());

and

     VERIFY(AfxSetModuleState(AfxGetThreadState()->m_pPrevModuleState) == &afxModuleState);

furthermore, afxcurrentresourcehandle null error, when i ignore and continue running the programme, a debug assertion failed at the code:

     ASSERT(afxCurrentResourceHandle != NULL)

of course the resource handle is null.
I track down the source code, and it seems that during the initialization, the 'dllmain'(in fact there is a lot of 'dllmains') in my dll has been invoked twice and only the seconde time the assert has been emitted, the first time it has been running ok. and I notice that the members in the global variable afxModuleState has all been null thus cause the assertion after the initialization, and what's afxcurrentresourcehandle null error I notice that during the first time initialization, the afxModuleState has been assigned right.
I wonder what's the cause of my problem and how to solve it. And I'm willing to hear your advice.
an additional information is that, in my regular dll, afxcurrentresourcehandle null error, I use boost library(which I'm not too familiar with)

 

===================================== seperate line =========================================

 

after the first tip posted on codeguru and no reply, i tack source code of the mfc dll startup and the following it the details:
the fisrst time initialization call stack:

sprers.eu!AfxWinInit
sprers.eu!DllMain
sprers.eu!__DllMainCRTStartup
sprers.eu!_DllMainCRTStartup

the second time initialization call stack:

sprers.eu!InternalDllMain
sprers.eu!DllMain
sprers.eu!__DllMainCRTStartup
sprers.eu!_DllMainCRTStartup

the call stack when the assert 'ASSERT(AfxGetModuleState() != AfxGetAppModuleState())' occurs:

sprers.eu!AfxCoreInitModule
sprers.eu!InternalDllMain
sprers.eu!DllMain
sprers.eu!__DllMainCRTStartup
sprers.eu!_DllMainCRTStartup

in code

AFX_MODULE_STATE* AFXAPI AfxGetModuleState()
{
_AFX_THREAD_STATE* pState = _afxThreadState;
ENSURE(pState);
AFX_MODULE_STATE* pResult;if (pState->m_pModuleState != NULL) {// thread state's module state serves as override pResult = pState->m_pModuleState; } else {// otherwise, use global app state pResult = _sprers.eua(); } ENSURE(pResult != NULL);return pResult; }












the pState is different from the first symantec service framework error initialization(the afxcurrentresourcehandle null error time is not my mfc dll?), and all its value is null

the second time call stack:

sprers.eu!AfxWinInit
sprers.eu!InternalDllMain
sprers.eu!DllMain
sprers.eu!__DllMainCRTStartup
sprers.eu!_DllMainCRTStartup

and the AfxWinInit code:

   AFXAPI AfxWinInit BOOL (HINSTANCE hInstance, HINSTANCE hPrevInstance,
__in LPTSTR lpCmdLine, int nCmdShow)
{
ASSERT(hPrevInstance == NULL);// handle critical errors and avoid Windows message boxes SetErrorMode(SetErrorMode(0) SEM_FAILCRITICALERRORS

Thread: afxCurrentResourceHandle == NULL

  1. August 8th, ,  PM#1

    afxCurrentResourceHandle == NULL

    I have a DLL that has a function which pops up a dialog. That function calls AFX_MANAGE_STATE(AfxGetStaticModuleState()) and it works fine when I am calling it from a different DLL.

    I created a new dialog-based application which also uses the DLL and tried to call the same function and the DoModal fails on ASSERT(afxCurrentResourceHandle != NULL)

    any ideas?


  2. August 8th, ,  PM#2

    Re: afxCurrentResourceHandle == NULL

    Are both DLLs used from the same program? In that case, the resource IDs may clash with each other. Try changing all resource IDs in your second DLL project (normally in resource.h).

    I'm not % sure of this, but give it a try!


  3. August 8th, ,  PM#3

    Re: afxCurrentResourceHandle == NULL

    no both DLL aren't called from the same program. We have a big program that calls the DLL which calls the DLL with the DoModal and that works fine.

    My little app calls only the DLL with the DoModal and that doesn't work


  4. August 8th, ,  PM#4

    Re: afxCurrentResourceHandle == NULL

    Ok, but isn't that the same thing:

    sprers.eu --> dll_sprers.eu --> dll_sprers.eu

    They (DLLs) both share the same process space (sprers.eu). Try changing the resource IDs in dll_sprers.eu





    * * *
    Please rate my answer!


  5. August 8th, ,  PM#5

    Re: afxCurrentResourceHandle == NULL

    sprers.eu --> dll_sprers.eu afxcurrentresourcehandle null error dll_sprers.eu

    is working

    sprers.eu --> dll_sprers.eu is not working

    It's not a matter of duplicate ID's if that was all it was afxCurrentResourceHandle wouldn't be NULL

    anyway, I check for duplicates in the resource.h files and that isn't the case

    Neil


  6. August 8th, ,  PM#6

    Re: afxCurrentResourceHandle == NULL

    call the following functions before the DoModal()
    HINSTANCE hPrevInstance = AfxGetResourceHandle();
    AfxSetResourceHandle(Dll2_InstanceHandle);

    //Call DoModal

    AfxSetResourceHandle(hPrevInstance);

    thanks,
    sprers.eu


  7. August 9th, ,  AM#7

    Re: afxCurrentResourceHandle == NULL

    where do I get Dll2_InstanceHandle?


  8. August 9th, ,  AM#8

    Re: afxCurrentResourceHandle == NULL

    shouldn't AFX_MANAGE_STATE(AfxGetStaticModuleState()) be taking care of that?


  9. August 9th, ,  PM#9

    sql error 17090 sqlstate null afxCurrentResourceHandle == NULL

    You can it from you DllMain(). the first parameter is the InstantHandle. store the handle to global variable. so that you can use the handle.

    thanks,
    sprers.eu


  10. August 9th, afxcurrentresourcehandle null error, ,  PM#10

    Re: afxCurrentResourceHandle == NULL

    Actually what I originally posted wasn't correct.

    What I really am dealing with is a *.lib not a dll

    App1 uses Dll which links in LibWithDialog - works fine

    App2 links in LibWithDialog - this doesn't work, the dialog ASSERTs on afxCurrentResourceHandle != NULL


  11. August 9th, ,  PM#11

    Re: afxCurrentResourceHandle == NULL

    oops - Actually what I originally posted wasn't correct.

    What I really am dealing with is a *.lib not a dll

    App1 uses Dll which links in LibWithDialog - works fine

    App2 links in LibWithDialog - this doesn't work, the dialog ASSERTs on afxCurrentResourceHandle != NULL


  12. January 18th, ,  AM#12

    Exclamation Re: afxCurrentResourceHandle == NULL

    Check if the main program and library have same compile option.

    If the character set(multi-byte vs. unicode) does not match, this problem may happen.


  13. March 4th, ,  PM#13

    Re: afxCurrentResourceHandle == NULL

    This is a case of missing AFX_MANAGE_STATE statement.
    More details here:
    sprers.eu


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may oki c330dn error code 069 post attachments
  • You may not edit your posts
  •  

Forum Rules




1 Comments

Leave a Comment