Jump to content

solved: need help with a .dll


Sven
 Share

Recommended Posts

Ninjabob7 over at the Autohotkey forums compiled a library to be used with PPJoy, complete with sourcecode and an example. However I'd very much love to use this .dll in AutoIt, so I tried porting his example functions. But I'm out of luck, because I can't seem to get it to work. Perhaps you guys can lend me a hand?

$axis = 2
$value = 100
$init = ""

$dll = DllOpen(@Scriptdir & "\PPJoy.dll")
$init = DllCall($dll, "none", "Initialize")

sleep(1000)

dllcall($dll, "none", "SetAxisPercent", "char", $axis - 1, "char", $value)
dllcall($dll, "none", "Update")

sleep(1000)
This is what I got, but like I said above I'm stuck and have no idea where to start debugging. Never tried digging into a .dll before. Any help would be greatly appreciated.

I've attached everything to this posting, but if you don't want to download anything, these are the two core functions from which I should be able to continue once they're ported:

PPJ_Init()
{
    hModule := DllCall("LoadLibrary", "str", "PPJoy.dll")
    Result := DllCall("PPJoy\Initialize")
}

PPJ_SetAxis(axis, value)
{
    DllCall("PPJoy\SetAxisPercent", "char", axis - 1, "char", value)
    DllCall("PPJoy\Update")
}

PPJoy.zip

Edited by Sven
Link to comment
Share on other sites

Turns out AutoIt crashes when the dll is called correctly. A bug in AutoIt maybe?

I've updated the .dll so it triggers its "Update" function by itself, circumventing the need to call it in AutoIt. Since now "Update" is triggered independently from AutoIt, you can see the joystick cursor move, just before AutoIt crashes.

The .dll was also updated to support absolute coordinates in addition to giving just a percentage value, and data types for axis and values are now integers due to uniformity. It just feels strange to have chars for the percentages, when the absolutes need integers because the chars are too small.

Updated AutoIt code:

$axis = 2
$value = 10000

$dll = DllOpen(@Scriptdir & "\test12.dll")
DllCall($dll, "none", "Initialize")

sleep(3000)

dllcall($dll, "none", "SetAxisAbsolute", "int", $axis - 1, "int", $value)

sleep(1000)

Attached to this posting is the updated version of ppjoy.dll. It contains a new function called "SetAxisAbsolute".

To reproduce the crash, you need to download and install PPJoy: Link

It's a virtual joystick driver that unfortunately only works well with x64 Vista and Win7 if these OSes have been put into test mode, which allows to use unsigned or not officially signed drivers. x86 versions of both OSes are fine.

After PPJoy is installed, put the attached .dll into the same directory together with the above code, open the "PPJoy Virtual Joystick 1 properties" window, run my script, quickly reactivate the Joystick 1 properties window (cursor position will only be updated if that window is active) and watch for the joystick cursor to move and AutoIt to crash.

TL;DR section: The above code causes AutoIt to crash, the below code for AutoHotkey works flawlessly:

axis := 2
value := 10000

DllCall("LoadLibrary", "str", "ppjoy.dll")
DllCall("ppjoy\Initialize")

sleep, 3000

DllCall("ppjoy\SetAxisAbsolute", "int", axis - 1, "int", value)

sleep, 1000

:Edit

Sorry, my bad. Went with the default "use run-time library" setting, which was set to "multithreaded", when instead it seems necessary to set it to "Multithreaded DLL" or "Single Threaded". Happens when you're a C++ noob like myself. Anyway, attached to this thread now is the fixed ppjoy.dll which works without crashing AutoIt.

ppjoy.zip

Edited by Sven
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...