• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    *Mark Dubbelaar

    which AutoCAD session is calling my DLL file

    75 Views, 3 Replies
    08-22-2005 11:46 PM
    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
    Please use plain text.
    *Mike Tuersley

    Re: which AutoCAD session is calling my DLL file

    08-23-2005 07:55 AM in reply to: *Mark Dubbelaar
    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...
    Please use plain text.
    *Tony Tanzillo

    Re: which AutoCAD session is calling my DLL file

    08-23-2005 11:25 AM in reply to: *Mark Dubbelaar
    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
    Please use plain text.
    *Mark Dubbelaar

    Re: which AutoCAD session is calling my DLL file

    08-23-2005 05:46 PM in reply to: *Mark Dubbelaar
    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
    Please use plain text.