Selfwritten DLL with MFC- and ATL-Support

Selfwritten DLL with MFC- and ATL-Support

Anonymous
Not applicable
511 Views
6 Replies
Message 1 of 7

Selfwritten DLL with MFC- and ATL-Support

Anonymous
Not applicable
Hi!

I used the ATL Wizard from Visual Studio 6.0 to create a DLL with MFC-
and ATL-Support.

Well, I inserted the acrxEntryPoint Function, exported the Symbol and
adapted the project settings (base address, etc.) to meet my needs.

Currently, I'm already able to load the ARX in AutoCAD (with the
arx/load command), but when I unload the DLL, my application crashes
AutoCAD and the error-message is:

------------------------------------------
Debug Assertion Failed!
Program: C:\WINNT\system32\regsvr32.exe
File: [...]\atlbase.h
Line: 5700

Expression: pM ->m_hInst != 0

[...]
-------------------------------------------

I guess, I have to register some stuff before using it, right?
I am not experienced with ATL or anything like that, I just had to
create an arx-project without the help of the ObjectARX wizard. This
project must be able to create a Toolbar and for this I need access to
IAcadMenuGroup a.s.o. and this stuff needs ATL.

Well, my application loads into AutoCAD, I can call functions in it, I
can work with it - although I'm getting the following message when
loading it:

"AXSupport.arx uses Memory from MSVCRTD.DLL, but AutoCAD uses Memory
from MSVCRT.DLL. This may lead to problems."

(Note: This error message may not match the exact english one - I
translated it from German to English).

Thanks in advance,
--
| .-. | CCNA Alexander Griesser | .''`. |
| /v\ \ Software Developer, EDV Software Service / : :' : |
| /( )\ | Bahnhofstr. 8, 9500 Villach | `. `' |
| ^^ ^^ `-------------------------------------------------' `- |
0 Likes
512 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Assuming this is your DEBUG build-

You need to use the same _DEBUG workaround that you would use in any
ObjectARX dll, because AutoCAD is linked to the release MFC libraries and
you are linked to the DEBUG libraries. This will crash if anything of
substance is passed to/from the dll like CString.

If your release build exhibits the same problem then something else is
wrong...

|
----+----------------------------------------------
| Byron Blattel
| CADwerx---Applications for AutoCAD
| Autodesk Registered Developer
| email: byron@cadwerx.net
| web site: http://www.cadwerx.net
|

"Alexander Griesser" wrote in message
news:slrnal50r2.pjb.tuxx@ess-linux.ess.local...
> Hi!
>
> I used the ATL Wizard from Visual Studio 6.0 to create a DLL with MFC-
> and ATL-Support.
>
> Well, I inserted the acrxEntryPoint Function, exported the Symbol and
> adapted the project settings (base address, etc.) to meet my needs.
>
> Currently, I'm already able to load the ARX in AutoCAD (with the
> arx/load command), but when I unload the DLL, my application crashes
> AutoCAD and the error-message is:
>
> ------------------------------------------
> Debug Assertion Failed!
> Program: C:\WINNT\system32\regsvr32.exe
> File: [...]\atlbase.h
> Line: 5700
>
> Expression: pM ->m_hInst != 0
>
> [...]
> -------------------------------------------
>
> I guess, I have to register some stuff before using it, right?
> I am not experienced with ATL or anything like that, I just had to
> create an arx-project without the help of the ObjectARX wizard. This
> project must be able to create a Toolbar and for this I need access to
> IAcadMenuGroup a.s.o. and this stuff needs ATL.
>
> Well, my application loads into AutoCAD, I can call functions in it, I
> can work with it - although I'm getting the following message when
> loading it:
>
> "AXSupport.arx uses Memory from MSVCRTD.DLL, but AutoCAD uses Memory
> from MSVCRT.DLL. This may lead to problems."
>
> (Note: This error message may not match the exact english one - I
> translated it from German to English).
>
> Thanks in advance,
> --
> | .-. | CCNA Alexander Griesser | .''`. |
> | /v\ \ Software Developer, EDV Software Service / : :' : |
> | /( )\ | Bahnhofstr. 8, 9500 Villach | `. `' |
> | ^^ ^^ `-------------------------------------------------' `- |
0 Likes
Message 3 of 7

Anonymous
Not applicable
* Byron Blattel :
> Assuming this is your DEBUG build-

Yes, it was. Thanks, I now switched to RELEASE and everything works
fine.

> You need to use the same _DEBUG workaround that you would use in any
> ObjectARX dll, because AutoCAD is linked to the release MFC libraries and
> you are linked to the DEBUG libraries.

Which workaround would that be?

thanks,
--
| .-. | CCNA Alexander Griesser | .''`. |
| /v\ \ Software Developer, EDV Software Service / : :' : |
| /( )\ | Bahnhofstr. 8, 9500 Villach | `. `' |
| ^^ ^^ `-------------------------------------------------' `- |
0 Likes
Message 4 of 7

