rodent1 Posted January 19, 2012 Posted January 19, 2012 (edited) Hi, I need to call a c++ dll and pass to it a pointer to an array of pointers to buffers. The DLL will then fill the buffers with GUID strings. But it seems that my array pointer is not valid. This is the latest of what I have tried: Dim $sJobIDs[100], $structJobIdsPtrs[100], $StructJobID, $JobIDsPtr ; for $i=0 to UBound($sJobIDs) - 1 $sJobIDs[$i]=" " ;enough space for a GUID $StructJobID = ByteStructFromString($sJobIDs[$i]) ;turn this string into a char array in a C++ structure $structJobIdsPtrs[$i] = DllStructGetPtr($StructJobID) ;store the pointer to the char array structure Next ; get a pointer to the first item in the array of pointers $JobIDsPtr = DllStructGetPtr(DllStructCreate("ptr", $structJobIdsPtrs[0])) msgbox(0,"","pointer value = " & $JobIDsPtr) Func ByteStructFromString ( byref $TheString ) Dim $struct = DllStructCreate ( "byte[" & StringLen ( $TheString ) & "]" ) DllStructSetData ( $struct, 1, StringToBinary ( $TheString ) ) Return $struct EndFunc But when I display the value of $JobIDsPtr, I get a zero. What am I doing wrong? Thanks Edited January 19, 2012 by rodent1
jaberwacky Posted January 20, 2012 Posted January 20, 2012 $StructJobID needs to store a struct so use DllStructCreate(Struct [,Pointer]). Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
JohnOne Posted January 20, 2012 Posted January 20, 2012 Could be something to do with OS arch maybe I'm not certain about that. But on my win 7 32 bit, I get the value of a pointer in the msgbox. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
kylomas Posted January 20, 2012 Posted January 20, 2012 But on my win 7 32 bit, I get the value of a pointer in the msgbox. as do I on my Win7 64bit machine (running autoit as 32 bit)kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
jaberwacky Posted January 20, 2012 Posted January 20, 2012 on this line $structJobIdsPtrs[$i] = DllStructGetPtr($StructJobID) ;store the pointer to the char array structure he is getting the pointer of a dllstruct, but $StructJobID isn't a dllstruct. Am I wrong? Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
JohnOne Posted January 20, 2012 Posted January 20, 2012 ByteStructFromString() func is returning a struct, so that is fine (I think) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
kylomas Posted January 20, 2012 Posted January 20, 2012 @LaCastiglione, I'm not sure that it is any more complicated than Local $structjobidsptrs = DllStructCreate("ptr[100]") Local $ptr_jobIDptrs = DllStructGetPtr($structjobidsptrs) kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
JohnOne Posted January 20, 2012 Posted January 20, 2012 "ptr[100]" Is that valid? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
AdmiralAlkex Posted January 20, 2012 Posted January 20, 2012 (edited) @rodent1 That's not how you create an array of something. As the helpfile tell you on the page for DllStructCreate(); Create arrays by adding '' after the data type: DllStructCreate("int;char[128]")now the second element is an array of 128 chars. Couple that knowledge with DllStructGetPtr() and you're finished. Actually, looking at ByteStructFromString() it seems you know all this. on this line $structJobIdsPtrs[$i] = DllStructGetPtr($StructJobID) ;store the pointer to the char array structure he is getting the pointer of a dllstruct, but $StructJobID isn't a dllstruct. Am I wrong? And what do you think DllStructCreate() returns? EDit: @kylomas Probably something like that. @JohnOne I'm not sure if you don't know how DllStructCreate() works or is trying to make a clever remark that 100 is too much/not the right amount. Edited January 20, 2012 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
rodent1 Posted January 20, 2012 Author Posted January 20, 2012 I like the simplicity of Kylomas's solution,Local $structjobidsptrs = DllStructCreate("ptr[100]") Local $ptr_jobIDptrs = DllStructGetPtr($structjobidsptrs) but it does not allocate the memory needed for the API to fill the data. I tried it as a long shot anyway. The API did not fill it. I have a API description to go by: Description : Retrieves a list of job IDs of the jobs currently on the server. The job_list array needs to be created and populated with pointers to buffers for the job IDs before calling this function. the maximum size of each job ID is 256 C prototype : HarmResult JOBM_getJobList( HarmSessionHandle *session, int32 skip, int32 max, char **job_list /* [] */, int32 *num_jobs, HarmNBTicket *nbticket) so I start by creating the buffers, then put them in cstructs, get a pointer to those, populate my array of pointers, put the array of pointers into a cstruct, but then I fail to get a pointer to it dim $struct_JobID ; stuct to hold GUIDs returned by API call Dim $ptr_JobIds[100] ; struct containing an array of pointers to job ID string buffers for $i=0 to UBound($ptr_JobIds) - 1 $struct_JobID = DllStructCreate("char[256]"); allocate memory for a 256 byte string struct $ptr_JobIds[$i] = DllStructGetPtr($struct_JobID); store a pointer to the job ID struct Next ; put the array $ptr_JobIds into a structure Dim $struct_ptr_JobIds = DllStructCreate("ptr", $ptr_JobIds) ; get a pointer to $struct_ptr_JobIds Dim $ptr_struct_ptr_JobIds = DllStructGetPtr($struct_ptr_JobIds) MsgBox(0,'Debug line ' & @ScriptLineNumber,'$ptr_struct_ptr_JobIds: I get a 0 value here!' & @lf & $ptr_struct_ptr_JobIds) ; put that pointer into a pointer struct Dim $struct_ptr_struct_ptr_JobIds = DllStructCreate("ptr", $ptr_struct_ptr_JobIds) Dim $ptr_ptr_JobIdPtrs = DllStructGetPtr($struct_ptr_struct_ptr_JobIds) The command DllStructGetPtr($struct_ptr_JobIds) returns a 0. I am a newbie in this area and appreciate all the help!
Shaggi Posted January 20, 2012 Posted January 20, 2012 autoit arrays != c arrays. you need to create a dllstruct for 100 ptrs, and fill each with a ptr to a created dllstruct, like this: const $MAX_BUF = 0xFF $job_list = dllstructcreate("ptr[100]") ; char ** job_list = (char**) malloc(100 * sizeof(char*)); const $p_job_list = dllstructgetptr($job_list) for $i = 1 to 100 ; for(int i = 0; i < 100; ++i) { dllstructsetdata($job_list, _ ;job_list[i] = $i, _ dllstructgetptr( _ dllstructcreate("char[" & $MAX_BUF & "]"))) ; (char*) malloc(MAX_BUF * sizeof(char)); next; } consolewrite("job_list is located at: " & $p_job_list & @CRLF) Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now