Jump to content

[Unresolved] Help with coverting VB6 to AU3


ken82m
 Share

Recommended Posts

I don't know VB so I can't make sense of most of this lol

But, I did find a conversion tool (input and output posted below).

I tried adding the $ to the variables and removing the $ from the "$As $Long"

but "long" doesn't seem to be recognized and I get a syntax error on the "As"

Can anyone help finish the conversion? :mellow:

It's supposed to bring up a window to browse for users.

Thanks,

Kenny

Input:

Private Const NERR_SUCCESS                          As Long = 0&
Private Const OPENUSERBROWSER_INCLUDE_SYSTEM          As Long = &H10000
Private Const OPENUSERBROWSER_SINGLE_SELECTION      As Long = &H1000&
Private Const OPENUSERBROWSER_NO_LOCAL_DOMAIN        As Long = &H100&
Private Const OPENUSERBROWSER_INCLUDE_CREATOR_OWNER   As Long = &H80&
Private Const OPENUSERBROWSER_INCLUDE_EVERYONE      As Long = &H40&
Private Const OPENUSERBROWSER_INCLUDE_INTERACTIVE    As Long = &H20&
Private Const OPENUSERBROWSER_INCLUDE_NETWORK        As Long = &H10&
Private Const OPENUSERBROWSER_INCLUDE_USERS        As Long = &H8&
Private Const OPENUSERBROWSER_INCLUDE_USER_BUTTONS  As Long = &H4&
Private Const OPENUSERBROWSER_INCLUDE_GROUPS          As Long = &H2&
Private Const OPENUSERBROWSER_INCLUDE_ALIASES        As Long = &H1&
Private Const OPENUSERBROWSER_FLAGS                As Long = OPENUSERBROWSER_INCLUDE_USERS Or _
                                                                OPENUSERBROWSER_INCLUDE_USER_BUTTONS Or _
                                                                OPENUSERBROWSER_INCLUDE_EVERYONE Or _
                                                                OPENUSERBROWSER_INCLUDE_INTERACTIVE Or _
                                                                OPENUSERBROWSER_INCLUDE_NETWORK Or _
                                                                OPENUSERBROWSER_INCLUDE_ALIASES
Private Type OPENUSERBROWSER_STRUCT
   cbSize       As Long
   fCancelled   As Long
   Unknown     As Long
   hWndParent   As Long
   szTitle     As Long
   szDomainName  As Long
   dwFlags     As Long
   dwHelpID   As Long
   szHelpFile   As Long
End Type

Private Type ENUMUSERBROWSER_STRUCT
   SidType      As Long
   Sid1        As Long
   Sid2        As Long
   szFullName    As Long
   szUserName    As Long
   szDisplayName  As Long
   szDomainName   As Long
   szDescription  As Long
   sBuffer      As String * 1000
End Type

Private Declare Function OpenUserBrowser Lib "netui2.dll" _
  (lpOpenUserBrowser As Any) As Long
   
Private Declare Function EnumUserBrowserSelection Lib "netui2.dll" _
  (ByVal hBrowser As Long, _
   ByRef lpEnumUserBrowser As Any, _
   ByRef cbSize As Long) As Long
   
Private Declare Function CloseUserBrowser Lib "netui2.dll" _
   (ByVal hBrowser As Long) As Long
   
Private Declare Function lstrlenW Lib "kernel32" _
   (ByVal lpString As Long) As Long
   
Private Declare Sub CopyMemory Lib "kernel32" _
   Alias "RtlMoveMemory" _
  (Destination As Any, _
   Source As Any, _
   ByVal Length As Long)


