473,395 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ctypes: Problems using Windows-DLL from VB example code

Hi

I'm trying to use a DLL from Python using ctypes.
The call to dso_lib.capture_hold_chk() does return 232. So it seem to work.
The call to dso_lib.port_init(init_data) gives:
WindowsError: exception: access violation reading 0x00000006

Any suggestions?

Thanks.

Noralf
Here is my python code:
import os
from ctypes import *

# Hardware control data
class A_INIT(Structure):
_fields_ = [("time_d_va", c_long),
("tri_in_sel", c_int),
("ch1_div", c_int),
("ch1_in_sel", c_int),
("ch2_div", c_int),
("ch2_in_sel", c_int),
("ram_rw_mode", c_int),
("ram_copy_mode", c_int),
("ram_copy_delay", c_int),
("ho_mode", c_int),
("ho_mode1", c_int),
("CH", c_int),
("TRI_12E", c_int),
("Ch1_To_Gnd", c_int),
("Ch2_To_Gnd", c_int)]

dso_lib_filepath = os.path.join(os.path.dirname(__file__),
'dso_2100usb_s.dll')
dso_lib = cdll.LoadLibrary(dso_lib_filepath)
init_data = A_INIT()

init_data.time_d_va = 0
init_data.tri_in_sel = 7
init_data.ch1_div = 4
init_data.ch1_in_sel = 1
init_data.ch2_div = 4
init_data.ch2_in_sel = 1
init_data.ram_rw_mode = 1
init_data.ram_copy_mode = 14
init_data.ram_copy_delay = 0
init_data.ho_mode = 1
init_data.ho_mode1 = 0
init_data.CH = 0
init_data.TRI_12E = 0
init_data.Ch1_To_Gnd = 0
init_data.Ch2_To_Gnd = 0

print dso_lib.capture_hold_chk() # returns 232

print dso_lib.port_init(init_data) # WindowsError exception
Here is the code from a Visual Basic example using the DLL:

Type A_INIT 'hardware control data
time_d_va As Long
tri_in_sel As Integer
ch1_div As Integer
ch1_in_sel As Integer
ch2_div As Integer
ch2_in_sel As Integer
ram_rw_mode As Integer
ram_copy_mode As Integer
ram_copy_delay As Integer
ho_mode As Integer
ho_mode1 As Integer
CH As Integer
TRI_12E As Integer
Ch1_To_Gnd As Integer
Ch2_To_Gnd As Integer
End Type
Public init_data As A_INIT

Public RESULT As Integer

Public Declare Function port_init Lib "dso_2100usb_s.dll" (init_data As
A_INIT) As Integer

Sub init()
init_data.ch1_div = 4
init_data.ch1_in_sel = 1
init_data.Ch1_To_Gnd = 0
init_data.ch2_div = 4
init_data.ch2_in_sel = 1
init_data.Ch2_To_Gnd = 0
init_data.ho_mode = 1
RESULT = port_init(init_data)
End Sub
May 9 '07 #1
4 2633
Noralf Trønnes schrieb:
Hi

I'm trying to use a DLL from Python using ctypes.
The call to dso_lib.capture_hold_chk() does return 232. So it seem to work.
The call to dso_lib.port_init(init_data) gives:
WindowsError: exception: access violation reading 0x00000006

Any suggestions?
Have you tried to pass the structure by reference?

dso_lib.port_init(byref(init_data))

Thomas

May 9 '07 #2
Have you tried to pass the structure by reference?
>
dso_lib.port_init(byref(init_data))

Thomas
That gives me another exeption:

print dso_lib.port_init(byref(init_data))
ValueError: Procedure called with not enough arguments (4 bytes missing) or
wrong calling convention

Noralf.
May 9 '07 #3
>Have you tried to pass the structure by reference?
>>
dso_lib.port_init(byref(init_data))

That gives me another exeption:

print dso_lib.port_init(byref(init_data))
ValueError: Procedure called with not enough arguments (4 bytes missing) or
wrong calling convention
Please try using 'windll' instead of 'cdll' to load the library; then call 'dso_lib.port_init(byref(init_data))'.

Thomas

May 9 '07 #4
Thank you very much!

That did the trick.

Noralf.
May 9 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Heller | last post by:
It's release day ;-) ctypes 0.6.3 released ===================== Overview 'ctypes' is a Python package to create and manipulate C data types in Python, and to call functions in dynamic...
2
by: zapazap | last post by:
Dear Snake Charming Gurus, (Was: http://mail.python.org/pipermail/python-list/2004-January/204454.html) First, a thank you to Tim Golden, Thomas Heller, and Mark Hammond for your earlier help...
19
by: Thomas Heller | last post by:
ctypes 0.9.2 released - Oct 28, 2004 ==================================== Overview ctypes is a ffi (Foreign Function Interface) package for Python 2.3 and higher. ctypes allows to call...
18
by: Paul Watson | last post by:
I need to call some Windows APIs. Is the only way to download ctypes or the win32 interfaces? Is there any plan to get ctypes batteries into the standard Python build?
3
by: p.lavarre | last post by:
Subject: Python CTypes translation of (pv != NULL) And so then the next related Faq is: Q: How should I test for ((void *) -1)? A: (pv == 0xffffFFFF) works often.
1
by: sjdevnull | last post by:
Hey, I'm trying to wrap GNU readline with ctypes (the Python readline library doesn't support the callback interface), but I can't figure out how to set values to a variable inside the library. ...
2
by: Jacob Rael | last post by:
Hello, I was following along with this site: http://www.brunningonline.net/simon/blog/archives/000659.html and I got a error. It boils down to: ====================
5
by: Daniel | last post by:
I'm trying to implement a routine that converts a PDF document to image files using ctypes and the Apple CoreGraphics library as per the 'Splitting a PDF File' example on Apple's web site ....
1
by: skip | last post by:
I am starting to experiment with ctypes. I have a function which returns a pointer to a struct allocated in heap memory. There is a corresponding free function for that sort of struct, e.g.: ...
14
by: Gordon Allott | last post by:
Hello :) The result of various incompatibilities has left me needing to somehow extract the address that a null pointer is pointing to with the null pointer being exposed to python via...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.