Trying to load and use a dll file in python properly

0

I am trying to load and use a dll in python. I have been trying to use windows-kill but I don't know much at all about C++. I was able to compile it fine in visual studio and the exe file works fine but I'd like to figure out how to load the dll with Python so I can learn how to load other dll's that I may want to use eventually.
So far this is the code I have come up with. I wasn't sure if it needed SIGINT or a number for the value because the command line uses -SIGINT but I have been trying both.

lib = ctypes.CDLL('windows-kill-library.dll')
libOpen = getattr(lib, "?sendSignal@WindowsKillLibrary@@YAXKK@Z")
libOpen.argtypes = [wintypes.DWORD, wintypes.DWORD]
val = 'SIGINT'
# val = 0
l = libOpen(9844, val)
print(l)

Using SIGINT as the val I get the error:

ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type

and using a number as a value I get:

OSError: [WinError -529697949] Windows Error 0xe06d7363

I know the argtypes must be wrong or something but I have been trying lots of different things and getting the same errors.

This is the undecorated name:

void WindowsKillLibrary::sendSignal(unsigned long,unsigned long)

I have tried using ctypes.c_ulong and some others for the argtypes but still get the same errors.

In visual studio when I hover over DWORD in the 2 lines below:

DWORD signal_type;
DWORD signal_pid;

It says "typedef unsigned long DWORD" if that helps.

Here is also the usage example that can be found here

/// <summary>
/// Sends the signal.
/// </summary>
/// <param name="signal_pid">The signal target process id.</param>
/// <param name="signal_type">The signal type.</param>
void sendSignal(DWORD signal_pid, DWORD signal_type);

Does anyone know how I can make this work? Thanks.

python
c++
windows
ctypes
asked on Stack Overflow Jun 14, 2018 by Richard

1 Answer

0

You're needing a DLL because Windows doesn't have a native signal facility, so the library is emulating the POSIX signal functionality. POSIX SIGINT is the numeric value 2, which is a perfectly fine value for the DWORD. That constant 2 is conveniently available as signal.SIGINT.value.

answered on Stack Overflow Jun 14, 2018 by MSalters

User contributions licensed under CC BY-SA 3.0