Sign in to follow this  
Followers 0
lcloki

Problem with this DllCall()

5 posts in this topic

Hello,

I ve got a problem with this call. The call itself seems to be fine, but i think there is no data returned!?

btw: The ip is fine and the call returns 0, if i change it to "192.168.1.7" which doesnt exist it returns 1722 (RPC_S_SERVER_UNAVAILABLE).

NetQueryDisplayInformation() - MSDN Library Directlink

Can somebody help me to find th error?

Here is my code:

$buffer  = DllStructCreate("char[256];char[256];dword;dword;dword")
    $number  = 1

    $res     = DllCall( "netapi32.dll", "int", "NetQueryDisplayInformation", _
                        "wstr", "\\192.168.1.1", _                      
                        "int", 3, _                         
                        "int", 0, _                         
                        "int", 1000, _                      
                        "int", -1, _                        
                        "int_ptr", $number, _
                        "ptr", DllStructGetPtr($buffer))

    MsgBox(0, "",   "number: " & $number & @CRLF & _
                    "buffer: " & $buffer & @CRLF & _
                    "@error: " & @error)
                    
    MsgBox(0, "",   "#1: " & $res[0] & @CRLF & _
                    "#2: " & $res[1] & @CRLF & _
                    "#3: " & $res[2] & @CRLF & _
                    "#4: " & $res[3] & @CRLF & _
                    "#5: " & $res[4] & @CRLF & _
                    "#6: " & $res[5] & @CRLF & _
                    "#7: " & $res[6] & @CRLF & _
                    "#8: " & $res[7])
    
    MsgBox(0, "",   "#1: " & DllStructGetData($buffer,1) & @CRLF & _
                    "#2: " & DllStructGetData($buffer,2) & @CRLF & _
                    "#3: " & DllStructGetData($buffer,3) & @CRLF & _
                    "#4: " & DllStructGetData($buffer,4) & @CRLF & _
                    "#5: " & DllStructGetData($buffer,5) )

    DllStructDelete($buffer)

Share this post


Link to post
Share on other sites



Can somebody help me to find th error?

Firstly, the SortedBuffer is system-allocated so I think the dllstruct declaration should be:

$buffer  = DllStructCreate("ptr;ptr;dword;dword;dword")

You will also need to call NetApiBufferFree before deleting the struct.

Secondly, the strings returned are unicode strings and will need to be converted ansi.

Share this post


Link to post
Share on other sites

So, okay. But if you set the Declaration to

$buffer  = DllStructCreate("ptr;ptr;dword;dword;dword")

you have only two pointers. but how to retrieve the unicode string?

By the way:

The code returns "0a"

Looks like unicode ... :whistle:

But the lenght is too short ...

Share this post


Link to post
Share on other sites

So, okay. But if you set the Declaration to

$buffer  = DllStructCreate("ptr;ptr;dword;dword;dword")

you have only two pointers. but how to retrieve the unicode string?

By the way:

The code returns "0a"

Looks like unicode ... :whistle:

But the lenght is too short ...

<{POST_SNAPBACK}>

WideCharToMultiByte

AutoIT cannot handle/display unicode property and that's why you can't see the rest of the data in your buffer. Converting it to ANSI using the above API should do the trick.

Share this post


Link to post
Share on other sites

So,

i am hanging here too ... :whistle:

Func _WideCharToMultiByte($str)

$buffer  = DllStructCreate("char[256]")

$res  = DllCall( "kernel32.dll", "int", "WideCharToMultiByte", _

      "int", 1141, _

      "int", 400, _

      "wstr", $str, _

      "int", -1, _

      "str", ($buffer), _

      "int", 256, _

      "int", 0, _

      "int", 0)

   

MsgBox(0, "", "#1: " & $res[0] & @CRLF & _

    "#2: " & $res[1] & @CRLF & _

    "#3: " & $res[2] & @CRLF & _

    "#4: " & $res[3] & @CRLF & _

    "#5: " & $res[4] & @CRLF & _

    "#6: " & $res[5] & @CRLF & _

    "#7: " & $res[6] & @CRLF & _

    "#8: " & $res[7])

MsgBox(0, "",  "#1: " & DllStructGetData($buffer,1) & @CRLF & _

    "#2: " & DllStructGetData($buffer,2) & @CRLF & _

    "#3: " & DllStructGetData($buffer,3) & @CRLF & _

    "#4: " & DllStructGetData($buffer,4) & @CRLF & _

    "#5: " & DllStructGetData($buffer,5) )

DllStructDelete($buffer)

Return ""

EndFunc

$buffer  = DllStructCreate("char[256];char[256];dword;dword;dword")

$number  = 0

$res  = DllCall( "netapi32.dll", "int", "NetQueryDisplayInformation", _

      "wstr", "\\192.168.1.1", _     

      "int", 3, _     

      "int", 0, _     

      "int", 1000, _     

      "int", -1, _     

      "int_ptr", $number, _

      "ptr", DllStructGetPtr($buffer))

;MsgBox(0, "", _WideCharToMultiByte(DllStructGetData($buffer,1)))

DllStructDelete($buffer)

So,

an ANSI-String consists of 8 Bit, that makes 2^8=256 possibilities to store symbols. Each number is assigned with a specifiy symbol. So far so good,

An Unicode-String consists of 16 bit, that makes 2^16=65536 possibilites to store symbols. The first 256 symbols in ANSI are the same as they are in Unicode, but how can i difference between them, if i use in both Strings only synmols below 256? :dance:

Please correct me, if i am wrong...

btw: how can i create a unicode string for testing purposes (for testing with my _ WideCharToMultiByte function)?

something like ...

$tmp = chr(46) & chr(49) & chr(52) & ...

would be great...

Share this post


Link to post
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
Sign in to follow this  
Followers 0