Private Sub Form_Load()

   Dim cnt As Long

  'load and show 11 Check1 controls
   For cnt = 0 To 10
      
      If cnt <> 0 Then Load Check1(cnt)
      
      With Check1(cnt)
      
         If cnt < 6 Then
            .Move 360, 360 + (Check1(cnt).Height * cnt), 2500
         Else
            .Move 2860, 360 + (Check1(cnt).Height * (cnt - 6)), 2500
         End If
         
         Select Case cnt
            Case 0:  .Caption = "include aliases"
            Case 1:  .Caption = "include groups"
            Case 2:  .Caption = "include user buttons"
            Case 3:  .Caption = "include users"
            Case 4:  .Caption = "include network"
            Case 5:  .Caption = "include 'interactive'"
            Case 6:  .Caption = "include 'everyone'"
            Case 7:  .Caption = "include 'creator owner'"
            Case 8:  .Caption = "include 'system'"
            Case 9:  .Caption = "single selection"
            Case 10: .Caption = "no local domain"
            Case Else
         End Select
      
         .Visible = True
      
      End With
      
   Next

   With Command1
      .Caption = "OpenUserBrowser"
      .Move Check1(5).Left, _
           (Check1(5).Height * 5) + 780
   End With
   
   With Text1
      .Move Command1.Left, _
            Command1.Top + Command1.Height + 300, _
            Me.ScaleWidth - 720
                  
      Me.Height = .Top + .Height + 780
      
   End With 
   
End Sub


Private Sub Command1_Click()

   Dim sUsers As String

   If GetBrowserNames(Me.hWnd, _
                      "\\vbnetdev", _
                      "VBnet Add Users & Groups Demo", _
                      sUsers) Then
      Text1.Text = sUsers
   End If

End Sub


Private Function BuildFlags() As Long

  'using a var to shorten web display ...
  'in application can replace var with
  'the function name itself
   Dim bf As Long

  'clear and set flags
   bf = 0&
   
   If Check1(0).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_ALIASES
   If Check1(1).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_GROUPS
   If Check1(2).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_USER_BUTTONS
   If Check1(3).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_USERS
   If Check1(4).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_NETWORK
   If Check1(5).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_INTERACTIVE
   If Check1(6).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_EVERYONE
   If Check1(7).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_CREATOR_OWNER
   If Check1(8).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_SYSTEM
   If Check1(9).Value = 1 Then bf = bf Or OPENUSERBROWSER_SINGLE_SELECTION
   If Check1(10).Value = 1 Then bf = bf Or OPENUSERBROWSER_NO_LOCAL_DOMAIN
   
   BuildFlags = bf

End Function


Private Function GetBrowserNames(ByVal hParent As Long, _
                                 ByVal sDomain As String, _
                                 ByVal sTitle As String, _
                                 sBuff As String) As Boolean

   Dim hBrowser   As Long
   Dim browser  As OPENUSERBROWSER_STRUCT
   Dim enumb      As ENUMUSERBROWSER_STRUCT
   
  'initialize the OPENUSERBROWSER structure
   With browser
      .cbSize = Len(browser)
      .fCancelled = 0
      .Unknown = 0
      .hWndParent = hParent
      .szTitle = StrPtr(sTitle)
      .szDomainName = StrPtr(sDomain)
      .dwFlags = BuildFlags()
   End With
   
  'show the dialog function
   hBrowser = OpenUserBrowser(browser)
   
  'if not cancelled...
   If browser.fCancelled = NERR_SUCCESS Then
   
      '...retrieve any selections and populate
      'the sBuff string passed to this function,
      'returning True if successful.
       Do While EnumUserBrowserSelection(hBrowser, enumb, Len(enumb) + 1) <> 0
       
          'return selection as \\DOMAIN\NAME
          'can be adjusted at will
           sBuff = sBuff & GetPointerToByteStringW(enumb.szDomainName) & "\" & _
                           GetPointerToByteStringW(enumb.szUserName) & vbCrLf
                           
           GetBrowserNames = True
           
       Loop
       
       Call CloseUserBrowser(hBrowser)
       
      'if desired, strip the last crlf from the string
       If GetBrowserNames = True Then
           sBuff = Left(sBuff, Len(sBuff) - 2)
       End If
   End If
    
End Function


Private Function GetPointerToByteStringW(ByVal dwData As Long) As String
  
   Dim tmp() As Byte
   Dim tmplen As Long
   
   If dwData <> 0 Then
   
      tmplen = lstrlenW(dwData) * 2
      
      If tmplen <> 0 Then
      
         ReDim tmp(0 To (tmplen - 1)) As Byte
         CopyMemory tmp(0), ByVal dwData, tmplen
         GetPointerToByteStringW = tmp
         
     End If
     
   End If
    
End Function

Output:

