Hello,
I'm a newcomer to AutoIt. I wish to use AutoIt as quick test bank for Delphi DLLs which I'm developing quite heavily, as supplements to a freeware Basic clone. My development environment is MS Windows XP Pros SP3, with Delphi 6 Personal Edition.
Now, some of my DLL functions need a string pointer as inpur parameter. The function than modifies the string in-memory, using de passed string pointer as address to the first data bye of the string. I made certain that enough space is reserved where the pointer points to, so there is no risk of data corruption. All my functions return a single 32 bit signed integer value.
The first check I tried, tries to call a function defined in Delphi as follows:
function KGFdllVersion(pout: ptruint):integer; stdcall; export;
Thus, my function accepts a pointer pout to the first byte of a string (25 bytes fixed length). A 25 byte Ascii identification string will be returned ad that address. Ands the function will return a numeric integer value (it will actually be 190).
So, after looking at the documentation, I came up with the following script:
The initial value of $sver is just a space holder, with a security string stop at the end. I discovered that I fave to use the DllStruct commands to produce a real pointer. But problem: I only get nice memory violations. Calling the same function with the target Basic langage works just file, so the DLL isn't the problem. Just for information, here is the calling code in the Basic program:
When I replace line 6 with
Now, the question is: what have I missed ? I checked within the DLL function: both version do crash before I even can display the firct check message in the dll function. replacing "str*" with "ptr* (nonsens, I know), there is no more crash, the returned integer value is correct, but obviously the value of $stString hansn't be changed.
I'm a newcomer to AutoIt. I wish to use AutoIt as quick test bank for Delphi DLLs which I'm developing quite heavily, as supplements to a freeware Basic clone. My development environment is MS Windows XP Pros SP3, with Delphi 6 Personal Edition.
Now, some of my DLL functions need a string pointer as inpur parameter. The function than modifies the string in-memory, using de passed string pointer as address to the first data bye of the string. I made certain that enough space is reserved where the pointer points to, so there is no risk of data corruption. All my functions return a single 32 bit signed integer value.
The first check I tried, tries to call a function defined in Delphi as follows:
function KGFdllVersion(pout: ptruint):integer; stdcall; export;
Thus, my function accepts a pointer pout to the first byte of a string (25 bytes fixed length). A 25 byte Ascii identification string will be returned ad that address. Ands the function will return a numeric integer value (it will actually be 190).
So, after looking at the documentation, I came up with the following script:
Local $dll, $ver, $sver $sver = "1234567890123456789012345"+chr(0) Local $stString = DllStructCreate("char v[26]") DllStructSetData($stString, 1, $sver) $dll = DllOpen("AutoIt_test.dll") $ver = DllCall($dll, "int", "KGFdllVersion", "ptr", DllStructGetPtr($stString)) DllClose($dll) MsgBox(0,"",$ver[0]) MsgBox(0,"",DllStructGetData($stString,1))
The initial value of $sver is just a space holder, with a security string stop at the end. I discovered that I fave to use the DllStruct commands to produce a real pointer. But problem: I only get nice memory violations. Calling the same function with the target Basic langage works just file, so the DLL isn't the problem. Just for information, here is the calling code in the Basic program:
dim ver%, sver$ sver$ = "1234567890123456789012345" dll_on "AutoIt_test.dll" ver% = dll_call1("KGFdllVersion",adr(sver$)) message str$(ver%)+" = " + sver$
When I replace line 6 with
$ver = DllCall($dll, "int", "KGFdllVersion", "str*", $stString)there is no more crash, but the reserved space is unchanged. Obviously, the text string written by the DLL function goes somewhere, but not into my string variable.
Now, the question is: what have I missed ? I checked within the DLL function: both version do crash before I even can display the firct check message in the dll function. replacing "str*" with "ptr* (nonsens, I know), there is no more crash, the returned integer value is correct, but obviously the value of $stString hansn't be changed.