-1

I try to use ctypes for using DLL on python program.

This is C# code and function's args that I want to use in python:

[DllImport("test.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
public static extern int function(
  byte[] filename,
  byte[] name,
  IntPtr result,
  out IntPtr UnmanagedStringArray,
  out int iStringsCountReceiver);

The code below is my python code. I searched several sites but I could not find hint about argtypes. Please help me use DLL in python.

mydll = c.cdll.LoadLibrary("test.dll")
func = mydll['function']
func.argtypes=( ....)
Andronicus
  • 25,419
  • 17
  • 47
  • 88
ironykim
  • 3
  • 3
  • Does this answer your question? [Calling C/C++ from Python?](https://stackoverflow.com/questions/145270/calling-c-c-from-python) – Paweł Mach Oct 21 '20 at 17:32

1 Answers1

0

byte[] is equivalent to char* in C, so c_char_p will work. IntPtr in C# is an integer the size of a pointer. c_void_p should work. out parameters require pointers.

You can try:

import ctypes as c
mydll = c.CDLL('./test')
func = mydll.function
func.argtypes = c.c_char_p,c_c_char_p,c.c_void_p,c.POINTER(c_void_p),c.POINTER(c.c_int)
func.restype = c.c_int
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251