Using DllCall and Pass back Address to WIL
Keywords: dllcall binary buffer
Question:
I'm experimenting with writing customized DLLs in C++ to be used in our WinBatch scripts. I've written a DLL in C++ that passes back some numeric values to the WinBatch script. A sample DllCall statement I've used isb=0 a1=dllcall(dllname, void:"MyTest", word:b) Message("b is ", b)The MyTest function in the DLL returns some calculated value. The C++ Dll looks like this:__declspec(dllexport) void WINAPI PASCAL MyTest(int* len) { int i; i = 43; *len = i; }The Dll compiles and links ok but when I run the WinBatch, the value of b is displayed as 0 not the expected 43. I have success passing back string values using char* and lpbinary but not with int* and long (or word). Any ideas what I am missing?If I forget the b=0 statement before the dllcall, WinBatch aborts with a "Tag Overwrite 1" error message. But I guess that is supposed to happen.
Answer:
This should work:bb=BinaryAlloc(4) BinaryEODSet(bb,4) a1=dllcall(dllname, void:"MyTest", lpbinary:bb) b=BinaryPeek4(bb,0) BinaryFree(bb) Message("b is ", b)
Article ID: W12870Filename: Using Dll Created in C to Pass Address.txt