<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Debugging In-process ActiveX DLL in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/debugging-in-process-activex-dll/m-p/325676#M92056</link>
    <description>Hi Natan,&lt;BR /&gt;
I know the feeling,  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  I recompiled my first DLL over 100 times before I&lt;BR /&gt;
found out how to actively debug it.  I am using VB6 Prof. and Acad R14, but&lt;BR /&gt;
I think the following will still work for you.&lt;BR /&gt;
&lt;BR /&gt;
-------------------------------------&lt;BR /&gt;
ThisDrawing Object&lt;BR /&gt;
-------------------------------------&lt;BR /&gt;
There are several ways to set your reference to the AutoCAD drawing.  The&lt;BR /&gt;
way I do it is to create a function in my DLL, and pass the function a&lt;BR /&gt;
reference to the current Drawing object from VBA.  The function then sets a&lt;BR /&gt;
global variable to the reference passed by AutoCAD VBA.  This avoids all the&lt;BR /&gt;
multi-session joys of GetObject.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
- Note:  If you set a global variable in your DLL to a reference to your&lt;BR /&gt;
AutoCAD drawing, you MUST set the reference to nothing before unloading the&lt;BR /&gt;
DLL.  Otherwise AutoCAD will show you one of those neat Fatal Error...&lt;BR /&gt;
messages.  &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
Public Sub SetDrawing(AcadDrawing As AcadDocument)&lt;BR /&gt;
    Set gDoc = AcadDrawing&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
From the AutoCAD side, you can also create a wrapper function that returns a&lt;BR /&gt;
reference to the DLL.  This can make programming a little easier.  I use the&lt;BR /&gt;
following function to reference my DLL.&lt;BR /&gt;
&lt;BR /&gt;
Public Function DLL() As ESD_Tools&lt;BR /&gt;
On Error Resume Next&lt;BR /&gt;
If gVB Is Nothing Then&lt;BR /&gt;
    Set gVB =&lt;BR /&gt;
ThisDrawing.Application.GetInterfaceObject("ESDTools.ESD_Tools")&lt;BR /&gt;
    gVB.SetDrawing ThisDrawing&lt;BR /&gt;
