how to avoid an assert in AfxGetResourceHandle (in debugbuilds)

G

Guest

Hi,
I have posted this on 8/19/2004 but was unclear in my intention. So here it
comes again:
how can I avoid the failing assert in the following scenario?

- create a managed C++ Windows Forms Application,
- in the designer view, drag a button on the form
- add the following code to the Click event for that button:
CFileDialog dlg(TRUE);
dlg.DoModal();
- #include <afxdlgs.h> in the Header of that from
- build and run the application (in debug mode)
- when you click the button the following assert in AfxGetResourceHandle
fails:
ASSERT(afxCurrentResourceHandle != NULL)

Note that in the project settings use MFC as shared library is turned on.

Thanks in advance


Arne
 
G

Guest

Ronald Laeremans said:
Did you add a CWinApp object?

No, I assume that I should have done this.
I tried adding this line at (cpp) file-scope:
CWinApp hackForCFileDialog;
with no improvement.

Since I cannot have a CWinApp as a member variable in my managed Form where
should the CWinApp object live?

Thanks

Arne
 
R

Ronald Laeremans [MSFT]

It needs to be a global object.

Ronald

Arne said:
No, I assume that I should have done this.
I tried adding this line at (cpp) file-scope:
CWinApp hackForCFileDialog;
with no improvement.

Since I cannot have a CWinApp as a member variable in my managed Form
where
should the CWinApp object live?

Thanks

Arne
 
G

Guest

Hi Ronald,
Ronald Laeremans said:
It needs to be a global object.

sorry for the late reply, I'm trying to reduce weekend-working.

So then the filescope

CWinApp hackForCFileDialog;

in the cpp file of the form should have done it - but it did not work.

Thanks again

Arne
 
R

Ronald Laeremans [MSFT]

Can you try the other way around? Start an MFC project..Make it compile with
/clr and when you have that working see what else you might be missing in
your example?

Ronald
 
G

Guest

Hi Ronald,
Can you try the other way around? Start an MFC project..Make it compile with
/clr and when you have that working see what else you might be missing in
your example?
I tried that, and as MFC project it works.
Then I tried to make the global CWinApp object an instance of a class
derived from CWinApp and override the InitInstance method as found in the MFC
Project.
This did not help. I noted that the InitInstance method was not called.
Explicitly calling that method from the default constructor of the CWinApp
derived class did not help either.
The mere existence of a CWinApp (derived) object is not sufficient to be
able to open a CFileDialog instance from a windows forms project.
Hence I assume that either the CWinApp object has to be bound somehow to the
windows forms application or it is simply not possible to open a CFileDialog
from a windows forms project.

Thanks again for the help

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top