calling loaded DLL function expecting POINT * argument

T

Tim Williams

Hello all,

I'm trying to use the ctypes module to call functions in a DLL. I've figured out how to modify my path so the library is found, and I can call LoadLibrary on it, but one of the functions expects an array of POINTS. Here is the prototype from the .h file:


TRACKER_API HRESULT InitializeMask(HANDLE pHandle, int nWidth, int nHeight, POINT* ptMasks, int nNumPoints);

I did a

from ctypes.wintypes import *

Here's my test script:
##############
'''
Created on Aug 23, 2012

@author: williams
'''
import os
import numpy as np
import scipy.io
from ctypes import *
from ctypes.wintypes import *


matdata = scipy.io.loadmat(os.path.join(os.environ['userprofile'],'Desktop','S31_f1.mat'))
data = matdata['data']
nHeight,nWidth = data.shape

pth = os.environ['path'].split(';')
pth.append(os.path.join(os.environ['userprofile'],'My Documents','DLLs'))
os.environ['path'] = ';'.join(pth)
tck=oledll.LoadLibrary('Tracker')
hTrkr = tck.CreateTracker()
maskImage = np.zeros((1024,1280),dtype='int32')
maskImage[300:305,100:105] = True
idx = np.array(maskImage.nonzero())
nPoint = idx.shape[1]

ptMaskType = nPoint * POINT
pts = zip(idx[1,:],idx[0,:])
ptMasks = ptMaskType(*pts)

tck.InitializeMask.argtypes=(HANDLE, c_int, c_int, c_void_p, c_int)
InitMaskResult = tck.InitializeMask(hTrkr, nWidth, nHeight, ptMasks, nPoint)

if __name__ == '__main__':
pass
##############

so I have the POINT class, and I've created the array of POINTs. When I try to call this function, I get this message:
Traceback (most recent call last):
File "<console>", line 1, in <module>
ValueError: Procedure probably called with too many arguments (20 bytes in excess)


This is the first time that I've tried to use the ctypes module, so any help is appreciated.

TIA,
 
T

Tim Williams

How is TRACKER_API defined? You're using ctypes.oledll, which uses the

__stdcall calling convention. It's possible your DLL is defined as

__cdecl. Try cdll.LoadLibrary instead of oledll.LoadLibrary.

--

Tim Roberts, (e-mail address removed)

Providenza & Boekelheide, Inc.

Thanks for the reply. I've been out all last week. I'll give it a try.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top