Help with DllCalls
Posted: 20 Jan 2016, 10:54
I am "recycling" this thread for my latest issue having possibly figured out my original problem (original post is still below). I'm trying to perform a DllCall. I'm not particularly experienced in this, but I've managed a few successfully. However, this one is giving me bother. Here's what I have right now:and here's the C definition of the function:I'm quite confused about how to get this working. Also relevant are the following typedef statements from the C code:So InterceptionContext is just a void pointer (hence Ptr in my code) and InterceptionDevice is just an int (hence Int in my code). Some other functions seems to accept the context variable fine (generated by another DllCall), although I'm not completely sure.
As to what happens with this call: ErrorLevel is set to 0, so the call is apparently successful. However, hwid_buffer and output_size are both 0; neither should be as far as I'm concerned. The original function can be seen in this file.
Hope some of you can point out something I'm doing wrong! I wasn't sure how to pass the pointer to hwid_buffer, but from what I could find it seemed like this was the right way to do it :/
Original Post
I'm trying to access some strings stored in memory by a DLL call. Here's my current code:
As far as I can tell from the source code of the DLL (here), the DllCall should return a pointer to an array of pointers. I'm trying to de-reference the first element of that array. So I get the first Ptr from the address stored in "context", which should be another pointer, referencing a string. I store this address in handle1. Then I try to retrieve the string from this address. However, the third MsgBox never displays, and after ~15 seconds, the script exits with the exit code 3221225477.
Can anyone see what I might be doing wrong here? I'm not massively experienced with DllCalls, but I think I understand the basic concepts, and have some experience with pointers etc. from C programming. Thanks for any help.
EDIT: For some reference, the return type of interception_create_context(void) is defined like this:i.e. a void pointer. The value returned by the function is an array defined as follows:If I have a fundamental misunderstanding of the result of this in terms of what is resident in memory (see above for what I believe it to be), please let me know.
EDIT: From some googling, it looks like this exit code is an Access Violation - I'm thinking from looking at the DLL source code that what I'm trying to access may not be accessible to other programs :/ Which seems like it defeats the point of having it as a DLL?
EDIT: I realised that perhaps the stuff loaded into memory can only be accessed by the DLL through further DLL calls rather than directly in memory. I'll look into this a bit further then.
Code: Select all
hwid_buffer := 0
output_size := DllCall("interception.dll\interception_get_hardware_id", "Ptr", context, "Int", 1, "Ptr", &hwid_buffer, "UInt", 4, "Cdecl UInt")
MsgBox % "hw_id : " . ErrorLevel
MsgBox % hwid_buffer
MsgBox % output_size
Code: Select all
unsigned int interception_get_hardware_id(InterceptionContext context, InterceptionDevice device, void *hardware_id_buffer, unsigned int buffer_size)
Code: Select all
typedef void *InterceptionContext;
typedef int InterceptionDevice;
As to what happens with this call: ErrorLevel is set to 0, so the call is apparently successful. However, hwid_buffer and output_size are both 0; neither should be as far as I'm concerned. The original function can be seen in this file.
Hope some of you can point out something I'm doing wrong! I wasn't sure how to pass the pointer to hwid_buffer, but from what I could find it seemed like this was the right way to do it :/
Original Post
I'm trying to access some strings stored in memory by a DLL call. Here's my current code:
Code: Select all
context := DllCall("interception.dll\interception_create_context")
MsgBox % context
handle1 := NumGet(context,0,"Ptr")
MsgBox % handle1
MsgBox % StrGet(handle1)
DllCall("interception.dll\interception_destroy_context", Ptr, context)
Can anyone see what I might be doing wrong here? I'm not massively experienced with DllCalls, but I think I understand the basic concepts, and have some experience with pointers etc. from C programming. Thanks for any help.
EDIT: For some reference, the return type of interception_create_context(void) is defined like this:
Code: Select all
typedef void *InterceptionContext;
Code: Select all
typedef struct
{
void *handle;
void *unempty;
} *InterceptionDeviceArray;
EDIT: From some googling, it looks like this exit code is an Access Violation - I'm thinking from looking at the DLL source code that what I'm trying to access may not be accessible to other programs :/ Which seems like it defeats the point of having it as a DLL?
EDIT: I realised that perhaps the stuff loaded into memory can only be accessed by the DLL through further DLL calls rather than directly in memory. I'll look into this a bit further then.