End If&lt;BR /&gt;
Set DLL = gVB&lt;BR /&gt;
If Err Then Call AlertAdmin(Err, "All_ESD_Functions.DLL()", "DLL may not be&lt;BR /&gt;
installed")&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
If you do it like this, it only takes one line of code to call the DLL.&lt;BR /&gt;
Just use the syntax:  DLL.(FunctionName)&lt;BR /&gt;
As you can see in the function, I am also setting a global variable to&lt;BR /&gt;
reference the DLL from the AutoCAD VBA side.  This allows me to show / hide&lt;BR /&gt;
forms without closing them between calls to the DLL.&lt;BR /&gt;
If you use this method, I would also suggest creating another function in&lt;BR /&gt;
the DLL; one that will unload all forms and set the drawing's global&lt;BR /&gt;
reference to nothing.  You will need to call this function before unloading&lt;BR /&gt;
the VBA project or closing AutoCAD.&lt;BR /&gt;
&lt;BR /&gt;
-------------------------------------&lt;BR /&gt;
Debugging the inprocess DLL&lt;BR /&gt;
-------------------------------------&lt;BR /&gt;
The following steps should allow you to actively debug your DLL in the&lt;BR /&gt;
Visual Basic Editor.&lt;BR /&gt;
1.  With AutoCAD closed, open your DLL project.&lt;BR /&gt;
2.  In Visual Basic, click Start with Full Compile from the Run menu.&lt;BR /&gt;
3.  When there are no compile errors, and the DLL is running, start AutoCAD.&lt;BR /&gt;
4.  In AutoCAD VBA, go to tools --&amp;gt; References and add the reference to your&lt;BR /&gt;
DLL.&lt;BR /&gt;
5.  Use a VBA procedure to call a function in your DLL.&lt;BR /&gt;
Note:  Modal forms in your DLL will act differently when running this way.&lt;BR /&gt;
You may need to toggle to VB and click Break, Run in order to see the form.&lt;BR /&gt;
If the DLL has an error, VB should stop and tell you.  You can also use&lt;BR /&gt;
breakpoints and other debugging features in your code.  Just keep in mind&lt;BR /&gt;
the fact that you have active references between Acad and VB and if you End&lt;BR /&gt;
either process without clearing these variables, Acad will likely crash.&lt;BR /&gt;
&lt;BR /&gt;
Are you confused yet?  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  It took me a while to figure this out, but it&lt;BR /&gt;
sure has made it a lot easier to work with inprocess DLLs.&lt;BR /&gt;
&lt;BR /&gt;
Have a great day!!&lt;BR /&gt;
&lt;BR /&gt;
- Adam&lt;BR /&gt;
&lt;BR /&gt;
P.S.&lt;BR /&gt;
Make sure you frequently save your work, especially on the Acad side.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
"Natan Elsberg" &lt;NELSBERG&gt; wrote in message&lt;BR /&gt;
news:396b1127.17754469@discussion.autodesk.com...&lt;BR /&gt;
&amp;gt; I hope someone here can help me or point me in the right direction:&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; I am trying to transfer a suite of routines that I already wrote and&lt;BR /&gt;
&amp;gt; debugged in VBA to an activex dll.  I am told this is the best way of&lt;BR /&gt;
&amp;gt; making a robust / secure and fast application in visual basic.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; I am using VB5 enterprise edition to compile the activex dll.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; I realize that one of the issues that I need to attend to is&lt;BR /&gt;
&amp;gt; initializing some of the objects that we get for free in vba&lt;BR /&gt;
&amp;gt; (thisdrawing for instance).&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; I have written a simple public class whose job will be to farm out the&lt;BR /&gt;
&amp;gt; work to the routines I have already written in standard .bas modules&lt;BR /&gt;
&amp;gt; and initialize the important objects globally at the module level..&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; My problem is that I have quite a bit of debugging to do mainly due to&lt;BR /&gt;
&amp;gt; the initialization of the thisdrawing object and others, and I can't&lt;BR /&gt;
&amp;gt; figure out how to get the debugging process working.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; I have read the help on books online but it doesn't seem to be&lt;BR /&gt;
&amp;gt; applicable to the case where I am debbugging an in-process dll from an&lt;BR /&gt;
&amp;gt; already existing application.  The best I understood  - I would need&lt;BR /&gt;
&amp;gt; the acad.exe as well in the project group and I have no idea what that&lt;BR /&gt;
&amp;gt; means nor how to do it.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; If anyone could help shed some light on this issue I would be most&lt;BR /&gt;
&amp;gt; obliged.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Thanks,&lt;BR /&gt;
&amp;gt; Natan Elsberg&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/NELSBERG&gt;</description>
    <pubDate>Tue, 11 Jul 2000 12:32:28 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2000-07-11T12:32:28Z</dc:date>
    <item>
      <title>Debugging In-process ActiveX DLL</title>
      <link>https://forums.autodesk.com/t5/vba-forum/debugging-in-process-activex-dll/m-p/325675#M92055</link>
      <description>I hope someone here can help me or point me in the right direction:&lt;BR /&gt;
&lt;BR /&gt;
I am trying to transfer a suite of routines that I already wrote and&lt;BR /&gt;
debugged in VBA to an activex dll.  I am told this is the best way of&lt;BR /&gt;
making a robust / secure and fast application in visual basic.&lt;BR /&gt;
&lt;BR /&gt;
I am using VB5 enterprise edition to compile the activex dll.&lt;BR /&gt;
&lt;BR /&gt;
I realize that one of the issues that I need to attend to is&lt;BR /&gt;
initializing some of the objects that we get for free in vba&lt;BR /&gt;
(thisdrawing for instance).&lt;BR /&gt;
&lt;BR /&gt;
I have written a simple public class whose job will be to farm out the&lt;BR /&gt;
work to the routines I have already written in standard .bas modules&lt;BR /&gt;
and initialize the important objects globally at the module level..&lt;BR /&gt;
&lt;BR /&gt;
My problem is that I have quite a bit of debugging to do mainly due to&lt;BR /&gt;
the initialization of the thisdrawing object and others, and I can't&lt;BR /&gt;
figure out how to get the debugging process working.&lt;BR /&gt;
&lt;BR /&gt;
I have read the help on books online but it doesn't seem to be&lt;BR /&gt;
applicable to the case where I am debbugging an in-process dll from an&lt;BR /&gt;
already existing application.  The best I understood  - I would need&lt;BR /&gt;
the acad.exe as well in the project group and I have no idea what that&lt;BR /&gt;
means nor how to do it.&lt;BR /&gt;
&lt;BR /&gt;
If anyone could help shed some light on this issue I would be most&lt;BR /&gt;
obliged.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Natan Elsberg</description>
      <pubDate>Tue, 11 Jul 2000 12:32:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/debugging-in-process-activex-dll/m-p/325675#M92055</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2000-07-11T12:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging In-process ActiveX DLL</title>
      <link>https://forums.autodesk.com/t5/vba-forum/debugging-in-process-activex-dll/m-p/325676#M92056</link>
      <description>Hi Natan,&lt;BR /&gt;
I know the feeling,  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  I recompiled my first DLL over 100 times before I&lt;BR /&gt;
found out how to actively debug it.  I am using VB6 Prof. and Acad R14, but&lt;BR /&gt;
I think the following will still work for you.&lt;BR /&gt;
&lt;BR /&gt;
-------------------------------------&lt;BR /&gt;
ThisDrawing Object&lt;BR /&gt;
-------------------------------------&lt;BR /&gt;
There are several ways to set your reference to the AutoCAD drawing.  The&lt;BR /&gt;
way I do it is to create a function in my DLL, and pass the function a&lt;BR /&gt;
reference to the current Drawing object from VBA.  The function then sets a&lt;BR /&gt;
global variable to the reference passed by AutoCAD VBA.  This avoids all the&lt;BR /&gt;
multi-session joys of GetObject.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
- Note:  If you set a global variable in your DLL to a reference to your&lt;BR /&gt;
AutoCAD drawing, you MUST set the reference to nothing before unloading the&lt;BR /&gt;
DLL.  Otherwise AutoCAD will show you one of those neat Fatal Error...&lt;BR /&gt;
messages.  &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
Public Sub SetDrawing(AcadDrawing As AcadDocument)&lt;BR /&gt;
    Set gDoc = AcadDrawing&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
From the AutoCAD side, you can also create a wrapper function that returns a&lt;BR /&gt;
reference to the DLL.  This can make programming a little easier.  I use the&lt;BR /&gt;
following function to reference my DLL.&lt;BR /&gt;
&lt;BR /&gt;
Public Function DLL() As ESD_Tools&lt;BR /&gt;
On Error Resume Next&lt;BR /&gt;
If gVB Is Nothing Then&lt;BR /&gt;
    Set gVB =&lt;BR /&gt;
ThisDrawing.Application.GetInterfaceObject("ESDTools.ESD_Tools")&lt;BR /&gt;
    gVB.SetDrawing ThisDrawing&lt;BR /&gt;
End If&lt;BR /&gt;
Set DLL = gVB&lt;BR /&gt;
If Err Then Call AlertAdmin(Err, "All_ESD_Functions.DLL()", "DLL may not be&lt;BR /&gt;
installed")&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
If you do it like this, it only takes one line of code to call the DLL.&lt;BR /&gt;
Just use the syntax:  DLL.(FunctionName)&lt;BR /&gt;
As you can see in the function, I am also setting a global variable to&lt;BR /&gt;
reference the DLL from the AutoCAD VBA side.  This allows me to show / hide&lt;BR /&gt;
forms without closing them between calls to the DLL.&lt;BR /&gt;
If you use this method, I would also suggest creating another function in&lt;BR /&gt;
the DLL; one that will unload all forms and set the drawing's global&lt;BR /&gt;
reference to nothing.  You will need to call this function before unloading&lt;BR /&gt;
the VBA project or closing AutoCAD.&lt;BR /&gt;
&lt;BR /&gt;
-------------------------------------&lt;BR /&gt;
Debugging the inprocess DLL&lt;BR /&gt;
-------------------------------------&lt;BR /&gt;
The following steps should allow you to actively debug your DLL in the&lt;BR /&gt;
Visual Basic Editor.&lt;BR /&gt;
1.  With AutoCAD closed, open your DLL project.&lt;BR /&gt;
2.  In Visual Basic, click Start with Full Compile from the Run menu.&lt;BR /&gt;
3.  When there are no compile errors, and the DLL is running, start AutoCAD.&lt;BR /&gt;
4.  In AutoCAD VBA, go to tools --&amp;gt; References and add the reference to your&lt;BR /&gt;
DLL.&lt;BR /&gt;
5.  Use a VBA procedure to call a function in your DLL.&lt;BR /&gt;
Note:  Modal forms in your DLL will act differently when running this way.&lt;BR /&gt;
You may need to toggle to VB and click Break, Run in order to see the form.&lt;BR /&gt;
If the DLL has an error, VB should stop and tell you.  You can also use&lt;BR /&gt;
breakpoints and other debugging features in your code.  Just keep in mind&lt;BR /&gt;
the fact that you have active references between Acad and VB and if you End&lt;BR /&gt;
either process without clearing these variables, Acad will likely crash.&lt;BR /&gt;
&lt;BR /&gt;
Are you confused yet?  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  It took me a while to figure this out, but it&lt;BR /&gt;
sure has made it a lot easier to work with inprocess DLLs.&lt;BR /&gt;
&lt;BR /&gt;
Have a great day!!&lt;BR /&gt;
&lt;BR /&gt;
- Adam&lt;BR /&gt;
&lt;BR /&gt;
P.S.&lt;BR /&gt;
Make sure you frequently save your work, especially on the Acad side.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
"Natan Elsberg" &lt;NELSBERG&gt; wrote in message&lt;BR /&gt;
news:396b1127.17754469@discussion.autodesk.com...&lt;BR /&gt;
&amp;gt; I hope someone here can help me or point me in the right direction:&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; I am trying to transfer a suite of routines that I already wrote and&lt;BR /&gt;
&amp;gt; debugged in VBA to an activex dll.  I am told this is the best way of&lt;BR /&gt;
&amp;gt; making a robust / secure and fast application in visual basic.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; I am using VB5 enterprise edition to compile the activex dll.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; I realize that one of the issues that I need to attend to is&lt;BR /&gt;
&amp;gt; initializing some of the objects that we get for free in vba&lt;BR /&gt;
&amp;gt; (thisdrawing for instance).&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; I have written a simple public class whose job will be to farm out the&lt;BR /&gt;
&amp;gt; work to the routines I have already written in standard .bas modules&lt;BR /&gt;
&amp;gt; and initialize the important objects globally at the module level..&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; My problem is that I have quite a bit of debugging to do mainly due to&lt;BR /&gt;
&amp;gt; the initialization of the thisdrawing object and others, and I can't&lt;BR /&gt;
&amp;gt; figure out how to get the debugging process working.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; I have read the help on books online but it doesn't seem to be&lt;BR /&gt;
&amp;gt; applicable to the case where I am debbugging an in-process dll from an&lt;BR /&gt;
&amp;gt; already existing application.  The best I understood  - I would need&lt;BR /&gt;
&amp;gt; the acad.exe as well in the project group and I have no idea what that&lt;BR /&gt;
&amp;gt; means nor how to do it.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; If anyone could help shed some light on this issue I would be most&lt;BR /&gt;
&amp;gt; obliged.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Thanks,&lt;BR /&gt;
&amp;gt; Natan Elsberg&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/NELSBERG&gt;</description>
      <pubDate>Tue, 11 Jul 2000 12:32:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/debugging-in-process-activex-dll/m-p/325676#M92056</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2000-07-11T12:32:28Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/debugging-in-process-activex-dll/m-p/325677#M92057</link>
      <description>Hi guys,&lt;BR /&gt;
    I know the feeling as well. It's a good thing that Randall and the Llama&lt;BR /&gt;
know thier dll's &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; The following is the example given to me on how to assign&lt;BR /&gt;
and set a class property to the acad app. No need for getobject,&lt;BR /&gt;
getinterfaceobject, ect.&lt;BR /&gt;
&lt;BR /&gt;
&lt;SNIP&gt;&lt;BR /&gt;
Hi Josh,&lt;BR /&gt;
&lt;BR /&gt;
Ok, lets look at a fast example:&lt;BR /&gt;
&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
&lt;BR /&gt;
Private objAcad As AcadApplication&lt;BR /&gt;
&lt;BR /&gt;
Public Property Set AcadApp(objApp As AcadApplication)&lt;BR /&gt;
  Set objAcad = objApp&lt;BR /&gt;
End Property&lt;BR /&gt;
&lt;BR /&gt;
Public Property Get AcadApp() As AcadApplication&lt;BR /&gt;
  Set AcadApp = objAcad&lt;BR /&gt;
End Property&lt;BR /&gt;
&lt;BR /&gt;
Public Function LayerExists(LayerName As String) As Boolean&lt;BR /&gt;
  Dim ThisDwg As AcadDocument&lt;BR /&gt;
  Dim Layr As AcadLayer&lt;BR /&gt;
  If Not Me.AcadApp Is Nothing Then&lt;BR /&gt;
    Set ThisDwg = Me.AcadApp.ActiveDocument&lt;BR /&gt;
    For Each Layr In ThisDwg.Layers&lt;BR /&gt;
      If UCase(Layr.Name) = UCase(LayerName) Then LayerExists = True&lt;BR /&gt;
    Next&lt;BR /&gt;
  End If&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
Now on the client end (in AutoCAD VBA):&lt;BR /&gt;
&lt;BR /&gt;
Public Sub Test&lt;BR /&gt;
Dim objMyDll As YourDll.CreatableObjectName 'The dll library and the class&lt;BR /&gt;
name&lt;BR /&gt;
Set objMyDll = New CreatableObjectName 'just the class here&lt;BR /&gt;
Set objMyDll.AcadApp = Application&lt;BR /&gt;
MsgBox objMyDll.LayerExists("layernamehere")&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Ta da&lt;BR /&gt;
&lt;BR /&gt;
(&lt;BR /&gt;
  )&lt;BR /&gt;
c[]&lt;BR /&gt;
Randall Rath&lt;BR /&gt;
&lt;SNIP&gt;&lt;BR /&gt;
&lt;BR /&gt;
In the client end you can also save a line of code by using:&lt;BR /&gt;
&lt;BR /&gt;
Public Sub Test&lt;BR /&gt;
Dim objMyDll As New YourDll.CreatableObjectName&lt;BR /&gt;
Set objMyDll.AcadApp = Application&lt;BR /&gt;
'your code here&lt;BR /&gt;
End Sub&lt;BR /&gt;
Adam Waller wrote:&lt;BR /&gt;
&lt;BR /&gt;
-Josh&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; Hi Natan,&lt;BR /&gt;
&amp;gt; I know the feeling,  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  I recompiled my first DLL over 100 times before I&lt;BR /&gt;
&amp;gt; found out how to actively debug it.  I am using VB6 Prof. and Acad R14, but&lt;BR /&gt;
&amp;gt; I think the following will still work for you.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; -------------------------------------&lt;BR /&gt;
&amp;gt; ThisDrawing Object&lt;BR /&gt;
&amp;gt; -------------------------------------&lt;BR /&gt;
&amp;gt; There are several ways to set your reference to the AutoCAD drawing.  The&lt;BR /&gt;
&amp;gt; way I do it is to create a function in my DLL, and pass the function a&lt;BR /&gt;
&amp;gt; reference to the current Drawing object from VBA.  The function then sets a&lt;BR /&gt;
&amp;gt; global variable to the reference passed by AutoCAD VBA.  This avoids all the&lt;BR /&gt;
&amp;gt; multi-session joys of GetObject.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&amp;gt; - Note:  If you set a global variable in your DLL to a reference to your&lt;BR /&gt;
&amp;gt; AutoCAD drawing, you MUST set the reference to nothing before unloading the&lt;BR /&gt;
&amp;gt; DLL.  Otherwise AutoCAD will show you one of those neat Fatal Error...&lt;BR /&gt;
&amp;gt; messages.  &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Public Sub SetDrawing(AcadDrawing As AcadDocument)&lt;BR /&gt;
&amp;gt;     Set gDoc = AcadDrawing&lt;BR /&gt;
&amp;gt; End Sub&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; From the AutoCAD side, you can also create a wrapper function that returns a&lt;BR /&gt;
&amp;gt; reference to the DLL.  This can make programming a little easier.  I use the&lt;BR /&gt;
&amp;gt; following function to reference my DLL.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Public Function DLL() As ESD_Tools&lt;BR /&gt;
&amp;gt; On Error Resume Next&lt;BR /&gt;
&amp;gt; If gVB Is Nothing Then&lt;BR /&gt;
&amp;gt;     Set gVB =&lt;BR /&gt;
&amp;gt; ThisDrawing.Application.GetInterfaceObject("ESDTools.ESD_Tools")&lt;BR /&gt;
&amp;gt;     gVB.SetDrawing ThisDrawing&lt;BR /&gt;
&amp;gt; End If&lt;BR /&gt;
&amp;gt; Set DLL = gVB&lt;BR /&gt;
&amp;gt; If Err Then Call AlertAdmin(Err, "All_ESD_Functions.DLL()", "DLL may not be&lt;BR /&gt;
&amp;gt; installed")&lt;BR /&gt;
&amp;gt; End Function&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; If you do it like this, it only takes one line of code to call the DLL.&lt;BR /&gt;
&amp;gt; Just use the syntax:  DLL.(FunctionName)&lt;BR /&gt;
&amp;gt; As you can see in the function, I am also setting a global variable to&lt;BR /&gt;
&amp;gt; reference the DLL from the AutoCAD VBA side.  This allows me to show / hide&lt;BR /&gt;
&amp;gt; forms without closing them between calls to the DLL.&lt;BR /&gt;
&amp;gt; If you use this method, I would also suggest creating another function in&lt;BR /&gt;
&amp;gt; the DLL; one that will unload all forms and set the drawing's global&lt;BR /&gt;
&amp;gt; reference to nothing.  You will need to call this function before unloading&lt;BR /&gt;
&amp;gt; the VBA project or closing AutoCAD.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; -------------------------------------&lt;BR /&gt;
&amp;gt; Debugging the inprocess DLL&lt;BR /&gt;
&amp;gt; -------------------------------------&lt;BR /&gt;
&amp;gt; The following steps should allow you to actively debug your DLL in the&lt;BR /&gt;
&amp;gt; Visual Basic Editor.&lt;BR /&gt;
&amp;gt; 1.  With AutoCAD closed, open your DLL project.&lt;BR /&gt;
&amp;gt; 2.  In Visual Basic, click Start with Full Compile from the Run menu.&lt;BR /&gt;
&amp;gt; 3.  When there are no compile errors, and the DLL is running, start AutoCAD.&lt;BR /&gt;
&amp;gt; 4.  In AutoCAD VBA, go to tools --&amp;gt; References and add the reference to your&lt;BR /&gt;
&amp;gt; DLL.&lt;BR /&gt;
&amp;gt; 5.  Use a VBA procedure to call a function in your DLL.&lt;BR /&gt;
&amp;gt; Note:  Modal forms in your DLL will act differently when running this way.&lt;BR /&gt;
&amp;gt; You may need to toggle to VB and click Break, Run in order to see the form.&lt;BR /&gt;
&amp;gt; If the DLL has an error, VB should stop and tell you.  You can also use&lt;BR /&gt;
&amp;gt; breakpoints and other debugging features in your code.  Just keep in mind&lt;BR /&gt;
&amp;gt; the fact that you have active references between Acad and VB and if you End&lt;BR /&gt;
&amp;gt; either process without clearing these variables, Acad will likely crash.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Are you confused yet?  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  It took me a while to figure this out, but it&lt;BR /&gt;
&amp;gt; sure has made it a lot easier to work with inprocess DLLs.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Have a great day!!&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; - Adam&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; P.S.&lt;BR /&gt;
&amp;gt; Make sure you frequently save your work, especially on the Acad side.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; "Natan Elsberg" &lt;NELSBERG&gt; wrote in message&lt;BR /&gt;
&amp;gt; news:396b1127.17754469@discussion.autodesk.com...&lt;BR /&gt;
&amp;gt; &amp;gt; I hope someone here can help me or point me in the right direction:&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; I am trying to transfer a suite of routines that I already wrote and&lt;BR /&gt;
&amp;gt; &amp;gt; debugged in VBA to an activex dll.  I am told this is the best way of&lt;BR /&gt;
&amp;gt; &amp;gt; making a robust / secure and fast application in visual basic.&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; I am using VB5 enterprise edition to compile the activex dll.&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; I realize that one of the issues that I need to attend to is&lt;BR /&gt;
&amp;gt; &amp;gt; initializing some of the objects that we get for free in vba&lt;BR /&gt;
&amp;gt; &amp;gt; (thisdrawing for instance).&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; I have written a simple public class whose job will be to farm out the&lt;BR /&gt;
&amp;gt; &amp;gt; work to the routines I have already written in standard .bas modules&lt;BR /&gt;
&amp;gt; &amp;gt; and initialize the important objects globally at the module level..&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; My problem is that I have quite a bit of debugging to do mainly due to&lt;BR /&gt;
&amp;gt; &amp;gt; the initialization of the thisdrawing object and others, and I can't&lt;BR /&gt;
&amp;gt; &amp;gt; figure out how to get the debugging process working.&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; I have read the help on books online but it doesn't seem to be&lt;BR /&gt;
&amp;gt; &amp;gt; applicable to the case where I am debbugging an in-process dll from an&lt;BR /&gt;
&amp;gt; &amp;gt; already existing application.  The best I understood  - I would need&lt;BR /&gt;
&amp;gt; &amp;gt; the acad.exe as well in the project group and I have no idea what that&lt;BR /&gt;
&amp;gt; &amp;gt; means nor how to do it.&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; If anyone could help shed some light on this issue I would be most&lt;BR /&gt;
&amp;gt; &amp;gt; obliged.&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; Thanks,&lt;BR /&gt;
&amp;gt; &amp;gt; Natan Elsberg&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;/NELSBERG&gt;&lt;/SNIP&gt;&lt;/SNIP&gt;</description>
      <pubDate>Tue, 11 Jul 2000 21:19:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/debugging-in-process-activex-dll/m-p/325677#M92057</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2000-07-11T21:19:53Z</dc:date>
    </item>
  </channel>
</rss>

