Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
  1. dumpbin.exe /exports the.dll
  2. If you have a tool available to disassemble the dll, you can work out which calling convention was used. For the example above, the when built using _stdcall, the disassembly looks like:
    Disassembly of Function test (0x00331000) SYM:test 0x331000: PUSH EBP 0x331001: MOV EBP,ESP 0x331003: MOVSX EAX,DWORD PTR [EBP+0x8] ; ARG:0x8 0x331007: MOVSX ECX,DWORD PTR [EBP+0xC] ; ARG:0xC 0x33100B: ADD EAX,ECX 0x33100D: MOVSX ECX,DWORD PTR [EBP+0x10] ; ARG:0x10 0x331011: ADD EAX,ECX 0x331013: MOVSX ECX,DWORD PTR [EBP+0x14] ; ARG:0x14 0x331017: ADD EAX,ECX 0x331019: POP EBP 0x33101A: RET 0x10

    When built with _cdecl it looks like

    Disassembly of Function test (0x00331000) SYM:test 0x331000: PUSH EBP 0x331001: MOV EBP,ESP 0x331003: MOVSX EAX,DWORD PTR [EBP+0x8] ; ARG:0x8 0x331007: MOVSX ECX,DWORD PTR [EBP+0xC] ; ARG:0xC 0x33100B: ADD EAX,ECX 0x33100D: MOVSX ECX,DWORD PTR [EBP+0x10] ; ARG:0x10 0x331011: ADD EAX,ECX 0x331013: MOVSX ECX,DWORD PTR [EBP+0x14] ; ARG:0x14 0x331017: ADD EAX,ECX 0x331019: POP EBP 0x33101A: RET

    The significant part of that is the last (RET) line. In the former, the called code (the function itself) is responsible for cleaning up the stack, hence RET 0x10.

    In the latter case, the calling code is responsible for cleaning up the stack, hence the bare return.

  3. Not with Win32::API that I am aware of.

    It might be possible to build a modified version to do it, but it would be messy. Using XS would be simpler and better.

  4. I don't really understand this. Are you using W::API::Prototype::ApiLink() or Win32::API->new() and 'ssss'?

    If the latter, according to the docs, the 's' template does not mean 'short', but 'struct'.

    As mentioned above, shorts are placed on the stack as ints; the difference is in how they are addressed (16-bit indirect operands instead of 32-bit indirect etc.). I think you would have to use 'IIII' for the latter method.

  5. I'm far from expert with XS.

    You would still need to determine which calling convention was used, but it should be possible to prototype the external call in the XS code to cater for either successfully, though you may need to do a little manual intervention if the dll was built with _cdecl.

If you are not getting traps when using 'IIII' (or ApiLink and 'SHORT'), then odds are that it was built using _stdcall and Win32::API may be all you need. Though if you are prepared to get stuck in with writing an XS wrapper, it would be considerably more efficient.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: Win32::API and 'short' arguments by BrowserUk
in thread Win32::API and 'short' arguments by spurperl

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found