Jump to content

Return Text from Dllcall


Recommended Posts

does anyone know how to call this function from a dll?

void __cdecl GetPlayerName(void *,int *);

Others i can do - this one i cant figure out.

The function is passed 2 pointers and I guess that the void pointer tells it where to write the name and the int pointer tells it how many characters it can write, but it might be an offset. Something like this might work.

$ans = DllStructCreate("chr[256]")
$size = DllStructCreate("int")
DllStructSetData($Size,1,255)
$res = DllCall("dllname.dll","int:cdecl","GetPlayerName","ptr",DllStructGetPtr($ans),"int_ptr",DllStructGetPtr($size))
MsgBox(0,'name is',DllStructGetData($ans,1))

I don't know how many characters can be used for a name so 255 + 1 for the NULL terminator seemed safe. If the second parameter is an offset and not the allowed length of the name then maybe set the size value to zero instead of 255.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

This could also be done with one struct I think:

$nameStruct = DllStructCreate("char[256];int")
DllStructSetData($nameStruct, 2, "256")
$Result = DllCall("dllname.dll", "int:cdecl", "GetPlayerName", "ptr", DllStructGetPtr($nameStruct, 1), "int*", DllStructGetPtr($nameStruct, 2))
If @error Then Exit(@error)
ConsoleWrite($Result[0] & @LF)

Also, int_ptr is old, use int* instead..

Link to comment
Share on other sites

Also, int_ptr is old, use int* instead..

From the help for 3.2.11.5

lresult/int_ptr/long_ptr an integer big enough to hold a pointer when running on x86 or x64 versions of AutoIt.

lparam/int_ptr/long_ptr an integer big enough to hold a pointer when running on x86 or x64 versions of AutoIt.

wparam/uint_ptr/ulong_ptr an unsigned integer big enough to hold a pointer when running on x86 or x64 versions of AutoIt.

* Add * to the end of another type to pass it by reference. For example "int*" passes a pointer to an "int" type.

onestcoder didn't say if he was running on 32 or 64 bit OS so if he's using Beta then int_ptr is safer, using int* for an address pointer is a bit old fashioned now. :)

If he's using the production version then you are right although I expect this will eventually be changed.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

This is what i tried first: the result was "1" not the name :)

$dll = DllOpen("FFACE.dll")
$nameStruct = DllStructCreate("char[256];int")
DllStructSetData($nameStruct, 2, "256")
$Result = DllCall($dll, "int:cdecl", "GetPlayerName", "ptr", DllStructGetPtr($nameStruct, 1), "int*", DllStructGetPtr($nameStruct, 2))
If @error Then Exit(@error)
$test = ConsoleWrite($Result[0] & @LF)
MsgBox(0,'name is',$test)
DllClose($dll)

Then I tried this second: and autoit crashed :)

$dll = DllOpen("FFACE.dll")
$ans = DllStructCreate("chr[256]")
$size = DllStructCreate("int")
DllStructSetData($Size,1,255)
$res = DllCall($dll,"int:cdecl","GetPlayerName","ptr",DllStructGetPtr($ans),"int_ptr",DllStructGetPtr($size))
MsgBox(0,'name is',DllStructGetData($ans,1))
DllClose($dll)

Need a website: http://www.iconixmarketing.com

Link to comment
Share on other sites

This is what i tried first: the result was "1" not the name :)

$dll = DllOpen("FFACE.dll")
$nameStruct = DllStructCreate("char[256];int")
DllStructSetData($nameStruct, 2, "256")
$Result = DllCall($dll, "int:cdecl", "GetPlayerName", "ptr", DllStructGetPtr($nameStruct, 1), "int*", DllStructGetPtr($nameStruct, 2))
If @error Then Exit(@error)
$test = ConsoleWrite($Result[0] & @LF)
MsgBox(0,'name is',$test)
DllClose($dll)

Then I tried this second: and autoit crashed :)

$dll = DllOpen("FFACE.dll")
$ans = DllStructCreate("chr[256]")
$size = DllStructCreate("int")
DllStructSetData($Size,1,255)
$res = DllCall($dll,"int:cdecl","GetPlayerName","ptr",DllStructGetPtr($ans),"int_ptr",DllStructGetPtr($size))
MsgBox(0,'name is',DllStructGetData($ans,1))
DllClose($dll)
I see I had the types round the wrong way.

I should have written

$res = DllCall($dll,"int:cdecl","GetPlayerName","int_ptr",DllStructGetPtr($ans),"int*",DllStructGetPtr($size))

Try it but I am not hopeful.

Also try this modified version of FreeFry's. You are thinking that the return from the dll is the name but it's not, the dll writes the name in the struct by my guess.

$dll = DllOpen("FFACE.dll")
$nameStruct = DllStructCreate("char[256];int")
DllStructSetData($nameStruct, 2, "256")
$Result = DllCall($dll, "int:cdecl", "GetPlayerName", "ptr", DllStructGetPtr($nameStruct, 1), "int*", DllStructGetPtr($nameStruct, 2))
If @error Then Exit(@error)
$test = ConsoleWrite($Result[0] & @LF)
MsgBox(0,'name is',dllstructgetdata($namestruct,1))
DllClose($dll)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

SUCCESS!!!! O HAPPY DAY

This worked. THANK YOU

$dll = DllOpen("FFACE.dll")
$running = DllCall($dll, "int", "InitFFACE")
$nameStruct = DllStructCreate("char[256];int")
DllStructSetData($nameStruct, 2, "256")
$Result = DllCall($dll, "int:cdecl", "GetPlayerName", "ptr", DllStructGetPtr($nameStruct, 1), "int*", DllStructGetPtr($nameStruct, 2))
If @error Then Exit(@error)
$test = ConsoleWrite($Result[0] & @LF)
MsgBox(0,'name is',dllstructgetdata($namestruct,1))
DllClose($dll)

Thank you both for your time and effort.

/bow humbly

Need a website: http://www.iconixmarketing.com

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
 Share

  • Recently Browsing   0 members

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