Fabian Steiner | 1 Apr 2006 23:00

Passing structures as parameters to functions

Hi!

I am currently using ctypes to write a Python wrapper for a Windows-dll
which is written in C. So far it has worked quite well, but at the
moment I have got some problems: I have to pass a structure as a
parameter to a function, but whenever I try this I get the following
error: "ctypes.ArgumentError: argument 1: exceptions.TypeError: Don't
know how to convert parameter 1"

The structure looks like this:

class NvConfiguration(Structure):
    _fields_ = [('bindingType', c_int),
                   ('appStorageClass', c_int),
                   ('serviceType', c_byte),
                   ('updateType', c_int),
                   ('offlineType', c_int),
                   ('setPriorityConfigurable', c_int),
                   ('authConfigurable', c_int)]

The function which is called:

 def OpenNetInterface(self, netIntfConfig, nodeSelfDoc, iniFilePath):
       # What kind of "argtype" is NvConfiguration then? Structure
doesn't work.
       # self._xlonhapi.OpenNetInterface.argtypes = [Structure,
c_char_p, c_char_p]
        return self._xlonhapi.OpenNetInterface(netIntfConfig,
nodeSelfDoc, iniFilePath)

(Continue reading)

Fabian Steiner | 1 Apr 2006 22:51

Using structures as parameters

Hi!

I am currently using ctypes to write a Python wrapper for a Windows-dll
which is written in C. So far it has worked quite well, but at the
moment I have got some problems: I have to pass a structure as a
parameter to a function, but whenever I try this I get the following
error: "ctypes.ArgumentError: argument 1: exceptions.TypeError: Don't
know how to convert parameter 1"

The structure looks like this:

class NvConfiguration(Structure):
    _fields_ = [('bindingType', c_int),
                   ('appStorageClass', c_int),
                   ('serviceType', c_byte),
                   ('updateType', c_int),
                   ('offlineType', c_int),
                   ('setPriorityConfigurable', c_int),
                   ('authConfigurable', c_int)]

The function which is called:

 def OpenNetInterface(self, netIntfConfig, nodeSelfDoc, iniFilePath):
       # What kind of "argtype" is NvConfiguration then? Structure
doesn't work.
       # self._xlonhapi.OpenNetInterface.argtypes = [Structure,
c_char_p, c_char_p]
        return self._xlonhapi.OpenNetInterface(netIntfConfig,
nodeSelfDoc, iniFilePath)

(Continue reading)

Luke Dunstan | 2 Apr 2006 04:54
Picon
Favicon

Re: Using structures as parameters


----- Original Message ----- 
From: "Fabian Steiner" <lists <at> fabis-site.net>
To: <ctypes-users <at> lists.sourceforge.net>
Sent: Sunday, April 02, 2006 4:51 AM
Subject: [ctypes-users] Using structures as parameters

> Hi!
>
> I am currently using ctypes to write a Python wrapper for a Windows-dll
> which is written in C. So far it has worked quite well, but at the
> moment I have got some problems: I have to pass a structure as a
> parameter to a function, but whenever I try this I get the following
> error: "ctypes.ArgumentError: argument 1: exceptions.TypeError: Don't
> know how to convert parameter 1"
>
> The structure looks like this:
>
> class NvConfiguration(Structure):
>    _fields_ = [('bindingType', c_int),
>                   ('appStorageClass', c_int),
>                   ('serviceType', c_byte),
>                   ('updateType', c_int),
>                   ('offlineType', c_int),
>                   ('setPriorityConfigurable', c_int),
>                   ('authConfigurable', c_int)]
>
> The function which is called:
>
> def OpenNetInterface(self, netIntfConfig, nodeSelfDoc, iniFilePath):
(Continue reading)

Luke Dunstan | 5 Apr 2006 09:30
Picon
Favicon

Re: Re: Casting from function pointer to void* (correction)


----- Original Message ----- 
From: "Thomas Heller" <theller <at> python.net>
To: <ctypes-users <at> lists.sourceforge.net>
Sent: Thursday, March 30, 2006 4:13 AM
Subject: [ctypes-users] Re: Casting from function pointer to void* 
(correction)

> Luke Dunstan wrote:
>>
>> ----- Original Message ----- From: "Luke Dunstan" 
>> <coder_infidel <at> hotmail.com>
>> To: <ctypes-users <at> lists.sourceforge.net>
>> Sent: Tuesday, March 28, 2006 11:17 PM
>> Subject: [ctypes-users] Casting from function pointer to void*
>>
>>
>>>
>>> Hi,
>>>
>>> I have some code like this:
>>>
>>>    PFN = CFUNCTYPE(...)
>>>    pfn = PFN(foo)
>>>    pv = ctypes.cast(pfn, c_void_p)
>>>
>>> This works with ctypes 0.9.9.3 but the current CVS version gives this 
>>> error:
>>>
>>> Traceback (most recent call last):
(Continue reading)

m2ids 2005 | 5 Apr 2006 10:45
Picon

ctypes in linux


Hi all,

I have written an application that uses ctypes for getting the dll . Now i need the same in linux.
i have installed ctypes and itz going perfectly...just wanted to clear some doubts..

