Registry key help needed

Registry key help needed

Anonymous
Not applicable
4,983 Views
8 Replies
Message 1 of 9

Registry key help needed

Anonymous
Not applicable

Good morning,

 

I have an app written in VB.NET which is triggered by a Save event in AutoCAD.  There's no CommandMethod and no Command for users to enter.  The Save event triggers the application.

 

When I manually NETLOAD the dll, it works perfectly.  

 

So, I wrote a registry key to load the dll on startup.  (I have dozens of apps which have dlls that load on startup via registry keys).  

 

When the registry is updated with the key (below) for the new dll, the application is not triggered by the Save event.  

 

Here's the registry key:

[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R22.0\ACAD-1001\Applications\PhaseClone]
"Clones phasing layouts on save event for Instant users to access"
"LOADCTRLS"=dword:0000000e
"LOADER"="C:\\PTD-Menu\\DLL\\PhaseClone.dll"
"MANAGED"=dword:00000001

 

I have always assumed that such a registry key does the same as a manual NETLOAD because it has always worked that way for the applications invoked with a command.  But it's not working with this app which is invoked with the Save event.

 

Can anyone help me with a registry key which will load this dll and make it run at the Save event?

 

Thank you,

 

Erik

 

0 Likes
Accepted solutions (1)
4,984 Views
8 Replies
Replies (8)
Message 2 of 9

ActivistInvestor
Mentor
Mentor

 Set loadctrls = 2 (see this topic)

 


@Anonymous wrote:

Good morning,

 

I have an app written in VB.NET which is triggered by a Save event in AutoCAD.  There's no CommandMethod and no Command for users to enter.  The Save event triggers the application.

 

When I manually NETLOAD the dll, it works perfectly.  

 

So, I wrote a registry key to load the dll on startup.  (I have dozens of apps which have dlls that load on startup via registry keys).  

 

When the registry is updated with the key (below) for the new dll, the application is not triggered by the Save event.  

 

Here's the registry key:

[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R22.0\ACAD-1001\Applications\PhaseClone]
"Clones phasing layouts on save event for Instant users to access"
"LOADCTRLS"=dword:2

"LOADER"="C:\\PTD-Menu\\DLL\\PhaseClone.dll"
"MANAGED"=dword:00000001

 

I have always assumed that such a registry key does the same as a manual NETLOAD because it has always worked that way for the applications invoked with a command.  But it's not working with this app which is invoked with the Save event.

 

Can anyone help me with a registry key which will load this dll and make it run at the Save event?

 

Thank you,

 

Erik

 


 

0 Likes
Message 3 of 9

Anonymous
Not applicable

Thank you for the reply.  I changed the LOADCTRLS the way you suggested, but the Save event still did not trigger the app.

 

What else might I try?

 

Thanks,

 

Erik

0 Likes
Message 4 of 9

Norman_Yuan
Mentor
Mentor

Since you say, the code works after "NETLOAD", you only need to confirm if the DLL is loaded on startup or not (because of your registry set up)

 

You could easily tell if:

 

1. If you simply add a CommandMethod into the code, so, you can try the command after AutoCAD starts. Or

2. You can simply try to delete the DLL file after AutoCAD starts. If you can delete it, the DLL file is not loaded - then you can go figure why; If the DLL cannot be deleted, then the DLL is loaded, there must be code problem that makes it not working as expected.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 9

ActivistInvestor
Mentor
Mentor

@Anonymous wrote:

Thank you for the reply.  I changed the LOADCTRLS the way you suggested, but the Save event still did not trigger the app.

 

What else might I try?

 

Thanks,

 

Erik


Without seeing your code or the relevant parts (namely the IExtensionApplication.Initialize() implementation), I can only speculate that because your app is being loaded at startup, Initialize() is called in the application execution context. Conversely, when you use NETLOAD to load your assembly, Initialize() runs in the document execution context. Your code may be in some way sensitive to the execution context and fails when it runs in the application context.

 

