Jump to content

DllCall troubles

Recommended Posts

Okay, here's the C++ source of the DLL function I'm calling:


extern "C"__declspec(dllexport) float ReadFloat ( long pid, void *address ) {
    DWORD read=0;
    float valread=0;
    HANDLE gamehandle;

    gamehandle=OpenProcess(PROCESS_ALL_ACCESS, false, pid);
    if( gamehandle == 0 ) {
        return -2;
    } else {
        ReadProcessMemory(gamehandle, address, &valread, 4, &read);
        if( read == 0 ) {
            return -1;
        } else {
            return valread;

And here is the function that I'm having problems with:


Func _ReadFloat($EXEName, $Address)
    Local $ProcessID = ProcessExists($EXEName)
    If Not $ProcessID = 0 Then
        Local $ret = DllCall("AU3ReadWriteMemory.dll", "long", "ReadFloat", "long", $ProcessID, "long", $Address)
        If @error Then
            Return -2
            msgbox(0, "", $ret[0])
            Return $ret[0]
        Return -3

The problem is that I cannot get it to return a Float/Single type variable, or even a string with a decimal, seemingly no matter what I try. I'm all out of ideas.

My crappy quick-fix was to chang "float ReadFloat" to "long ReadFloat" and convert valread to a long type variable before returning it -- it returns everything up until the decimal, which is better than nothing -- but it bugs me that I cannot get it to return the Float.

I'm sure it's something extremely simple or just a limitation of AutoIt's DllCall function, but, being as this is my second day on both C++ coding and using DllCall, I cannot figure it out for the life of me. Any help would be very appreciated.


Link to comment
Share on other sites

If you use the beta version of autoit and change your function to have a pointer to a float for the return:

extern "C"__declspec(dllexport) float ReadFloat ( long pid, void *address, float *ret )

Then you could do:

$float_struct = DllStructCreate("float")
Local $ret = DllCall("AU3ReadWriteMemory.dll", "long", "ReadFloat", "long", $ProcessID, "long", $Address,"ptr",DllStructPtr($float_struct))
$float = DllStructGet($float_struct,1)
return $float
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Link to comment
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...