Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^6: Correct call for dll with Win32::API

by walto (Pilgrim)
on Dec 05, 2008 at 05:40 UTC ( #728192=note: print w/replies, xml ) Need Help??


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

I installed Visual c++ and started dumpbin as you suggested. This is the output:
Dump of file c:\Programme\HCE300B_APP\ApiLib\HCE300_API.dll File Type: DLL Section contains the following exports for HCE300_API.dll 00000000 characteristics 0 time date stamp Thu Jan 01 01:00:00 1970 0.00 version 1 ordinal base 14 number of functions 14 number of names ordinal hint RVA name 5 0 0005A51C HCE300_Break 13 1 0005B148 HCE300_Close 3 2 0005A514 HCE300_GetDeviceType 9 3 0005AFD8 HCE300_GetLastStatus 1 4 0005B2C8 HCE300_GetRecordFormat 2 5 0005B260 HCE300_GetTrack2Density 14 6 0005A52C HCE300_Open 11 7 0005A854 HCE300_Read 12 8 0005B174 HCE300_Reset 4 9 0005A4F0 HCE300_SetDeviceType 7 A 0005B268 HCE300_SetRecordFormat 6 B 0005A4D0 HCE300_SetShowDialog 8 C 0005B200 HCE300_SetTrack2Density 10 D 0005AC5C HCE300_Write Summary 1000 .edata 3000 .idata 6000 .reloc 1A000 .rsrc 2000 BSS 5B000 CODE 2000 DATA
I also found some more C sample code:
char ReadBuf[250]; /* Open Success */ if(HCE300_Read(2, ReadBuf) == HCE300_OK) { } else { }
(I removed the unreadable chinese comments from the sample)

Replies are listed 'Best First'.
Re^7: Correct call for dll with Win32::API
by BrowserUk (Pope) on Dec 05, 2008 at 13:48 UTC

    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.

      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.
      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://728192]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2021-01-27 11:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?