You should always wrap all of the code in your Initialize() method in a try block, followed by a catch block that displays any exception raised, because AutoCAD will suppress exceptions raised in Initialize():

 

To verify that the assembly is being loaded at startup, you can just display a message from Initialize() on the command line. If it is being loaded, then we need to see the Initialize() method in order to tell you more about what may be the problem.

 

0 Likes
Message 6 of 9

Anonymous
Not applicable

Thank you for the suggestion to see whether the dll is loading with the registry key rather than assume it isn't.

 

The dll is indeed loading, so the registry key is working.

 

However, when I load the dll via netload, the application is triggered by the Save event, but when the dll is loaded via the registry key at startup, the application does not run with the Save event.

 

Same dll in the same location.  Manual netload causes it to run, registry key loading does not.  It does not say "Unknown Command" (there is no command).  It just doesn't run. 

 

I'm stumped. 

 

I've attached the entire application as a .txt file in case anyone has a minute to look for what I might be doing wrong.

The skeleton of the project is:

- Upon a Save event (not SaveAs, just QSave)...

- Assess the filename of the current drawing.  If it meets certain filename criteria, then...

- Copy the file into a specified folder location and replace what may already be there with the same filename.

 

That's it.  That's all it does.  But I need it to load the dll from the registry, not from manual netload.  (If my users had to netload dlls every time they need to use them they'd kill me :))

 

Thank you,

 

Erik

0 Likes
Message 7 of 9

Anonymous
Not applicable

I replied to an earlier post before I saw yours.  I attached the project as a .txt file and I'll attach it to this reply as well.

 

Your description of the context the application is running in seems to make sense, but I don't know enough about it all to really understand what to do with that information.  I'd be so grateful if you could take a look at the application (it's not very long) and see if you can identify where I went wrong and how I might fix it.  This is the first time I've tried to initiate an application from an event rather than invoking a command, so there is a ton I don't understand...yet 🙂

 

Thank you,

 

Erik

 

0 Likes
Message 8 of 9

ActivistInvestor
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Thank you for the suggestion to see whether the dll is loading with the registry key rather than assume it isn't.

 

The dll is indeed loading, so the registry key is working.

 

However, when I load the dll via netload, the application is triggered by the Save event, but when the dll is loaded via the registry key at startup, the application does not run with the Save event.

 

Same dll in the same location.  Manual netload causes it to run, registry key loading does not.  It does not say "Unknown Command" (there is no command).  It just doesn't run. 

 

I'm stumped. 

 

I've attached the entire application as a .txt file in case anyone has a minute to look for what I might be doing wrong.

The skeleton of the project is:

- Upon a Save event (not SaveAs, just QSave)...

- Assess the filename of the current drawing.  If it meets certain filename criteria, then...

- Copy the file into a specified folder location and replace what may already be there with the same filename.

 

That's it.  That's all it does.  But I need it to load the dll from the registry, not from manual netload.  (If my users had to netload dlls every time they need to use them they'd kill me :))

 

Thank you,

 

Erik


After seeing your code, the reason for the problem is simple. You are adding the SaveComplete event handler only to existing open documents, but you are not adding it to any subsequently-opened documents.

 

To do that, you must add a handler for the DocumentCollection's DocumentCreated event (in your Initialize() method), and in the handler for the event, you must add the SaveComplete event handler to the newly-opened/created document.

 

Message 9 of 9

Anonymous
Not applicable

Thank you so much.  That's exactly the nudge I needed.  I added the DocumentCreated handler in the Initialize sub and it works like a charm.  

 

So, the way I'm understanding this, even though I start AutoCAD by opening a drawing, the drawing that is opening actually opens after the dll is initiated, so without the addition you pointed out, the app doesn't know about the "new" drawing.  

 

Anyway, your solution worked.  Thank you!

 

Erik

0 Likes