Why Domodal Crashing?

R

RLN

Hi All !

I have created MFC dialog in MFC extention DLL. That Dialog is created and
displaed successfully using domodal in win32 console application with mfc
support and also successfully executed with mfc appwizard executable.

Now I have created Office Add-in using the sample of Comaddin. There I am
calling the same MFC Extension based dialog in that but is crashing after
calling domodal.
I have tried the methods of setting the resource handle of instance also.
But no use of that.

Why Dialog is crashing. ? How to resolve the issue.

Com Addin Sample is : http://support.microsoft.com/default.aspx/kb/230689
 
D

Dmitry Streblechenko

Crashing where? Do you see it in your source code? How about the call stack?
Do you specify one of the Outlook windows as the dialog owner?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
T

Tom Serface

How is it crashing? Is there a specific error message or area of the code
that you can identify. Is your DLL trying to access resources? If so,
perhaps there is a problem with the resource ID clashing or not being
available if the instance handle has changed?

Tom
 
D

David Lowndes

I have created MFC dialog in MFC extention DLL. That Dialog is created and
displaed successfully using domodal in win32 console application with mfc
support and also successfully executed with mfc appwizard executable.

Now I have created Office Add-in using the sample of Comaddin. There I am
calling the same MFC Extension based dialog in that but is crashing after
calling domodal.

The key aspect is probably that you've created an MFC extension DLL
rather than just a plain DLL (that uses MFC). Both your projects that
have worked have MFC support, presumably the one that doesn't doesn't
have MFC support?

Dave
 
D

David Ching

David Lowndes said:
The key aspect is probably that you've created an MFC extension DLL
rather than just a plain DLL (that uses MFC). Both your projects that
have worked have MFC support, presumably the one that doesn't doesn't
have MFC support?

Since Office is *not* written in MFC, it does appear that this is indeed the
reason.

-- David
 
D

Dmitry Streblechenko

Why would it matter what it is written in? Windows that live in different
dlls communicate using Windows API only.
It makes no difference wahtsoever whether the window was created using MFC,
ATL or some other lanagugae (e.g. Delphi or VB).

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
D

David Ching

Dmitry Streblechenko said:
Why would it matter what it is written in? Windows that live in different
dlls communicate using Windows API only.
It makes no difference wahtsoever whether the window was created using
MFC, ATL or some other lanagugae (e.g. Delphi or VB).

An MFC Extension DLL can export classes derived from MFC classes, so it is
not true that communication with this DLL is through the Windows API only.
And even if in this case the exported functions did not use MFC classes, the
requirements of the exported functions are different. For example, exports
in an MFC Extension DLL do not have to call AFX_MANAGE_STATE(), but they do
from an MFC Regular DLL (thanks Ajay). It does sound like an MFC state
issue due to the fact that DoModal() is crashing... the dialog resource is
probably not being found.

-- David
 
A

Ajay

Hi All !

I have created MFC dialog in MFC extention DLL. That Dialog is created and
displaed successfully using domodal in win32 console application with mfc
support and also successfully executed with mfc appwizard executable.

Now I have created Office Add-in using the sample of Comaddin. There I am
calling the same MFC Extension based dialog in that but is crashing after
calling domodal.
I have tried the methods of setting the resource handle of instance also.
But no use of that.

Why Dialog is crashing. ? How to resolve the issue.

Com Addin Sample is :http://support.microsoft.com/default.aspx/kb/230689

This DLL shouldnt be an MFC Extension DLL. You should make it a
Regular DLL instead. Also, you can debug your DLL by running office
app as your app in debug application path.
 
R

RLN

Whatever you are telling is right. it is not able to find the resource. But
After getting few other suggestions I have added call AfxSetResouceHandle
before calling the dialog. Then I got the dialog but even now crashing the
following line :

if (!AfxGetThread()->PumpMessage())

The above line from CWnd::RunModalLoop function. This is from default MFC.

If i create a ATL Window it is not crashing. if i create a window using MFC
then only it is crashing. I need specifically MFC because this MFC extension
dll is using by many project and gui is many subclassed. Please give the
solution for this.

If anybody needed I can send a full code for solving my problem.
 
A

Ajay

Whatever you are telling is right. it is not able to find the resource. But
After getting few other suggestions I have added call AfxSetResouceHandle
before calling the dialog. Then I got the dialog but even now crashing the
following line :

                if (!AfxGetThread()->PumpMessage())

The above line from CWnd::RunModalLoop function. This is from default MFC..

If i create a ATL Window it is not crashing. if i create a window using MFC
then only it is crashing. I need specifically MFC because this MFC extension
dll is using by many project and gui is many subclassed.  Please give the
solution for this.

AFAIK, this will not work. MFC extension dll would need a host app
which knows about the state variables. There are none in your case
(office apps are not MFC apps). Just because this project is used by
other projects doesnt mean it can be used in a completely disparate
application which does not support what your module needs. You will
need some kind of wrapper and not a Extension DLL (AFAIK).
 
R

RLN