Anonymous
Not applicable
> Which workaround would that be?

To temporarily undefine _DEBUG for the CRT, the 'Wizard' wraps all MFC/ATL
includes with the following -

// 'DEBUG workaround' below prevents the MFC or ATL #include-s
// from pulling in "afx.h" that would force the debug CRT through
// #pragma-s.

#ifdef _DEBUG
#define _DEBUG_WAS_DEFINED
#undef _DEBUG
#define NDEBUG
#endif

// MFC includes
#include // MFC core and standard components
#include // MFC extensions
...
#define _ATL_APARTMENT_THREADED
#include
// You may derive a class from CComModule and use it if you want to override
// something, but do not change the name of _Module
extern CComModule _Module;
#include
#include
...
// I also put my STL includes inside as well
#include
#include

#ifdef _DEBUG_WAS_DEFINED
#undef NDEBUG
#define _DEBUG
#undef _DEBUG_WAS_DEFINED
#endif
0 Likes
Message 5 of 7

Anonymous
Not applicable
* Byron Blattel :
> > Which workaround would that be?
>
> To temporarily undefine _DEBUG for the CRT, the 'Wizard' wraps all MFC/ATL
> includes with the following -

Ah, ok, now I did this hack in my stdafx.h and I can debug my
ARX-Application now. The only remaining problem is:

When I start the debugger and use f.ex. a CString Object inside of my
ARX-Code, I'm prompted to give the path to a file called "corehdr.pdb",
which is definetly not on my system.

I asked google about that, but it also returned no hits, so maybe one of
you can help me out there or tell me, what else I need to do, to have a
full debuggable arx-workspace.

First, I thought, the problem would be there with all MFC classes, so I
instantiated a CArray object and that works fine. I can see the contents
in the debugger.

For the CString and CStringArray objects I only get error code
"CXX0017: Error: Symbol foobar not found."

Same thing for CFont, as I just found out.

Does anyone know about such a behaviour or can anyone tell me, why I
need corehdr.pdb and why this file is not installed on my system?

Thanks in Advance,
--
| .-. | CCNA Alexander Griesser | .''`. |
| /v\ \ Software Developer, EDV Software Service / : :' : |
| /( )\ | Bahnhofstr. 8, 9500 Villach | `. `' |
| ^^ ^^ `-------------------------------------------------' `- |
0 Likes
Message 6 of 7

Anonymous
Not applicable
corehdr.pdb is a debug file for AutoCAD's internal code which is why you
don't have it on your system. You should be able to cancel out of the
dialog that asks for it and keep debugging.

"Alexander Griesser" wrote in message
news:slrnampqfi.450.tuxx@ess-linux.ess.local...
> * Byron Blattel :
> > > Which workaround would that be?
> >
> > To temporarily undefine _DEBUG for the CRT, the 'Wizard' wraps all
MFC/ATL
> > includes with the following -
>
> Ah, ok, now I did this hack in my stdafx.h and I can debug my
> ARX-Application now. The only remaining problem is:
>
> When I start the debugger and use f.ex. a CString Object inside of my
> ARX-Code, I'm prompted to give the path to a file called "corehdr.pdb",
> which is definetly not on my system.
>
> I asked google about that, but it also returned no hits, so maybe one of
> you can help me out there or tell me, what else I need to do, to have a
> full debuggable arx-workspace.
>
> First, I thought, the problem would be there with all MFC classes, so I
> instantiated a CArray object and that works fine. I can see the contents
> in the debugger.
>
> For the CString and CStringArray objects I only get error code
> "CXX0017: Error: Symbol foobar not found."
>
> Same thing for CFont, as I just found out.
>
> Does anyone know about such a behaviour or can anyone tell me, why I
> need corehdr.pdb and why this file is not installed on my system?
>
> Thanks in Advance,
> --
> | .-. | CCNA Alexander Griesser | .''`. |
> | /v\ \ Software Developer, EDV Software Service / : :' : |
> | /( )\ | Bahnhofstr. 8, 9500 Villach | `. `' |
> | ^^ ^^ `-------------------------------------------------' `- |
0 Likes
Message 7 of 7

Anonymous
Not applicable
* Art Cooney :
> corehdr.pdb is a debug file for AutoCAD's internal code which is why you
> don't have it on your system. You should be able to cancel out of the
> dialog that asks for it and keep debugging.

Yes, that's possible, I assumed that. But the other problem still
exists:

[ While debugging ]
> > For the CString and CStringArray objects I only get error code
> > "CXX0017: Error: Symbol foobar not found."
> >
> > Same thing for CFont, as I just found out.

regards,
--
| .-. | CCNA Alexander Griesser | .''`. |
| /v\ \ Software Developer, EDV Software Service / : :' : |
| /( )\ | Bahnhofstr. 8, 9500 Villach | `. `' |
| ^^ ^^ `-------------------------------------------------' `- |
0 Likes