ObjectARX

Reply
Valued Contributor
Millerni456
Posts: 55
Registered: ‎01-23-2013
Message 1 of 10 (462 Views)
Accepted Solution

executeInApplicationContext. AutoCAD crashes when opened drawing loses focus.

462 Views, 9 Replies
07-29-2013 01:44 PM

Hey everyone,

 

I finally figured out how to get an ObjectARX program running! :smileyhappy:

 

Unfortunately, I am running into this crash that happens after loading my program.

In the InitAppMsg procedure, I call this function:

acDocManager->executeInApplicationContext(OpenDrawing, (void *)"c:\....pathtodwg");

OpenDrawing is defined as follows:

void OpenDrawing(void *fName) {
    int nChars = MultiByteToWideChar(CP_ACP, 0, (const char*) fName, -1, NULL, 0); //Get size of    buffer.
    const ACHAR *acName = new ACHAR[nChars]; //Create buffer to store converted string.
    MultiByteToWideChar(CP_ACP, 0, (const char*)fName, -1, (LPWSTR)acName, nChars); //Fill buffer.
    acDocManager->appContextOpenDocument(acName); //Use buffer
    delete [] acName; //Delete buffer from memory
}

 

 

The function call is successful and will open up the drawing.  However, when I click the default drawing that is opened when the AutoCAD instance is created, OR if I close the newly opened drawing, AutoCAD crashes.

 

What I am trying to do is open arbitrary AutoCAD drawings, possibly edit their database, then re-save them.

 

If you can help me out with this one, it'd be greatly appreciated.

Ask if me you have any questions or need more information. (.cpp entry point file is attached).

 

Thanks,

-Nicholas

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 2 of 10 (453 Views)

Re: executeInApplicationContext. AutoCAD crashes when opened drawing loses focu

07-29-2013 02:39 PM in reply to: Millerni456

First of all, don't use char's - use TCHAR. We moved from MBCS in 2007, we now use UNICODE. If you try to mix MBCS characters with our UNICODE system it'll either be hard work and/or you will cause crashing

 

Also, I suspect you might be running into Multithreaded Debug DLL issues - you cannot run your ObjectARX DLL in debug mode with Multithreaded Debug DLL set in your compiler settings - this is because AutoCAD is compliled in release mode (Multithreaded DLL) - mixing the 2 will cause random crashes. If you are compiling and you see something like MSVCRTD.lib already linked, ignoring - then you know you have problems.

 

Next, if you want to programmatically edit a DWG file, no need to open it in the editor - simply use AcDbDatabase::readDWGFile() to read it into your own side-database.

 

Something like this (but in C++, not .NET) http://adndevblog.typepad.com/autocad/2012/07/using-readdwgfile-with-net-attachxref-or-objectarx-acd...

 

 





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Moderator
Alexander.Rivilis
Posts: 1,388
Registered: ‎04-09-2008
Message 3 of 10 (437 Views)

Re: executeInApplicationContext. AutoCAD crashes when opened drawing loses focu

07-30-2013 04:46 AM in reply to: Millerni456

Do not call acDocManager->executeInApplicationContext(...) inside On_kInitAppMsg handler. At this point, AutoCAD may not yet be fully initialized.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Contributor
Millerni456
Posts: 55
Registered: ‎01-23-2013
Message 4 of 10 (430 Views)

Re: executeInApplicationContext. AutoCAD crashes when opened drawing loses focu

07-30-2013 06:10 AM in reply to: Alexander.Rivilis

Thanks for both of your help!

 

The ARX was running in release mode, which wasn't the issue.  Although it is good to know that this is a requirement.

Also, I do not believe the crash was a result of encoding problems as well... All characters were converted to wchar in the long run.  But, again, thanks for letting me know to use TCHAR (as I did not know it is dynamic based on the character set).  The code now uses the _T(x) macro.

 

Also, I do believe the result of the problem was trying to open the drawing in the kInitAppMsg response.

I have changed to code and registered a command.  This command will trigger the following code:

acDocManager->executeInApplicationContext(....)

 

And viola!   AutoCAD no longer crashes!:smileyhappy:

 

 

Now... seeing as I am not running into the crash anymore, I'm not sure if this next question is on-topic... but, I've got an error message when loading my ARX file into AutoCAD.  I always select "Load Application" and it works fine.

I am using ObjectARX 2012 and AutoCAD 2012, both are 64-bit.  And the platform toolset I am using is v100.

error.PNG

 

 

 

Thanks again!

