Jump to content

How to passing char** in DllCall?


lovesoo
 Share

Recommended Posts

Does anyone can supply me a example for "passing char** in DllCall"?

I looked at the DllStructCreate and DllStructGetPtr, but it seems doesn't work correctly.

Code like that:

$FNStruct = DllStructCreate("char fns[128];")
DllStructSetData($FNStruct, "fns", "test123456")

DllCall($dll, "int:cdecl","TestXXX", "ptr", DllStructGetPtr($FNStruct))
Edited by lovesoo
Link to comment
Share on other sites

Code is:

$FNStruct = DllStructCreate("char fns[128];")
DllStructSetData($FNStruct, "fns", "TestDWF01.txt")

DllCall($dll, "int:cdecl","TestXXX", "ptr", DllStructGetPtr($FNStruct))

Through the DLL I saw the value is 't' not "TestDWF01.txt" , the value i gave it.

use the code below, got the same result

DllStructSetData($FNStruct, "fns", "TestDWF01.txt" & Chr(0))
Edited by lovesoo
Link to comment
Share on other sites

$s = DllStructCreate("ptr ppfname;ptr pfname;char fname[200]") ; struct ptr { char fname[200])

; p1 = address of fname
$p1 = dllStructGetptr($s, 3) ; p1 = address of fname
dllStructSetData($s, 2, $p1) ; set "address of fname" to pfname

;p2 = address of p1
$p2 = DllStructGetPtr($s, 2)
dllStructSetData($s, 1, $p1)

ConsoleWrite("p1 = " & $p1 & @CRLF)
ConsoleWrite("p2 = " & $p2 & @CRLF)

I'll try this at first

Link to comment
Share on other sites

I'd try

$str = "TestDWF01.txt"

DllCall($dll, "int:cdecl","TestXXX", "str*", $str)

"str" can be passed in meaning LPCSTR which is char*, so adding "*" to "Str" = "str*"

might create char**

And maybe it wont. Worth a pop though.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

$text = dllstructcreate("char[128]") ;create buffer
dllstructsetdata($text,1,"Hi")

$ptr = dllstructcreate("ptr") ;create a pointer to the buffer. works like char * text = "hi";
dllstructsetdata($ptr,1,dllstructgetptr($text))

dllcall(..., "ptr", dllstructgetptr($ptr)) ; pass a pointer to the pointer. works like char**
;dllcall(..., "struct*", $ptr) ; might work too

beware though, char** parameters is not unusual syntax for passing an array of strings in c. this will work like an 1-sized array with first index set as "hi". it could also be the function intends to change the text $ptr points too - you dont do double inderection without a reason (usually).

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

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...