.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

which AutoCAD session is calling my DLL file

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
247 Views, 3 Replies

which AutoCAD session is calling my DLL file

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
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

Sounds like you need to go thru the windows api and look at the processes.
Unfortunately, I don't have an example handy, tho.

-- Mike
___________________________
Mike Tuersley
___________________________
the trick is to realize that there is no spoon...
Message 3 of 4
Anonymous
in reply to: Anonymous

Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLinker.ProductKey

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Mark Dubbelaar" wrote in message news:4935663@discussion.autodesk.com...
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
Message 4 of 4
Anonymous
in reply to: Anonymous

cheers


"Tony Tanzillo" wrote in message
news:4936404@discussion.autodesk.com...
Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLinker.ProductKey

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Mark Dubbelaar" wrote in message
news:4935663@discussion.autodesk.com...
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost