Sign in to follow this  
Followers 0
lovesoo

How to passing char** in DllCall?

7 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



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

Thx a lot!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

What says the parameter description? May be, you need a nul-termination for this string:

DllStructSetData($FNStruct, "fns", "test123456" & Chr(0))
Edited by BugFix

Best Regards BugFix  

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

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