0

The C function from DLL:

Multi(double Freq, double Power, int ports[], int Size)
Need to pass the 3rd parameter as an array from python 

Tried the following different codes:

A:

import ctypes
pyarr = [2,3]
arr = (ctypes.c_int * len(pyarr))(*pyarr)

lp = CDLL(CDLL_file)
lp.Multi(c_double(Freq), c_double(Power), arr ,c_int(Size))`

This code shows an error ## exception :: access violation reading 0x00000000000

B:

retarr = (ctypes.c_int*2)()
retarr[0] =2
retarr[1] =3

lp = CDLL(CDLL_file)
lp.Multi(c_double(Freq), c_double(Power), retarr ,c_int(Size))`

This code shows an error

## exception :: access violation reading 0x00000000000 

C: The same code using ctypes.byref also tried ......

My understanding is the function expects an array as argument , Tries passing an array as such as well address. Both cases , it didn't work Do anyone sees any mistake in my understanding or any other to work this out ??

1
  • 1
    What is Size set to? Commented Jul 19, 2016 at 12:57

1 Answer 1

1

Specify your argtypes. Given this test.dll source:

#include <stdio.h>

__declspec(dllexport) void Multi(double Freq, double Power, int ports[], int Size)
{
    int i;
    printf("%f %f\n",Freq,Power);
    for(i = 0; i < Size; ++i)
        printf("%d\n",ports[i]);
}

This works:

from ctypes import *
dll = CDLL('test')
Multi = dll.Multi
Multi.argtypes = (c_double,c_double,POINTER(c_int),c_int)
Multi.restype = None

ports = (c_int * 2)(100,200)
Multi(1.1,2.2,ports,len(ports))

Output:

1.100000 2.200000
100
200
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.