(see new post 11/24/08)

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Well i got so far, it would be helpful to know where you got the code... :mellow:

Dim Const $NERR_SUCCESS                        = 0
Dim Const $OPENUSERBROWSER_INCLUDE_SYSTEM        = 0x10000
Dim Const $OPENUSERBROWSER_SINGLE_SELECTION    = 0x1000
Dim Const $OPENUSERBROWSER_NO_LOCAL_DOMAIN      = 0x100
Dim Const $OPENUSERBROWSER_INCLUDE_CREATOR_OWNER  = 0x80
Dim Const $OPENUSERBROWSER_INCLUDE_EVERYONE    = 0x40
Dim Const $OPENUSERBROWSER_INCLUDE_INTERACTIVE  = 0x20
Dim Const $OPENUSERBROWSER_INCLUDE_NETWORK      = 0x10
Dim Const $OPENUSERBROWSER_INCLUDE_USERS          = 0x8
Dim Const $OPENUSERBROWSER_INCLUDE_USER_BUTTONS   = 0x4
Dim Const $OPENUSERBROWSER_INCLUDE_GROUPS        = 0x2
Dim Const $OPENUSERBROWSER_INCLUDE_ALIASES      = 0x1
Dim Const $OPENUSERBROWSER_FLAGS                  = $OPENUSERBROWSER_INCLUDE_USERS + $OPENUSERBROWSER_INCLUDE_USER_BUTTONS + $OPENUSERBROWSER_INCLUDE_EVERYONE + $OPENUSERBROWSER_INCLUDE_INTERACTIVE + $OPENUSERBROWSER_INCLUDE_NETWORK + $OPENUSERBROWSER_INCLUDE_ALIASES

Dim $OPENUSERBROWSER_STRUCT = "long cbSize;" & _
"long fCancelled;" & _
"long Unknown;" & _
"long hWndParent;" & _
"long szTitle;" & _
"long szDomainName;" & _
"long dwFlags;" & _
"long dwHelpID;" & _
"long szHelpFile;"

Dim $ENUMUSERBROWSER_STRUCT = "long SidType;" & _
"long Sid1;" & _
"long Sid2;" & _
"long szFullName;" & _
"long szUserName;" & _
"long szDisplayName;" & _
"long szDomainName;" & _
"long szDescription;" & _
"string sBufferl"

Func OpenUserBrowser ()
    $ret = DllCall("netui2.dll", "long", "OpenUserBrowser", "TYPE ANY GOES HERE.  I NEED MORE DOCUMENTATION.... :)", $lpOpenUserBrowser)
EndFunc
Link to comment
Share on other sites

sorry :mellow:

there you go: http://vbnet.mvps.org/index.html?code/netw...userbrowser.htm

If you search google for "OpenUserBrowser" you'll find a few different versions. I really don't care which one as long as it works lol

As long as it has the ability to pass the flags like INCLUDE_USERS so I can limit what a user can select.

Thanks,

Kenny

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Hi Ken,

I'm afraid I'll be going out now so I'm unable to help you for a while. Thanks for the link though. It should help whoever helps you and me if its not done by the time I get back... :mellow:

But I showed you a basic example of what I turned the function into, so you should have enough understanding to attempt the other DllCalls. I have no idea about a few of those other functions in there though.

Cheers,

Brett

Link to comment
Share on other sites

Thanks, I'll play with it but I'm not expecting much lol :mellow:

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

I have a headache lol :mellow:

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Not a hell of alot to post lol

The functions were killing me so I went back to the variables.

I think they have to be set up with DllStructCreate() but so far haven't had anything that looks correct.

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

I give up lol - they can just type it in if it blows up it blows up lol :)

Sucks that microsoft had to make this so hard. They don't even document the functions to call this dialog.

Somebody had to figure it out themselves.

I really appreciate you guys trying though.

When I have some free time here and there I'll play with it and see if I can get anywhere with it.

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Someone was able to help me with the DllStructCreate commands.

So here's what I've got now.

Kenny

