I am currently trying to get a pointer element back from .dll library (compiled using cygwin and gcc - Source code is in C). But when executing the C function inside of python. The programm just "crashes" without any errors. (I am running Windows 11 Pro 23H2) --- Python Code --- import win32api, win32con, ctypes path = r"PATH_TO_DLL_FILE" (Path is absolute) dll_handle = win32api.LoadLibraryEx(path, 0, win32con.LOAD_WITH_ALTERED_SEARCH_PATH) lib = ctypes.CDLL(path, handle=dll_handle) lib.getArray.restype = ctypes.POINTER(ctypes.c_int) print("TEST") result = lib.getArray() print("NICE") print(type(result)) print(result) --- Output using python 3.12.4 --- TEST --- C File --- #include <stdlib.h> #include <stdio.h> int* getArray() { int* arr = (int*)malloc(10 * sizeof(int)); if (arr == NULL) { return NULL; // Handle allocation failure } for (int i = 0; i < 10; i++) { arr = i; printf("%d\n", arr); } return arr; } void freeMem(int *arr) { free(arr); } int main(int argc, char const *argv[]) { return 0; } --- Cmd for compiling --- gcc -shared -o test.dll test.c I try everything I could find online to it (which was sadly not that much, but I think that is also because calling me a hobby-c-programmer would be to much. I primarily use python, but opted to use c for the speed (The finall code is for a microcontroller)). But what I can tell you is that importing the library just with ctypes.CDLL didnt work for me (absolute or relativ path) and only the approach with LoadLibraryEx did. But generell any function which doesnt return a pointer seems to be working just fine. (The current C Code with the pointer compiled to a .exe file then being run works also fine) If anyone could help, it would greatly appreciated Continue reading...