Python Forum

Full Version: DLL library with ctypes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I have a SDK DLL which is documented in c++ only and I am trying to use a few functions from that library.
It is a SDK to control a special camera and convert the RAW images from that camera to RGB.
Most of them I got working so far, but I can't figure out how to get the conversion function working.
From what I saw from the documentation, you need to allocate a buffer first and then pass the allocated
buffer address to the conversion function.
Buffer allocation works fine and returns without error, but the conversion always fails with:
"OSError: exception: access violation reading 0x00000158F7991000"

Here is what I did so far:

#buffer:
BufNum = c_short()
BufSize = c_ulong
BufAdr = (POINTER(ctypes.c_ushort) * 1)()

BufSize = 1920 * 1440 *sizeof(c_ushort)
	
iRet = AllocateBuffer(cam_handle, byref(BufNum), BufSize, byref(BufAdr), byref(buf_handle))  
if iRet == 0:
   print("buffer allocated successful")

IMG = create_string_buffer(((1920 + 4) * 1440 * 3))
#evertyhing works fine until here
Convert16TOCOL(conv_handle, 0,0,1920, 1440, BufAdr, IMG)
In the documentation it says:
a.) Prototype:
int PCOCONVERT_API PCO_Convert... (HANDLE ph, int imode, int icolormode, int width, int height, word
*b16, ...)
b.) Input parameter:
· HANDLE ph: Handle to a previously created convert object.
· int imode: Mode parameter.
· int icolmode: Color mode parameter
· int width: Width of the image to convert
· int height: Height of the image to convert
· word *b16: Pointer to the raw image
· …: Pointer to the resulting image; Either a byte* or a word*

The example implementation in c++ does the following:

int iRetCode = PCO_AllocateBuffer(hCam, (SHORT*)&m_wBufferNr, m_wXResMax * m_wYResMax * sizeof(WORD), &m_pic12, &m_hEvent);

m_hBmp = CreateDIBSection(m_myHdc, (BITMAPINFO *)&bilut.bih, // Create a memory Bitmap
DIB_RGB_COLORS,
(void **)&m_pic8,
NULL, 0);


iRetCode = PCO_Convert16TOCOL(hColConvert, imode, imosaik, m_wXResAct, m_wYResAct, m_pic12, m_pic8);
// Convert raw data using the color Lookup table

To me it seems like there is something wrong with my IMG and the buffer length is exceeded.

Can anybody tell me what i need to do to initialize the resulting IMG correctly?
Or is there something else wrong?

Thanks for you help!