in reply to Re: How to use 'unsigned char' C data type with Win32::API
in thread Solved: How to use 'unsigned char' C data type with Win32::API
Hi BrowserUk
For some reason, having 'int' and getting data from my DLL is not working well.
my $i2cGetDeviceAddressFunc = Win32::API->new('CrdI2C32', 'int i2cGetD +eviceAddress()') or warn "\n ERROR: Can not import API:i2cGetDeviceAd +dress , $^E ,"; my $ret = 0; $ret = $i2cGetDeviceAddressFunc->Call(); print "\n RET: $ret";
Output
1. Run RET: 53113496 2. Run RET: 52195992 3. Run RET: 52851352 4. Run RET: 52458136 5. Run RET: 51540632
Output is not what i expected and more over every run, it produce different output. But the C code which calls the i2cGetDeviceAddress() API produces same output always.
I don't have source code of the DLL (CRDI2C32.DLL) , We bought this from other company, They gave C, C++, VB & PASCAL example code which has API prototypes.
PASCAL Sample: xx.pas Function i2cGetDeviceAddress : Byte; + stdcall; external 'CrdI2C32.DLL'; C Sample: xx.h typedef unsigned char __stdcall i2cGetDeviceAddress_type(); extern i2cGetDeviceAddress_type *i2cGetDeviceAddress; xx.c i2cGetDeviceAddress_type *i2cGetDeviceAddress = NULL; .... i2cGetDeviceAddress = (i2cGetDeviceAddress_type*)GetProcAddress(hDll, +"i2cGetDeviceAddress"); if (i2cGetDeviceAddress == NULL) { FreeLibrary(hDll); return 22; // function not found in library } VB Sample: xx.bas Declare Function i2cGetDeviceAddress Lib "CrdI2C32.DLL" () As Byte
In Section
Seekers of Perl Wisdom