I have a problem with $title.
Motivation/background: I need to control an instrument (more specifically, read data from it), however, there are no simple, direct means to do this. All I have is a vendor-supplied DLL and a .h header that lists the functions and their parameters.
I already have a perl program that drives the rest of the measurement setup, so I thought I could integrate into it the control of this specific instrument, if I could just use that DLL.
I first tried Win32::API. It looked promising, but it turned out that it doesn't work. If I used the
Win32::API->Import($S{DLL_path}, 'int RegisterClient2(int *pnClientId,
+ char *pszIPAddress)');
...
my $result = RegisterClient2($client_id, $S{read_IP});
syntax, it gave me an error message:
Can't call method "Call" on an undefined value at (eval 4) line 2.
If I used the
my $RegisterClient2 = Win32::API->new($S{DLL_path}, 'int RegisterClien
+t2(int *pnClientId, char *pszIPAddress)');
...
my $result = $RegisterClient2->Call($client_id, $S{read_IP});
syntax, it just crashed.
After some googling I've found a number of reports here and elsewhere with similar negative experiences - so I gave up on this approach.
My next idea was to use Inline::C. I used that module on linux earlier, to great satisfaction. And I've read it somewhere that it is possible to use it on Windows too, if one installs ActiveState's MinGW package first.
Indeed, Inline::C itself worked, as far as simple examples (with no external libraries) were concerned.
But I couldn't get it to work with my DLL.
use strict;
use warnings;
use Inline C => Config => MYEXTLIB => 'd:\path\to\CrappyLibrary.dll',
#use Inline C => Config => LIBS =>'-Ld:/path/to -lCrappyLibrary',
INC => '-Id:\path\to',BUILD_NOISY => 1;
use Inline C => 'DATA';
my $result = RegisterClient2($client_id, $S{read_IP});
__DATA__
__C__
#include "Easy4ApiDef.h"
I get the following error message:
Set up gcc environment - 3.4.5 (mingw-vista special r3)
Use of inherited AUTOLOAD for non-method main::RegisterClient2() is de
+precated at inline.pl line 115.
Can't locate auto/main/RegisterCli.al in @INC (@INC contains: D:\meres
+\SAR\_Inline\lib C:/Perl/site/lib C:/Perl/lib .) at inline.pl line 11
+5
The example function RegisterClient2 has the following prototype by the way:
extern "C" __declspec(dllexport) int RegisterClient2(int *pnClientId,
+const char *pszIPAddress);
The DLL itself is functioning. I know that because there supplied an example application with it that works correctly (also there is a ghastly LabView application that calls the functions from the DLL and it also works.)
My questions:
-1) What am I doing wrong?
0) Is it possible to salvage the Win32::API solution somehow, or is it really hopeless as I've thought?
1) Is it possible to make it work with Inline::C? If yes, how?
2) Are there further alternatives, or am I f&@#ed thoroughly?
Thanks in advance for your answers.
kikuchiyo