in reply to Re^6: Correct call for dll with Win32::API
in thread Correct call for dll with Win32::API

Update: ikegami's right. I shouldn't try to interact before having my second cup of tea. I exactly reverse the meaning of the underscore in my mind!

That shows that the calling convention used is __stdcall, so you should be able to call the dll successfully using Win32::API. __cdecl calling convention was used, so you will not be able to call the dll successfully winth Win32::API.

Ignore the rest!

And according to this translation of (probably the same?) chinese pdf, your (second) prototype:

my $readdevice = Win32::API->new ( 'HCE300_API.DLL', 'HCE300_Read','NP','N' ) or die $^E;
is correct. It also identifies that the maximum length of data that can be read from the device is 300 bytes (track 2 when in 210bpi mode). (Though despite the warning in the descroption that it can be 300 bytes, all the examples use char buf[250]!)

The upshot is that what you are trying should work. If it doesn't, there are many possibilities for why it doesn't, and all of them are far beyond the scope of this Perl forum.


You mentioned using USB. The description of the device shows that it is intended to be connected to an old fashioned RS232 serial port. My one attempt at using a USB connected serial port convinced me that their RS232 emulation is far from transparent. If the device/driver was never written and tested to operate over USB, you are likely to encounter real problems.

One possibility is that at the end of that manual above, there is a description of the comms protocol commands for driving the device. You might be able to bypass the DLL and drive the device directly by writing and reading raw bytes to and from the serial port itself. Though I'll have to just wish you luck with that, because serial comms is more a black art than science, and it is hard enough to do hands-on with a protocol analyser to hand. Doing it remotely is pretty much impossible.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^8: Correct call for dll with Win32::API
by ikegami (Patriarch) on Dec 05, 2008 at 14:00 UTC

    That shows that the calling convention used is __stdcall

    What shows that?

      The lack of preceding underscores on the exported names is a strong indication that the __cdecl calling convention wasn't used. It's not definitive as it could still be __fastcall, but if you follow the link to the translated PDF, you'll see that the prototypes are all similar to int WINAPI HCE300_Open (int ComPort);


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Of __stdcall, Microsoft says

        An underscore (_) is prefixed to the name. The name is followed by the at sign (@) followed by the number of bytes (in decimal) in the argument list. Therefore, the function declared as int func( int a, double b ) is decorated as follows: _func@12

Re^8: Correct call for dll with Win32::API
by walto (Pilgrim) on Dec 06, 2008 at 07:01 UTC
    Thanks BrowserUK and ikegami for your efforts. I could not comprehend all infomations you gave me. But what I understood is that Win32::API is not suitable for using this dll. So I put this project aside.
    The card reader is used via usb. It might have a built-in serial converter. If I find some more time I could try to access the raw data from the device. For which Linux (my preffered OS) could be useful.