Local $NERR_SUCCESS = 0
Local $OPENUSERBROWSER_INCLUDE_SYSTEM = 0x10000
Local $OPENUSERBROWSER_SINGLE_SELECTION = 0x1000
Local $OPENUSERBROWSER_NO_LOCAL_DOMAIN = 0x100
Local $OPENUSERBROWSER_INCLUDE_CREATOR_OWNER = 0x80
Local $OPENUSERBROWSER_INCLUDE_EVERYONE = 0x40
Local $OPENUSERBROWSER_INCLUDE_INTERACTIVE = 0x20
Local $OPENUSERBROWSER_INCLUDE_NETWORK = 0x10
Local $OPENUSERBROWSER_INCLUDE_USERS = 0x8
Local $OPENUSERBROWSER_INCLUDE_USER_BUTTONS = 0x4
Local $OPENUSERBROWSER_INCLUDE_GROUPS = 0x2
Local $OPENUSERBROWSER_INCLUDE_ALIASES = 0x1
Local $OPENUSERBROWSER_FLAGS = $OPENUSERBROWSER_INCLUDE_USERS Or $OPENUSERBROWSER_INCLUDE_USER_BUTTONS Or $OPENUSERBROWSER_INCLUDE_EVERYONE Or $OPENUSERBROWSER_INCLUDE_INTERACTIVE Or $OPENUSERBROWSER_INCLUDE_NETWORK Or $OPENUSERBROWSER_INCLUDE_ALIASES

$OPENUSERBROWSER_STRUCT = DllStructCreate("long cbSize;long fCancelled;long Unknown;long hWndParent;long szTitle;long szDomainName;long dwFlags;long dwHelpID;long szHelpFile")

$ENUMUSERBROWSER_STRUCT = DllStructCreate("long SidType;long Sid1;long Sid2;long szFullName;long szUserName;long szDisplayName;long szDomainName;long szDescription;long sBuffer")


Func OpenUserBrowser ($lpOpenUserBrowser)
    DLLCall("netui2.dll", "long", "OpenUserBrowser ", "any", $lpOpenUserBrowser)
EndFunc

Func EnumUserBrowserSelection (ByRef $hBrowser, ByRef $lpEnumUserBrowser, ByRef $cbSize)
    DLLCall("netui2.dll", "long", "EnumUserBrowserSelection ", "long", $hBrowser, "any", $lpEnumUserBrowser, "long", $cbSize)
EndFunc

Func CloseUserBrowser (ByRef $hBrowser)
    DLLCall("netui2.dll", "long", "CloseUserBrowser ", "long", $hBrowser)
EndFunc

Func lstrlenW (ByRef $lpString)
    DLLCall("kernel32", "long", "lstrlenW ", "long", $lpString)
EndFunc

Func CopyMemory ($Destination, $Source, $Length)
    DLLCall("kernel32", "long", "RtlMoveMemory", "any", $Destination, "any", $Source, "long", $Length)
EndFunc

;++++++++++++++++++++++++++++++++++++++++++++
;Partially converted by me
;++++++++++++++++++++++++++++++++++++++++++++

Func Form_Load()
   Dim $cnt

;load and show 11 Check1 controls
   For $cnt = 0 To 10
      
      If $cnt <> 0 Then Load $Check1($cnt);Check1 is what????
      
      With $Check1($cnt)
      
         If $cnt < 6 Then
            .Move 360, 360 + ($Check1($cnt).Height * $cnt), 2500
         Else
            .Move 2860, 360 + ($Check1($cnt).Height * ($cnt - 6)), 2500
         EndIf
         
         Select Case $cnt
            Case 0:  .Caption = "include aliases"
            Case 1:  .Caption = "include groups"
            Case 2:  .Caption = "include user buttons"
            Case 3:  .Caption = "include users"
            Case 4:  .Caption = "include network"
            Case 5:  .Caption = "include 'interactive'"
            Case 6:  .Caption = "include 'everyone'"
            Case 7:  .Caption = "include 'creator owner'"
            Case 8:  .Caption = "include 'system'"
            Case 9:  .Caption = "single selection"
            Case 10: .Caption = "no local domain"
            Case Else
         EndSelect
      
         .Visible = True
      
      EndWith
      
   Next

   With Command1
      .Caption = "OpenUserBrowser"
      .Move Check1(5).Left, _
           (Check1(5).Height * 5) + 780
   End With
   
   With Text1
      .Move $Command1.Left, _
            $Command1.Top + Command1.Height + 300, _
            $Me.ScaleWidth - 720
                  
      $Me.Height = .Top + .Height + 780
      
   EndWith 