ok fine. Now I freshly Created the ATL COM DLL Project and intergrated office
addin.
It will create 1 Toolbar button in office . On clicking the button
displaying the messagebox. Working fine. no issues.
After That I just created 1 Dialog and added a MFC class for that. No
Additional code.
Just
AfxSetResourceHandle()
CMyDialog Dlg;
Dlg.DModal();
//reset the resource handle.

That's all . Dialog box residing the same add-in dll. Now No mfc extension
dll or mfc regular dll just ATL COM dll. Now also crashing on the same
location
if (!AfxGetThread()->PumpMessage())



Then wat is the problem now.
 
R

RLN

ok fine. Now I freshly Created the ATL COM DLL Project and intergrated office
addin.
It will create 1 Toolbar button in office . On clicking the button
displaying the messagebox. Working fine. no issues.
After That I just created 1 Dialog and added a MFC class for that. No
Additional code.
Just
AfxSetResourceHandle()
CMyDialog Dlg;
Dlg.DModal();
//reset the resource handle.

That's all . Dialog box residing the same add-in dll. Now No mfc extension
dll or mfc regular dll just ATL COM dll. Now also crashing on the same
location
if (!AfxGetThread()->PumpMessage())



Then wat is the problem now.
 
R

RLN

ok fine. Now I freshly Created the ATL COM DLL Project and intergrated office
addin.
It will create 1 Toolbar button in office . On clicking the button
displaying the messagebox. Working fine. no issues.
After That I just created 1 Dialog and added a MFC class for that. No
Additional code.
Just
AfxSetResourceHandle()
CMyDialog Dlg;
Dlg.DModal();
//reset the resource handle.

That's all . Dialog box residing the same add-in dll. Now No mfc extension
dll or mfc regular dll just ATL COM dll. Now also crashing on the same
location
if (!AfxGetThread()->PumpMessage())



Then wat is the problem now.
--
WM_QUIT
RLN

--
WM_QUIT
RLN


Tom Serface said:
How is it crashing? Is there a specific error message or area of the code
that you can identify. Is your DLL trying to access resources? If so,
perhaps there is a problem with the resource ID clashing or not being
available if the instance handle has changed?

Tom
 
A

Ajay

ok fine. Now I freshly Created the ATL COM DLL Project and intergrated office
addin.
It will create 1 Toolbar button in office . On clicking the button
displaying the messagebox. Working fine. no issues.
After That I just created 1 Dialog and added a MFC class for that. No
Additional code.
Just
AfxSetResourceHandle()
CMyDialog Dlg;
Dlg.DModal();
//reset the resource handle.

That's all . Dialog box residing the same add-in dll. Now No mfc extension
dll or mfc regular dll just ATL COM dll. Now also crashing on the same
location
if (!AfxGetThread()->PumpMessage())

I am not too familiar with ATL COM Dll. Why are you using MFC if its
neither Extension nor Regular DLL. Crash that you are getting is still
related to MFC. Are you certain its not an Extension DLL even though
you may be using ATL.
 
D

David Ching

Ajay said:
I am not too familiar with ATL COM Dll. Why are you using MFC if its
neither Extension nor Regular DLL. Crash that you are getting is still
related to MFC. Are you certain its not an Extension DLL even though
you may be using ATL.

Also, is AFX_MANAGE_STATE macro being used at the top of all exported
functions, including all methods of exported classes?

-- David
 
A

Ajay

Also, is AFX_MANAGE_STATE macro being used at the top of all exported
functions, including all methods of exported classes?

I have no idea what OP is really doing here. OP would need this if it
was a regular MFC dll. You can use ATL with Extension as well as
Regular DLL so this issue is still going to be there.
 
L

Leo Violette

Try this...

// You're regular DLL that uses MFC (as opposed to an MFC Extension DLL),
should have a function
// like this to show your dialog.
INT_PTR DLLFuncShowMyDialog(void)
{
// Setup the MFC state for the current thread.
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CMyDialog Dlg;
INT_PTR iRC = Dlg.DoModal();
return iRC;
}
 
A

Ajay

Try this...

// You're regular DLL that uses MFC (as opposed to an MFC Extension DLL),
should have a function
// like this to show your dialog.
INT_PTR DLLFuncShowMyDialog(void)
{
    // Setup the MFC state for the current thread.
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    CMyDialog Dlg;
    INT_PTR iRC = Dlg.DoModal();
    return iRC;

}

OP has an extension DLL; if OP changes to a Regular DLL, these
problems will disappear by using AFX_MANAGE_STATE as you have shown
above.
 
D

Dmitry Streblechenko

*If* all the dlls are of compatible versions.
Outlook would not let you play any of these games. Outlook Object Model or
the Windows API only (which is not supported by MS) are the only options.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
A

Ajay

*If* all the dlls are of compatible versions.
Outlook would not let you play any of these games. Outlook Object Model or
the Windows API only (which is not supported by MS) are the only options.

This is a MFC related issue and would be present even if all DLLs are
compatible(whatever that means) or not. An MFC extension DLL shouldnt
be used to write a plugin/addin to a non-MFC app. On the other hand, a
MFC regular DLL will work fine as a plugin in a Office app. OP's issue
is not about accessing the object model but rather co-existing in it
in a particular way.
 

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