This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients amaury.forgeotdarc, belopolsky, eryksun, itsgk92, meador.inge, paul.moore, steve.dower, tim.golden, zach.ware
Date 2020-06-19.00:28:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1592526528.49.0.297608781504.issue41021@roundup.psfhosted.org>
In-reply-to
Content
Please provide complete code that can be compiled as is, and the required build environment. I wrote a similar example in C, compiled for x64 with MSVC, and it worked fine for me. Also, please provide more details about the error -- a traceback in a native debugger, exception analysis, or a dump file. 

One detail that stands out to me is that you set the ctypes callback return type to c_void_p -- instead of void (None). But that shouldn't cause a crash. Another concern is your use of WINFUNCTYPE (stdcall) and WinDLL instead of CFUNCTYPE (cdecl) and CDLL. In x64 they're the same, but it's still important to use the function's declared calling convention, for the sake of x86 compatibility. Make sure you're really using stdcall.

Here's the code that worked for me:

c/test.c:

    #include <windows.h>

    typedef void listen_fn(int, FILETIME);

    static void
    subscribe_thread(listen_fn *cb)
    {
        int i = 0;
        FILETIME systime;
        while (1) {
            GetSystemTimeAsFileTime(&systime);
            cb(i++, systime);
            Sleep(1000);
       }
    }

    void __declspec(dllexport)
    subscribe(listen_fn *cb)
    {
        CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)subscribe_thread, 
            cb, 0, NULL);
    }

test.py:

    import ctypes
    from ctypes import wintypes

    lib = ctypes.CDLL('c/test.dll')
    listen_fn = ctypes.CFUNCTYPE(None, ctypes.c_int, wintypes.FILETIME)

    @listen_fn
    def cb(val, ft):
        print(f"callback {val:03d} {ft.dwHighDateTime} {ft.dwLowDateTime}")

    print('press enter to quit')
    lib.subscribe(cb)
    input()
History
Date User Action Args
2020-06-19 00:28:48eryksunsetrecipients: + eryksun, paul.moore, amaury.forgeotdarc, belopolsky, tim.golden, meador.inge, zach.ware, steve.dower, itsgk92
2020-06-19 00:28:48eryksunsetmessageid: <1592526528.49.0.297608781504.issue41021@roundup.psfhosted.org>
2020-06-19 00:28:48eryksunlinkissue41021 messages
2020-06-19 00:28:48eryksuncreate