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 reply to Re^2: How to use 'unsigned char' C data type with Win32::API by sam_bakki
in thread Solved: How to use 'unsigned char' C data type with Win32::API by sam_bakki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.