In windows , i am calling the dll as ---->  x =  cdll.DllName
Is it ok if i call like this in linux ---> x = cdll.LoadLibrary("path of the file")

In windows i am using function from the C library as, cdll.msvcrt.memcpy(....)
how will i do this linux? i tried using msvcrt in linux but i think it will work only in windows...moreover all sample examples are written for windows...Can anyone suggest a solution for this? I am new to linux so don't know much abt it.

Regards,
Shine
m2ids 2005 | 5 Apr 2006 10:47
Picon

ctypes in linux

Hi all,

I have written an application that uses ctypes for getting the dll . Now i need the same in linux.
i have installed ctypes and itz going perfectly...just wanted to clear some doubts..

In windows , i am calling the dll as ---->  x =  cdll.DllName
Is it ok if i call like this in linux ---> x = cdll.LoadLibrary("path of the file")

In windows i am using function from the C library as, cdll.msvcrt.memcpy(....)
how will i do this linux? i tried using msvcrt in linux but i think it will work only in windows...moreover all sample examples are written for windows...Can anyone suggest a solution for this? I am new to linux so don't know much abt it.

Regards,
Shine

Defenestrator | 6 Apr 2006 01:15
Picon

Procedure probably called with too many arguments?

Hi,

I'm not sure if I'm doing something wrong since I'm fairly new to using ctypes.

I have a function in my DLL:

DLLIMPORT int ReturnSameInt(int i)
{
    return i;
}

And I tried calling it from Python using ctypes:

from ctypes import *
myDll = windll.SimpleDll
print myDll.ReturnSameInt( 100 )

But I'm getting the following error:

Traceback (most recent call last):
  File "pytest.py", line 3, in ?
    print myDll.ReturnSameInt( 100 )
ValueError: Procedure probably called with too many arguments (4 bytes in excess)

Any help will be appreciated!

Thanks!

Shine Anne | 6 Apr 2006 07:56
Picon

Calling a dll from Python ctypes


Hi all,

I doing an app in Linux(Fedora Core 4) using ctypes...i have a dll and thats now converted to a ".so " file.
i just wanted to know whether the method i adopted in calling the ".so" (say, libXXX.so)file is correct or not..
I first placed that file in a path created by me...and called the stmt
x=cdll.LoadLibrary("/mypath/libXXX.so")
but it gave me this error : "libLoadLibrary.so: cannot open shared object file: No such file or directory"
i was searching for a soln for the past 2 days but i am not able to figure it out, since i am new to linux .
finalli i coped this file in /lib/...ie,/lib/libXXX.so.
then i did this stmt..
        import dl
         a = dl.open('/lib/libXXX.so') ---------------> (1)
then itz called but when i tried the same with my path it failed....
ie,
 a = dl.open('/mypath/libXXXX.so').. -------------->(2)
the error is:
           Traceback (most recent call last):
            File "<stdin>", line 1, in ?
         dl.error: /mypath/libXXX.so: cannot restore segment prot after reloc: Permission denied
i wantedto know wether stmt (1) is right?
or do cdll.LoadLibrary("..") is the right way? if so, then wat r the steps?
--
Regards,

Shine Anne
Niki Spahiev | 6 Apr 2006 09:48
Picon

Re: Procedure probably called with too many arguments?

Defenestrator wrote:
> And I tried calling it from Python using ctypes:
> 
> from ctypes import *
> myDll = windll.SimpleDll

try cdll instead of windll.

HTH
Niki Spahiev

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
Thomas Heller | 6 Apr 2006 20:55
Favicon

Re: Calling a dll from Python ctypes

Shine Anne wrote:
> Hi all,
> 
> I doing an app in Linux(Fedora Core 4) using ctypes...i have a dll and thats
> now converted to a ".so " file.
> i just wanted to know whether the method i adopted in calling the ".so"
> (say, libXXX.so)file is correct or not..
> I first placed that file in a path created by me...and called the stmt
> x=cdll.LoadLibrary("/mypath/libXXX.so")
> but it gave me this error : "libLoadLibrary.so: cannot open shared object
> file: No such file or directory"

I did remove the 'LoadLibrary' method in the 0.9.9.3 release.  Since cdll tries
to load missing attributes as libraries, you get the error above:  It tries
to load a library named 'libLoadLibrary.so'.  The next release will add the LoadLibrary
method again, so it should work (but the preferred name will be 'load_library').
In the meantime you should use cdll.load("/mypath/libXXX.so").

> i was searching for a soln for the past 2 days but i am not able to figure
> it out, since i am new to linux .
> finalli i coped this file in /lib/...ie,/lib/libXXX.so.
> then i did this stmt..
>         import dl
>          a = dl.open('/lib/libXXX.so') ---------------> (1)
> then itz called but when i tried the same with my path it failed....
> ie,
>  a = dl.open('/mypath/libXXXX.so').. -------------->(2)
> the error is:
>            Traceback (most recent call last):
>             File "<stdin>", line 1, in ?
>          dl.error: /mypath/libXXX.so: cannot restore segment prot after
> reloc: Permission denied
> i wantedto know wether stmt (1) is right?
> or do cdll.LoadLibrary("..") is the right way? if so, then wat r the steps?
> --
> Regards,
> 
> Shine Anne
> 

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642

Gmane