I was trying to access some functions from a dll using python ctypes, but not sure how to pass pointers to get it to work.
Here is an example of what i am trying to call:

GetAvailableDevices  ( SdkHandle  session,  
  DeviceDetail *  pDev_list,  
  uint32_t *  dev_list_size   

[in] session Handle to the current sdk session
[in] pDev_list A pointer to an array of DeviceDetail structures that will receive the available device list information
[in,out] dev_list_size On input the size of the pDev_list array, on output the number of items filled into the array.

I tried the following:

from ctypes import *
device_list_size = 5
device_list = []
dll = cdll.LoadLibrary("C:\Sdk.dll")
session = dll.CreateSession()
dev_list = dll.GetAvailableDevices(session, pointer(device_list), pointer(device_list_size))

When I run the above i get : *** TypeError: type must have storage info

I am new to ctypes so not sure if this is correct, I would really appreciate if you could tell me the correct way of calling the above function.
Thanks in advance for your help.


Hello pyTony,

Thank you for the document it is very informative. However, since i don't have much experience with c, c++ I am still not able to gt my script to work:
I would really appreciate if you could throw some pointers & help me in translating the following c++ code to python:

typedef struct
    DeviceTechType            eTechnology;              
    DeviceFormFactorType      eFormFactor;               
    char                      szDescription[NW_MAX_PATH];    
        char                      szPort[NW_MAX_PATH];         
        char                      szFriendlyName[NW_MAX_PATH]; 

typedef enum 
    DEV_TYPE_PC_CARD            = 0, 
    DEV_TYPE_MINI_PCI           = 1,   
    DEV_TYPE_SM_BUS_MINI_PCI    = 3,   
} DeviceFormFactorType;

typedef enum
    DEV_NONE        = 0,       
    DEV_EVDO        = 4,      
    DEV_UMTS        = 7,      

int main(int argc, char* argv[])
    SdkWrapper          sdk;
    NvtlEventCallback   cb;
    DeviceInfoStruct    device_info;
    NetworkInfoStruct   network_info;
    DeviceDetail        device_list[5];
    unsigned long       device_list_size = 5;

    memset(device_list, 0, device_list_size*sizeof(DeviceDetail));
    rval = sdk.GetAvailableDevices( device_list, &device_list_size)
    printf("Found %ld devices\n", device_list_size);

This is what I have tried so far:

from ctypes import *

eformfactor = (DEV_TYPE_PC_CARD,
               DEV_TYPE_SM_BUS_MINI_PCI,) = map(c_int, xrange(4))

edevicetechtype = (DEV_NONE,
                   DEV_UMTS) = map(c_int, xrange(3)) 

class devdetails(Structure):
    _fields_ = [("eformfactor" ,eformfactor),
                ("edevicetechtype", edevicetechtype),
                ("szDescription", c_char * 255),
                ("szFriendlyName", c_char * 255),
                ("szPort", c_char * 255)]

device_list_size = c_int * 5
dll = cdll.LoadLibrary("C:\Program Files\Sdk.dll")
session = dll.CreateSession()
dev_list = dll.NvtlCommon_GetAvailableDevices(session, pointer(devdetails), byref(device_list_size))

Thanks in advance for your help.


Any body who can help me with this?

Thanks & Regards