-Nicholas

Moderator
Alexander.Rivilis
Posts: 1,388
Registered: ‎04-09-2008
Message 5 of 10 (426 Views)

Re: executeInApplicationContext. AutoCAD crashes when opened drawing loses focu

07-30-2013 06:24 AM in reply to: Millerni456

Millerni456 wrote:
...I always select "Load Application" and it works fine.

I am using ObjectARX 2012 and AutoCAD 2012, both are 64-bit.  And the platform toolset I am using is v100...



For AutoCAD 2012 you have to use Platform Toolset V90:

About Visual Studio 2010, Visual Studio Express, Platform Toolset and AutoCAD 2010-2012


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Contributor
Millerni456
Posts: 55
Registered: ‎01-23-2013
Message 6 of 10 (420 Views)

Re: executeInApplicationContext. AutoCAD crashes when opened drawing loses focu

07-30-2013 07:04 AM in reply to: Alexander.Rivilis

Oh dear....

 

The reason I changed it to v100 is because I cannot build the ARX:

 

1>------ Build started: Project: ARX_demo, Configuration: Release x64 ------
1>Build started 7/30/2013 10:01:35 AM.
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(292,5): error MSB8009: .NET Framework 2.0/3.0/3.5 target the v90 platform toolset. Please make sure that Visual Studio 2008 is installed on the machine.
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.10
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

 

Does this mean I have to build using Visual Studio 2008?

Please make sure that Visual Studio 2008 is installed on the machine.

I am using Visual Studio 2010, and thought that it would work fine.

 

Moderator
Alexander.Rivilis
Posts: 1,388
Registered: ‎04-09-2008
Message 7 of 10 (416 Views)

Re: executeInApplicationContext. AutoCAD crashes when opened drawing loses focu

07-30-2013 07:28 AM in reply to: Millerni456

Millerni456 wrote:
... Does this mean I have to build using Visual Studio 2008?
Please make sure that Visual Studio 2008 is installed on the machine.

I am using Visual Studio 2010, and thought that it would work fine.

 


It mean you have to have installed VS 2008 SP1.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 8 of 10 (407 Views)

Re: executeInApplicationContext. AutoCAD crashes when opened drawing loses focu

07-30-2013 08:43 AM in reply to: Alexander.Rivilis

What Alex says is true, you need to compile with V90 from VS 2010 if compiling for AutoCAD 2012.

 

It's totally possible to use VS 2010 to compile V90, you just have to make sure VS2008 is installed because when you compile in VS2010 using V90 VS2010 is literally using the VS2008 compiler, linker and libs.

 

Also, Alex is also right about kInitApp message. You could try kLoadDwg, but I recommend doing all of your code inside of a command that is called from kInitApp using ads_queueexpr(), or even better, use the Autoloader bundle format with a StartupCommand= to the command you want to execute on startup, then there is no extra code. http://adndevblog.typepad.com/autocad/2013/01/autodesk-autoloader-white-paper.html

 

 





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Valued Contributor
Millerni456
Posts: 55
Registered: ‎01-23-2013
Message 9 of 10 (400 Views)

Re: executeInApplicationContext. AutoCAD crashes when opened drawing loses focu

07-30-2013 10:38 AM in reply to: fenton.webb

Wow I'm impressed at how resourceful everybody is!

Thanks a ton for all the pointers.

 

I am still trying to work out the problem with v90 toolset.

It appears there is not an easy way to obtain Microsoft Visual Studio 2008.

 

 Despite this, I was able to install VS2008 Express + SP1, and after doing so I got a new error.  This one says that it cannot locate the 2008 compiler for 64-bit applications.

Execution path (C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\x86_amd64) could not be found.

 (The files actually are not in the directory it is looking inside of, so the installation must have skipped it).

 

So, I'm  left wondering if I can indeed use the express edition, or if I need to install the express edition separate from the service pack.   Or if I need to get VS2008 professional edition.  (I already have VS2010 Pro + SP1, but this probably will not count towards a license for the older version haha).

 

Apologies if this is swaying too far from the OP.

In the mean time I will be looking at obtaining the compiler files.

 

Thanks for all the help!

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 10 of 10 (391 Views)

Re: executeInApplicationContext. AutoCAD crashes when opened drawing loses focu

07-30-2013 11:19 AM in reply to: Millerni456

I think it might be time you got yourself an MSDN license - VS 2008 can easily be downloaded if you have one





Fenton Webb

Developer Technical Services

Autodesk Developer Network


You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community