To compile an activex dll you need a suitable compiler, for example, Visual BASIC, Delphi etc. (and the ability to code in the appropriate language).
I've a busy weekend coming up but I'll try to provide a skeleton Visual BASIC version c/w the Visual LISP wrapper.
For this example I decide to kill a couple birds with one stone: Write a quick/small dll example in Visual BASIC, use said dll to return the IPAddress to the caller, and use the dll from Visual LISP. Note, in order to concisely demonstrate just how easy this is I'm leaving out error trapping and additional utility functions I would normally code as part of the application. While you may call
WMI functionality directly from Visual LISP (haven't tried it myself, but it should be no different than using the File System or Scripting Objects, which I have used in Visual LISP), I thought I'd do it from a dll for fun, so it's a somewhat contrived example.
So ... In Visual BASIC 6 (Professional or Enterprise) Start a new ActiveX project, call it
DLLTest.
Add one class to the project and name it
Utility. Put the following (minimilistic) code into said class (code was distilled from this MSDN
page):
Option Explicit
Private myWMIService As Object
Private Sub Class_Initialize()
On Error Resume Next
Set myWMIService = GetObject("winmgmts:\\.\root\cimv2")
End Sub
Private Sub Class_Terminate()
Set myWMIService = Nothing
End Sub
Function GetIPAddress() As String
On Error Resume Next
Dim IPConfigSet As Object, _
IPConfig As Variant, _
i As Integer
Set IPConfigSet = _
myWMIService.ExecQuery( _
"Select IPAddress " & _
"from Win32_NetworkAdapterConfiguration " & _
"where IPEnabled=TRUE")
For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
GetIPAddress = IPConfig.IPAddress(0)
Exit Function
End If
Next
End Function
Compile the project to
DLLTest.dll.
When you compile the
DLLTest.dll it (the dll) will automatically be registered on that machine. If you copy the
DLLTest.dll file to other machines you will have to register it via RegSvr32.exe (e.g. at dos: RegSvr32.exe path\dlltest.dll). This can be done at the DOS command line (as previously noted), a batch file, a shelled process from Visual BASIC, or even via a Visual LISP wrapper. I'm not going to supply that code in this post.
Now call the registered
DLLTest.dll from Visual LISP (minimal, non error trapped code):
(defun c:DLLTest ( )
(alert
(strcat
"IPAddress = ["
(vlax-invoke
(vla-GetInterfaceObject
(vlax-get-acad-object)
"DLLTest.Utility"
)
'GetIPAddress
)
"]"
)
)
(princ)
)
Enjoy.