In the DLL dialog box, the "Debug assertion failed" dialog box appears ",
I searched the internet and found that the module handle settings were incorrect. Then, solve the problem as follows:
1. Define two global variables:
Hinstance g_hmoduleinstance = NULL;
Hinstance g_holdmoduleinstance = NULL;
2. assign values to g_hmoduleinstance in the dllmain function:
G_hmoduleinstance = hinstance;
3. Create two function setting module handles in the class of the resource to use the dialog box.
Void calternatextractfun: setresourcehandle ()
{
G_holdmoduleinstance = afxgetmodulestate ()-
> M_hcurrentresourcehandle;
Afxgetmodulestate ()-> m_hcurrentresourcehandle = g_hmoduleinstance;
}
Void calternatextractfun: restoreresourcehandle ()
{
Afxgetmodulestate ()-> m_hcurrentresourcehandle
= G_holdmoduleinstance;
}
4. call these two functions in the functions of the resource in the dialog box:
Void calternatextractfun: Execute ()
{
Setresourcehandle ();
Calterextractdlg DLG;
DLG. domodal ();
Restoreresourcehandle ();
}
But this line has an error: Debug assertion failed!
Then Debug:
In the cdialog: domodal () function
Try
{
// Create Modeless Dialog
Afxhookwindowcreate (this );
If (createdlgindirect (lpdialogtemplate,
Cwnd: fromhandle
(Hwndparent), hinst ))
Run createdlgindirect (lpdialogtemplate,
Cwnd: fromhandle
(Hwndparent), hinst) This sentence appears debug assertion failed!
Then go to the createdlgindirect function:
Bool cwnd: createdlgindirect (lpcdlgtemplate lpdialogtemplate,
Cwnd * pparentwnd, hinstance hinst)
{
# Ifdef _ debug
If (afxgetapp ()-> iskindof (runtime_class (colecontrolmodule )))
{
Trace (traceappmsg, 0, "Warning: Creating dialog from
Within a colecontrolmodule application is not a supported scenario. \ n ");
}
# Endif
An error occurred in afxgetapp ()-> iskindof (runtime_class (colecontrolmodule.
Then search for the createdlgindirect function online. There is a saying on the Internet that
# Ifdef _ debug
If (afxgetapp ()-> iskindof (runtime_class (colecontrolmodule )))
{
Trace (traceappmsg, 0, "Warning: Creating dialog from
Within a colecontrolmodule application is not a supported scenario. \ n ");
}
# Endif
Is a bug in vs C ++ 2005 + SP1.Algorithm:
Wangjia184 (I am a legend ...... SB) 14:36:40 on
VC/mfc/basic questions
Let's talk about it first.Program Structure
This is a vs2005 plug-in, which belongs to the ATL
In ATL, It is implicitly linked to an mfc dll. In mfc dll, there is a dialog
I used the pirated vs2005 Chinese version without patching. Everything is normal
The system was reinstalled these two days, changed to the original version of vs2005, and patch SP1 (Beta ).
The problem arises!
When dialog domodal (), an error is returned.
The error stack is as follows:
Domodal () calls createdlgindirect ()
The start of createdlgindirect is as follows:
# Ifdef _ debug
If (afxgetapp ()-> iskindof (runddtime_class (colecontrolmodule
)))
{
Trace (traceappmsg, 0, "Warning: Creating dialog from
A colecontrolmodule application is not a supported
Scenario. \ n ");
}
# Endif
Afxgetapp returns NULL, and my DLL entry is dllmain. This afxgetapp will certainly return
Null
So an error is reported here.
Run with the release version. Everything works normally. It seems that this section was added with SP1.
I'm dizzy. Do I have to debug the release version in the future?
Number of questions: 50. replies: 5
I don't know how everyone thinks, but how can we solve my problems?
My compilation environment:
Win XP SP2
Vs C ++ 2005 + SP1
Intel dual-core processor
|
Reply to: sjdev |
2008-3-9 12:09:45 |
No subject
Holdhandle = afxgetresourcehandle ();
Afxsetresourcehandle (hdll );
...
Use the resource in the DLL
...
Afxsetresourcehandle (holdhandle );
|
Reply to: clever101 |
2008-3-9 12:11:55 |
Hdll? In this case, you have to loadlibrary first.
From: http://topic.okbase.net/200803/2008030911/3291771.html
reference: http://social.microsoft.com/Forums/en-US/visualcpluszhchs/thread/9e459adc-dc68-491a-8632-8cb23ef6566f