ctypes

ctypes.ArgumentError: argument 1: TypeError: Don't know how to convert parameter 1

ctypes.ArgumentError: argument 1: TypeError: Don't know how to convert parameter 1 Question: my code.. import ctypes import win32security h_token = win32security.OpenProcessToken(ctypes.windll.kernel32.GetCurrentProcess(), win32security.TOKEN_ALL_ACCESS) lpApplicationName = ctypes.c_wchar_p(rf"C:\Windows\System32\cmd.exe") lpCommandLine = ctypes.c_wchar_p("") dwCreationFlags = 0x00000010 lpEnvironment = None lpProcessAttributes = None lpThreadAttributes = None bInheritHandles = False ctypes.windll.advapi32.CreateProcessWithTokenW(h_token, 0, lpApplicationName, lpCommandLine, dwCreationFlags, lpEnvironment, None, lpProcessAttributes, lpThreadAttributes, bInheritHandles) my output… …

Total answers: 2

How to debug crashing C++ library loaded in python project

How to debug crashing C++ library loaded in python project Question: I am attempting to figure out why calling a function in a dynamically loaded lib crashes python. I’m doing the following, I have a C++ function in a dynamic library file, which is loaded in python using ctypes. I then call the function from …

Total answers: 1

How to call a field of CFUNCTYPE?

How to call a field of CFUNCTYPE? Question: I have a DLL (.dll for Windows, .so for Linux) and this autogenerated C header file for that DLL (excerpt): Edit notes tl;dr: I have updated my header excerpt and Python code because I had left out too much. Details: I had left out a bunch of …

Total answers: 1

How to use struct pointer from C in Python?

How to use struct pointer from C in Python? Question: This is a snippet from a C header for a Windows DLL that was generated by Kotlin Multiplatform/Native: typedef struct { struct { struct { // … } root; } kotlin; } libnative_ExportedSymbols; extern libnative_ExportedSymbols* libnative_symbols(void); From C, you would access the struct root like …

Total answers: 2

Why does adding multiprocessing prevent python from finding my compiled c program?

Why does adding multiprocessing prevent python from finding my compiled c program? Question: I am currently looking to speed up my code using the power of multiprocessing. However I am encountering some issues when it comes to calling the compiled code from python, as it seems that the compiled file disappears from the code’s view …

Total answers: 2

ShellExecuteA cannot execute '.exe' in Python (with. ctypes ShellExecuteA)

ShellExecuteA cannot execute '.exe' in Python (with. ctypes ShellExecuteA) Question: I have compiled below code but cannot execute the "PPP.exe". ‘.exe’ file exists same directory with ‘.py’ file. Why cannot working(or "open") this code?? Please let me know. import ctypes ctypes.windll.shell32.ShellExecuteA(0, ‘open’, "PPP.exe", None, None, 1) Asked By: Jung-soo Lee || Source Answers: Use ShellExecuteW. …

Total answers: 1

Calling a C function with a char* argument through python ctypes difference python2 and python3

Calling a C function with a char* argument through python ctypes difference python2 and python3 Question: I am converting a file from python2 to python3 that calls a C function using the ctypes module. The below minimal example works in python2, however raises the following error in python3 (3.11) OSError: exception: access violation writing 0x00000000000094E0 …

Total answers: 1

Cannot call C++ class function in Python

Cannot call C++ class function in Python Question: C++ code: #include <iostream> class DemoClass{ private: int a, b; public: DemoClass(int v1, int v2){ a = v1; b = v2; } void DemoFunction(){ std::cout << "Hello C++!" << std::endl; std::cout << "output: a = " << a << ", b = " << b << std::endl; …

Total answers: 1

How to pass a string pointer-to-pointer from C to Python?

How to pass a string pointer-to-pointer from C to Python? Question: I need to pass a string pointer-to-pointer from C to Python, so Python can update the pointer and C can read it later. Steps C set a char** C call Python Python allocate memory Python update the char** C read the string C Code: …

Total answers: 1

Mallocing and Freeing in C, but passing the pointer through Python via ctypes

Mallocing and Freeing in C, but passing the pointer through Python via ctypes Question: I would like to put a malloc a function in C. I would then like to call this function from Python 3.10 via ctypes.DLL. I then would like to free it. However, I get a segmentation fault. Here’s my very simple …

Total answers: 1