EndFunc

Func Command1_Click()
   Dim $sUsers
   If GetBrowserNames($Me.hWnd, "\\vbnetdev", "VBnet Add Users & Groups Demo", $sUsers) Then $Text1.Text = sUsers
EndF`unc


Func BuildFlags()
;using a var to shorten web display ...
;in application can replace var with
;the function name itself
   $bf

;clear and set flags
   $bf = 0
   
   If $Check1(0).Value  = 1 Then $bf = $bf Or  $OPENUSERBROWSER_INCLUDE_ALIASES
   If $Check1(1).Value  = 1 Then $bf = $bf Or  $OPENUSERBROWSER_INCLUDE_GROUPS
   If $Check1(2).Value  = 1 Then $bf = $bf Or  $OPENUSERBROWSER_INCLUDE_USER_BUTTONS
   If $Check1(3).Value  = 1 Then $bf = $bf Or  $OPENUSERBROWSER_INCLUDE_USERS
   If $Check1(4).Value  = 1 Then $bf = $bf Or  $OPENUSERBROWSER_INCLUDE_NETWORK
   If $Check1(5).Value  = 1 Then $bf = $bf Or  $OPENUSERBROWSER_INCLUDE_INTERACTIVE
   If $Check1(6).Value  = 1 Then $bf = $bf Or  $OPENUSERBROWSER_INCLUDE_EVERYONE
   If $Check1(7).Value  = 1 Then $bf = $bf Or  $OPENUSERBROWSER_INCLUDE_CREATOR_OWNER
   If $Check1(8).Value  = 1 Then $bf = $bf Or  $OPENUSERBROWSER_INCLUDE_SYSTEM
   If $Check1(9).Value  = 1 Then $bf = $bf Or  $OPENUSERBROWSER_SINGLE_SELECTION
   If $Check1(10).Value = 1 Then $bf = $bf Or  $OPENUSERBROWSER_NO_LOCAL_DOMAIN
   
   $BuildFlags = $bf

EndFunc


Func GetBrowserNames($hParent, $sDomain, $sTitle , $sBuff)

   Dim $hBrowser
   Dim $browser = $OPENUSERBROWSER_STRUCT
   Dim $enumb   = $ENUMUSERBROWSER_STRUCT
   
;initialize the OPENUSERBROWSER structure
   With $browser
      .cbSize = Len($browser)
      .fCancelled = 0
      .Unknown = 0
      .hWndParent = $hParent
      .szTitle = DllStructCreate($sTitle & " dword")
      .szDomainName = DllStructCreate($sDomain & " dword")
      .dwFlags = BuildFlags()
   EndWith
   
;show the dialog function
    $hBrowser = OpenUserBrowser($browser)
   
;if not cancelled...
    If $browser.fCancelled = $NERR_SUCCESS Then
;...retrieve any selections and populate
;the sBuff string passed to this function,
;returning True if successful.
        Do While EnumUserBrowserSelection($hBrowser, $enumb, StringLen($enumb) + 1) <> 0
    ;return selection as \\DOMAIN\NAME
    ;can be adjusted at will
            $sBuff = $sBuff & GetPointerToByteStringW($enumb.szDomainName) & "\" & GetPointerToByteStringW($enumb.szUserName) & @CRLF
                           
            $GetBrowserNames = True
           
;Loop
       
        CloseUserBrowser($hBrowser)
       
;if desired, strip the last crlf from the string
        If GetBrowserNames = True Then
            $sBuff = StringLeft($sBuff, StringLen($sBuff) - 2)
        EndIf
    EndIf
    
EndFunc


Func GetPointerToByteStringW ( $dwData )
    Dim $tmp
    Dim $tmplen
   
    If $dwData <> 0 Then
      $tmplen = lstrlenW($dwData) * 2
        If $tmplen <> 0 Then
            ReDim $tmp(0 To ($tmplen - 1))
            CopyMemory($tmp(0), $dwData, $tmplen)
            GetPointerToByteStringW = $tmp
        EndIf
     
    EndIf
EndFunc
Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...