hi,
i'm having a bit of a problem in determining which autocad session / version
is accessing my common utilities dll file... what i'm after is something
similar to the vlisp vlax-product-key function, i have seen and tried
several different vb version of this, but they all have the same problem...
that is that they get the product key of the first opened AutoCAD session,
for instance, if i had 2 sessions of autocad opened, and while working in
the second section, i decide to change a system variable (i'm not sure of
the vb.net syntax, only 'cause i'm just starting) but the vb6 syntax is...
application.activedocument.setvariable "blarblar", "blar"
which changes the variable in the first opened session.
the vb examples of vlax-product-key access are as follow (one tries to get
the session from the registry, the other trys to get it from the active
window... this one causes problems if you're using a few apps at the same
time):
'[code]
Public Function AutoCADProductKey() As String
Dim sVer1 As String
Dim sVer2 As String
Dim odCRegistry As dC2004.dCRegistry
Set odCRegistry = New dC2004.dCRegistry
sVer1 = odCRegistry.ReadRegistry(HKEY_CURRENT_USER,
"SOFTWARE\Autodesk\Autocad", "CurVer")
sVer2 = odCRegistry.ReadRegistry(HKEY_CURRENT_USER,
"SOFTWARE\Autodesk\Autocad\" & sVer1, "CurVer")
AutoCADProductKey = "SOFTWARE\Autodesk\Autocad\" & sVer1 & "\" & sVer2
Set odCRegistry = Nothing
End Function
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias
"GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Function GetAutoCADVersion() As String
Dim sActiveWindowTitle As String
Dim vActiveWindowTitle As Variant
sActiveWindowTitle = GetActiveWindowTitle(True)
vActiveWindowTitle = Split(sActiveWindowTitle, " ")
If vActiveWindowTitle(0) = "AutoCAD" Then
GetAutoCADVersion = vActiveWindowTitle(1)
End If
End Function
Private Function GetActiveWindowTitle(ByVal ReturnParent As Boolean) As
String
Dim i As Long
Dim j As Long
i = GetForegroundWindow
If ReturnParent Then
Do While i <> 0
j = i
i = GetParent(i)
Loop
i = j
End If
GetActiveWindowTitle = GetWindowTitle(i)
End Function
Private Function GetWindowTitle(ByVal hwnd As Long) As String
Dim l As Long
Dim s As String
l = GetWindowTextLength(hwnd)
s = Space(l + 1)
GetWindowText hwnd, s, l + 1
GetWindowTitle = Left$(s, l)
End Function
'[code]
sorry for the long question, any help would be great
cheers
mark