WooJin

I'm trying to create a dialog manually by calling CDialog::Create().
The problem is, CDialog::Create() doesn't recognize my resource ID and it fails to create one.

This is the actual code.

CNeffyDlg dlg;
dlg.Create(IDD_NEFFY_DIALOG);
dlg.ShowWindow(SW_SHOW);

It fails on dlg.Create(IDD_NEFFY_DIALOG). To be detail, debug assertion fails on this method and the process terminates.

I've followed the function calls and this is the abstract call chain. (sorry for the mess)

1. _AFXWIN_INLINE BOOL CDialog::Create(UINT nIDTemplate, CWnd* pParentWnd)
{ return CDialog::Create(ATL_MAKEINTRESOURCE(nIDTemplate), pParentWnd);


2. #ifdef _DEBUG
if (!_AfxCheckDialogTemplate(lpszTemplateName, FALSE))


3. _AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
{ ASSERT(afxCurrentResourceHandle != NULL);


4. AFX_MODULE_STATE* AFXAPI AfxGetModuleState()


#4 returns and I guess the assertion on #3 fails. I have changed resource.h manually since there were duplicated resource ID values, and I've deleted aps, res file and recompiled it. It didn't help, and I don't know what to do. If anyone has an idea I'd be glad to here them. Thanks in advance.


More information : This is actually based on NPAPI code sample, and since this sample isn't a MFC project, I've added MFC support. Though I could use CString, AfxMessageBox(), the class wizard didn't let me create a MFC dialog class and told me I can't do it because this project isn't a MFC project. So I had to write down a MFC dialog code manually, and I copy&pasted the related code from another MFC dialog-based project.



Re: Visual C++ General Problem getting a resource

TilakGopi

Hi,

One thing is creating the dlg on stack won't show u the dialog as it will be immediately destroyed when the control goes out of scope.So,create the dialog on heap(using pointers) and then show it.

In my sample i didn't get any problem.Could u please post the code completely , so that i can found the problem.

And alow which IDE u r using (VC6.0,VS2003 or VS2005)

Thanx,

Ch.T.Gopi Kumar.






Re: Visual C++ General Problem getting a resource

Viorel.

 WooJin wrote:

[...]

More information : This is actually based on NPAPI code sample, and since this sample isn't a MFC project, I've added MFC support. [...]

If your MFC application was not created using wizards, then you probably need more manual initializations. For example, you probably need to call AfxSetResourceHandle function inside your WinMain function.

 

Maybe it would be better to create a new MFC project using wizard, and then move your code to this project

 

I hope this makes sense.

 





Re: Visual C++ General Problem getting a resource

WooJin

TilakGopi wrote:

Hi,

One thing is creating the dlg on stack won't show u the dialog as it will be immediately destroyed when the control goes out of scope.So,create the dialog on heap(using pointers) and then show it.

In my sample i didn't get any problem.Could u please post the code completely , so that i can found the problem.

And alow which IDE u r using (VC6.0,VS2003 or VS2005)

Thanx,

Ch.T.Gopi Kumar.

I'm using VS2005., and here's the code sample.

http://theand.net/myTest_MFC.zip

I haven't set the options for Release version, so I recommand you to compile it in Debug version.

I'd be very very grateful if you could check the actual code for me, and thanks for your reply :-)

Oh, the reason I didn't create the dialog on heap was because I was afraid when the process terminates, memory leak would occur.

And when I've followed the function call which made the termination, I found out it was before the code goes out of scope.

Thanks again!





Re: Visual C++ General Problem getting a resource

WooJin

Viorel. wrote:
WooJin wrote:

[...]

More information : This is actually based on NPAPI code sample, and since this sample isn't a MFC project, I've added MFC support. [...]

If your MFC application was not created using wizards, then you probably need more manual initializations. For example, you probably need to call AfxSetResourceHandle function inside your WinMain function.

Maybe it would be better to create a new MFC project using wizard, and then move your code to this project

I hope this makes sense.

I tried it but it didn't work out. Maybe it's due to my shortage of knowledge.

I've posted the source code above, and if you check it out you'll find that I have called AfxSetResourceHandle() and annotated the line after finding out it doesn't work.

In addition, my source code doesn't contain WinMain function and its entry point is quite different.

Thanks for the reply!





Re: Visual C++ General Problem getting a resource

TilakGopi

Hi,

I am not aware of running this type of applications.How to run it






Re: Visual C++ General Problem getting a resource

TilakGopi

Hi woojin,

Hope u solved ur problem.

What is the reason for it

And still i don't know how to run ur application

If u've time, could please post the solution and procedure for running ur application.

Thanx in advance.

Ch.T.Gopi Kumar.






Re: Visual C++ General Problem getting a resource

Bite Qiu - MSFT

MFC application doesn't have WinMain explicity, see: http://msdn.microsoft.com/library/default.asp url=/library/en-us/vccore/html/_core_cwinapp.3a_.the_application_class.asp

Such question is not covered in this forum, but you can probably get more help in vc.mfc newsgroup, see also the scope for this forum.

If you cannot find a more appropriate place or still believe this forum is the best fit for your questions, please feel free to mark the thread as not resolved and we will look into it again.

best regards,

rico