Problem with Win32::API and pointers
- From: jrgoody@xxxxxxxxxxxxxx
- Date: 12 May 2006 07:02:29 -0700
Hi,
I'm working on a project and trying to use the Win32::API to call a
DLL from Perl, but I have some problems. I'm using the last version
of the API (0.41).
I'll describe my problem. I hope someone can help me. The DLL I've
been trying to call from Perl is the FTD2XX.dll from FTDI, a Library to
communicate with a chip connected to the computer via USB. The thing is
really simple, this is my code:
#CODE
STARTS******************************************************************************
use Win32::API;
Win32::API::Type->typedef( 'FT_HANDLE', 'PVOID' );
Win32::API::Type->typedef( 'FT_STATUS', 'ULONG' );
#FT_Open
Win32::API->Import( 'FTD2XX', 'FT_STATUS FT_Open(int
deviceNumber,FT_HANDLE *pHandle)' );
#FT_Close
Win32::API->Import( 'FTD2XX', 'FT_STATUS FT_Close(FT_HANDLE ftHandle)'
);
#Open port
FT_Open(0,$ft_handle);
#Close port
$ft_status = FT_Close($$ft_handle);
#CODE
ENDS***********************************************************************************
This is how the functions and variables are defined in the .h file:
....
typedef PVOID FT_HANDLE;
typedef ULONG FT_STATUS;
....
FTD2XX_API
FT_STATUS WINAPI FT_Open(
int deviceNumber,
FT_HANDLE *pHandle
);
....
FTD2XX_API
FT_STATUS WINAPI FT_Close(
FT_HANDLE ftHandle
);
....
The function FT_Open should return FT_STATUS (this works) but also a
pointer *pHandle to the Handle, which is to be used for the forthcoming
operations to the port, like in the function FT_Close.
But when I run the program, this is what I receive:
"Perl Command Line Interpreter has encountered a problem and needs to
close. We are sorry for the inconvenience."
The problem is on the FT_Close function. If I comment it out, the
program runs OK (FT_Open returns Status OK), so I'm pretty sure the
problem has something to do with the handle. As I said, FT_Open should
give a pointer to the handle (2nd argument) and the handle itself is to
be used in FT_Close (only argument).
I thing it should work with the API, because it is pretty much the same
as in one of the examples in the API Documentation. But I can't get
it to work. Someone sees an error or something missing in my code?
Please tell me if you need more info from me or if you have any
suggestions on how I can fix this. This is really important for me. I
thank you very much in advance.
.
- Follow-Ups:
- Re: Problem with Win32::API and pointers
- From: Thomas Kratz
- Re: Problem with Win32::API and pointers
- Prev by Date: Re: HTTP::Proxy and not using 127.0.0.1
- Next by Date: Re: Problem with Win32::API and pointers
- Previous by thread: HTML to XML in Perl?
- Next by thread: Re: Problem with Win32::API and pointers
- Index(es):
Relevant Pages
|