Please help me to resolve this issue

2006-03-24 Thread Yanping Zhang
Hello everyone,

I am pretty new in python. Please give me any idea about 
this issue:

There is a function like this in my c dll:

typedef void (WINAPI *myCallBack) (unsigned int myarg1, unsigned int myarg2)

bool  myfunc(myCallBack mycall)


In my python code, I was able to access other functions in the dll, but I
have no idea how to call myfunc() because of WINAPI argument.

Thanks in advance.





__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


python ctype question about "access violation reading location 0x5a5a5a5a"

2006-03-28 Thread Yanping Zhang
Hi All,

I need to use this C routine in python and there is a void pointer parameter in 
it: 
(this routine was written by someone else):

myfunc(int a, (void *)userdata, bool b)

I saw someone in his C++ wrapper used this routine in this way:
myfunc(a, (void *)0x5a5a5a5a, b)

In my python wrapper, I tried  to call it as the following and both failed:
1. myfunc(c_int(a), 0x5a5a5a5a, c_int(b))
   got error "access voilation reading from 0x5a5a5a5a"
2. 
  data = 0x5a5a5a5a
  mydata = c_void_p(data)
  myfunc(c_int(a), mydata, c_int(b))
  same error as in 1

Can anyone know how to fix it? Thanks!

 

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Updated: python ctype question about "access violation reading location 0x5a5a5a5a"

2006-03-29 Thread Yanping Zhang
Here are more details about my codes, please help!

The function declared in C:
typedef void (WINAPI *PLEARNCALLBACKPROC) (unsigned int progress, unsigned int 
sigQuality,
unsigned long carrierFreq, void *userData);

UUIRTDRV_API BOOL PASCAL UUIRTLearnIR(HUUHANDLE hHandle, int codeFormat, char 
*IRCode,
PLEARNCALLBACKPROC progressProc, void *userData, BOOL *pAbort, unsigned int 
param1, void
*reserved0, void *reserved1);

My python codes:

import ctypes

port = windll.uuirtdrv

myhandle = c_void_p()
  
myhandle = port.UUIRTOpen()


#+++ Call back function 
LEARNCALLBACKFUNC = CFUNCTYPE(c_void_p, c_uint, c_uint, c_ulong, c_void_p)

def py_learncallback_func(progress,sigQuality, carrierFreq, userdata):

print "progress is: %d %d %d %d" % (progress, sigQuality & 0xff, 
carrierFreq, userdata)
if progress == 100:
   mybool = c_int(1)
   
return 

callback_func = LEARNCALLBACKFUNC(py_learncallback_func)

#++

glearnBuffer = create_string_buffer('\000'*2048)

mybool = c_int(0)
param1 = c_int(0)
reserved0 = c_void_p(0)
reserved1 = c_void_p(0)

mydata = create_string_buffer("0x5a5a5a5a")
#userdata = c_long(0x5a5a5a5a)  #failed
#userdata = byref(mydata)   #failed
#userdata = pointer(mydata) #failed 
userdata = c_void_p(0x5a5a5a5a) #failed

 
learnformat = c_int(0x)

port.UUIRTLearnIR(myhandle, learnformat, glearnBuffer, callback_func, userdata,
mybool,param1,reserved0, reserved1)


I tried to define userdata in different ways and all failed with "access 
violation
reading(writing) location...". The c routine just passes userdata to call back 
function and didn't
use it anywhere else.

Thanks!



> Hi All,
> 
> I need to use this C routine in python and there is a void pointer parameter 
> in it: 
> (this routine was written by someone else):
> 
> myfunc(int a, (void *)userdata, int b)
> 
> I saw someone in his C++ wrapper used this routine in this way:
> myfunc(a, (void *)0x5a5a5a5a, b)
> 
> In my python wrapper, I tried  to call it as the following and both failed:
> 1. myfunc(c_int(a), 0x5a5a5a5a, c_int(b))
>got error "access voilation reading from 0x5a5a5a5a"
> 2. 
>   data = 0x5a5a5a5a
>   mydata = c_void_p(data)
>   myfunc(c_int(a), mydata, c_int(b))
>   same error as in 1
> 
> Can anyone know how to fix it? Thanks!
> 
> 
> 
> __
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list