Skip to content Skip to sidebar Skip to footer

Access Violation Using Python Ctypes

I am trying to import and use a function from a DLL using Pythons ctypes module, but I keep getting this error: Windows Error: exception: access violation writing 0x0000002C I'v

Solution 1:

The length of your licenseKey buffer is one byte, and you are not passing Unicode strings. I'm not in front of my PC, but I this should be close assuming your parameters are otherwise correct. Make sure to call the W version of the function. You also don't need to create the exact types as long as they are ints and pointers.

buffer = create_string_buffer(REQUIRED_BUFSIZE)
mydll.WLGenLicenseKeyW(u"A.N. Body", u"ACME", u"APC44567", None, None, 0, 0, None, 0, 0, 0, buffer)

If you do want to use argtypes, then this is what you want:

mydll.WLGenLicenseKeyW.argtypes = [c_wchar_t,c_wchar_t,c_wchar_t,c_wchar_t,c_wchar_t,c_int,c_int,c_void_p,c_int,c_int,c_int,c_char_p]

SYSTEMTIME would also need to be defined if you want to pass something besides NULL.

edit

I found some documentation. The function uses the stdcall calling convention, so use:

mydll = WinDLL(dll)

Post a Comment for "Access Violation Using Python Ctypes"