ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

executeInApplicationContext. AutoCAD crashes when opened drawing loses focus.

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Millerni456
2187 Views, 9 Replies

executeInApplicationContext. AutoCAD crashes when opened drawing loses focus.

Hey everyone,

 

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

 

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

9 REPLIES 9
Message 2 of 10
fenton.webb
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
AutoCAD Engineering
Autodesk

Message 3 of 10

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

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 4 of 10

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!Smiley Happy

 

 

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

Message 5 of 10


@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

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 6 of 10

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.

 

Message 7 of 10


@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.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 8 of 10

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
AutoCAD Engineering
Autodesk

Message 9 of 10
Millerni456
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!

Message 10 of 10
fenton.webb
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
AutoCAD Engineering
Autodesk

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost