Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: functions with optional arguments in Windows DLLs

by BrowserUk (Pope)
on Dec 12, 2007 at 16:33 UTC ( #656666=note: print w/replies, xml ) Need Help??


in reply to functions with optional arguments in Windows DLLs

I've never heard of "optional" arguments to a C routine. A variable number as with int printf( char *t, ... ), but not optional.

If you're going to access a vararg function using Win32::API, you would need to do something hinky like create one API mapping for each number of args you are likely to use and then call the appropriate variant:

use Win32::API; $function2 = Win32::API->new( 'mydll', 'sum_integers', 'II', 'I', ); $function3 = Win32::API->new( 'mydll', 'sum_integers', 'III', 'I', ); $function4 = Win32::API->new( 'mydll', 'sum_integers', 'IIII', 'I', ); $function5 = Win32::API->new( 'mydll', 'sum_integers', 'IIIII', 'I', ); $function6 = Win32::API->new( 'mydll', 'sum_integers', 'IIIIII', 'I', );

Not pretty, but it ought to at least work.


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.

Replies are listed 'Best First'.
Re^2: functions with optional arguments in Windows DLLs
by spurperl (Priest) on Dec 13, 2007 at 20:08 UTC
    Indeed, you're right about optional arguments in C. So I guess the DLL I'm looking at (rmchart) wasn't written in C, but probably some kind of Basic). This is how the particular function I'm interested in is described:
    nResult (LONG) = RMC_Draw2File( ByVal nCtrlId (LONG), ByRef sFileName (ASCIIZ), Optional ByVal nWidth (LONG), Optional ByVal nHeight (LONG), Optional ByVal nJPGQualityLevel (LONG) )
    And judging by the description, the behavior I need happens when the optional args are not provided.

      According to this, optional arguments are 'filled in' to their default values, by the compilers of languages that support them. It also says that the default values should be clearly documented.

      The upshot appears to be that you will have to pass the default values when calling from a language that does not support this behaviour. So, you will need to look up the dfault values and provide them explicitly either every time you call via Win32::API or supply a wrapper function that fills them in.


      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.
        Yes, I suppose I'll have to do that. Thanks for the help.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2020-07-10 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?