Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DLL library with ctypes
#1
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  using ctypes to use a dll in a python module dauriac 3 389 Mar-06-2024, 04:38 PM
Last Post: dauriac
  Trying to debug segfault in ctypes binding to Fortran bthomas 1 608 Sep-01-2023, 11:26 AM
Last Post: bthomas
  ctypes juliolop 7 1,402 Apr-20-2023, 03:33 PM
Last Post: Larz60+
  Issue while using ctypes in python GiggsB 6 2,794 Mar-27-2022, 03:38 AM
Last Post: GiggsB
  Ctypes and libffi.so.7 luxedo 1 6,062 Oct-23-2021, 09:24 PM
Last Post: DeaD_EyE
  possible ctypes and numpy conflict? herbal_rage 0 3,154 Apr-16-2020, 11:35 AM
Last Post: herbal_rage
  python kernell crash with a ctypes program Jstechg 1 3,501 Nov-24-2018, 02:37 PM
Last Post: Jstechg
  generating ctypes wrapper for a c library? brighteningeyes 9 7,083 Nov-04-2018, 02:31 AM
Last Post: brighteningeyes
  dll not loading to Ctypes Philbot 1 6,865 Jul-01-2018, 09:55 AM
Last Post: Philbot
  Error Ctypes in Windows rramosg 4 9,370 Oct-17-2017, 05:26 AM
Last Post: rramosg

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020