I have a question to those who are better informed than I.. (ie, most of you :grin: )

Im building an "autocad-bot" masm program at the moment. I was basically following some VB examples to create an instance of autocad, and when i came across this:
Set acadApp = CreateObject("Autocad.Application")
'open AutoCAD

I decided to look up the "Autocad.Application" Registry key, and found the CLSID. (Since the SDK didnt provide this CLSID ~ The SDK assumes im writing ARX programs which are Add-ons to Autocad, thus assumes Acad is already running, and hence didnt give me this CLSID).

Getting back on track, i used this CLSID, with the provided IID_IAcadApplication in the SDK, and wrote a working source to insanciate Autocad, and Release it. The program works, however, under one condition: I place the MASM exe in the "Common Files\Autocad Sharred\" directory. This is where all the COM server objects resides. If i run it from any other dir, i get missing DLL errors.

Why is it that VB can compile the same thing i just did, and not have this problem. I assume there is more "hidden" code VB is placing to look up a registry key and set the path pointer, or something?? Does anyone have any suggestions, or code fragments, that would allow the program to run anywhere in the OS??

Here is the code i have written:


.data
IID_IAcadApplication GUID sIID_IAcadApplication
CLSID_Application GUID sCLSID_Application

.code

.elseif uMsg == WM_CREATE

xor eax, eax
mov pIAcadDocument, eax

invoke CoInitialize, NULL
invoke CoCreateInstance, ADDR CLSID_Application, NULL, CLSCTX_ALL,\
addr IID_IAcadApplication, addr pIAcadDocument

.if !(EAX)
coinvoke pIAcadDocument, IAcadApplication,put_Visible, TRUE
.endif


...
...
...


.elseif uMsg == WM_DESTROY

.if( pIAcadDocument )
coinvoke pIAcadDocument, IAcadApplication, Quit
.endif

invoke CoUninitialize
invoke PostQuitMessage,NULL
return 0
.endif

Thanx alot!
:alright:
NaN
Posted on 2002-12-17 18:34:55 by NaN
I found one solution that works, but its a back door approach:
InitCad PROC hWindow:DWORD

LOCAL dirbuf[512] :BYTE

.data
szDir db "C:\Program Files\Common Files\Autodesk Shared\",0
.code

[b] invoke GetCurrentDirectory, 512, addr dirbuf
invoke SetCurrentDirectory, addr szDir[/b]

xor eax, eax
mov pIAcadDocument, eax

invoke CoInitialize, NULL
invoke CoCreateInstance, ADDR CLSID_Application, NULL, CLSCTX_ALL,\
addr IID_IAcadApplication, addr pIAcadDocument

.if !(EAX)
coinvoke pIAcadDocument, IAcadApplication,put_Visible, TRUE
.endif
[b] invoke SetCurrentDirectory, addr dirbuf[/b]

ret
InitCad ENDP

This works, but its not the best solution cause im hard coding in the required path. I did a search thru the registry for "Autodesk Shared" but didnt pull up any keys that i can directly use. Is there a shell registry key or something to get the OS path to "\Program Files\Common Files\"?? If so i can simply concatenate on the subdirectory....

Thanx!
:alright:
NaN
Posted on 2002-12-17 20:37:49 by NaN
Hi NaN,

that entry should be in HKEY_LOCAL_MACHINE\Software\Microsoft\CurrentVersion.

I also wonder why the code works in VB. Maybe VB loads the TypeLib/TypeInfo first and uses entry in HELPDIR there?
Posted on 2002-12-18 03:17:40 by japheth
Thanx for the Key location, i will give it a try ;)

As for the VB thing, ya its wierd. Till now with other COM servers, i have never run into this problem. I suspect that Acad wants me to use the ACAD.EXE file and not instanciate it like im doing (CLSID_Application). Like i said it was the one GUID that was not given to me in the .tlb file. Looking in the registry it shows the local32 key to be:

"C:\Program Files\Autocad2000\Acad.exe /Automation"

And being a com fan, i would like to avoid shell executing Acad, if i can ;) (which appears to be no problem so far, only this one bump..)

Thanx again for the help!
:alright:
NaN
Posted on 2002-12-18 17:01:28 by NaN
I never found the key you suggested, however, it did lead me to this:
HKEY_LOCAL_MACHINE\Software\Autodesk\ ObjectDBX\R15.0\Applications\ISM\Loader


Which has a key:

MODULE = C:\Program Files\Common Files\Autodesk Shared\acIsmObj15.dbx
All i have to do is get it, and cut off the file name... :grin:

I feel pretty sure this will exist on all installations...

Thanx again!
:alright:
NaN
Posted on 2002-12-18 21:54:51 by NaN
Heya NAN, Fire up your PSDK or MSDN and look into "SHGetSpecialFolderLocation" (shell32.dll version 4.7 or later) and or "SHGetFolderLocation" (shell32.dll version 5.0 or later) and for the nFolder parameter pass the function: CSIDL_PROGRAM_FILES_COMMON and the ppidl parameter will contain PIDL to the "Common Files" directory. :grin: BUT this will only work on Windows NT, Windows 2000, and Windows XP systems. Not valid for Windows Millennium Edition (Windows Me). so maybe pass it CSIDL_PROGRAM_FILES and get the PIDL to the program files directory and add on \Common Files\Autodesk Shared\? Dunno never played with this in ASM only in VB.


Ooops almost forgotten, once you have the PIDL to the Common file directory or the program files directory, pass the PIDL to SHGetPathFromIDList and it will fill in pszPath with the system path of that directory so you can append "Autodesk Shared\" and then maybe you can do your thing or use SetCurrentDirectory with your path to common files.

Hope this helps ya!:cool:
Posted on 2002-12-18 22:11:43 by Gunner
Thanks for the info Gunner, its appreciated!

:alright:
NaN
Posted on 2002-12-19 18:27:43 by NaN