Jump to content
Sign in to follow this  
JohnOne

Optionad dll parameters

Recommended Posts

JohnOne

Is it possible in some way to make parameters optional in an exported C++ win32 dll?

Kind of (this does not work) 

int func(LPCTSTR param1, LPCTSTR param2 = L"param"){
    //stuff
    return 0;
}

Or something similar, I know it's a long shot cause find find anything to suggest there is.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
GtaSpider

Whats the matter?

void func( int required, int optional = 0);

 

Should work with C++ (not with C)


www.AutoIt.de - Moderator of the German AutoIt Froum

Share this post


Link to post
Share on other sites
JohnOne

Does not work, crashes without error (Well OS error with option to close, wait or check online) when called from AutoIt.

EDIT:

That's fine for internal function but I've not been able to get it to work externally.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
funkey

Afaik you cannot use optional parameters in DLLs. This is because the C++ compiler handles the optional parameters at compile time. So if you compile a DLL there is no optional parameter possible. But you just can use AutoIt for using optional parameters in your UDF.

  • Like 1

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites
jaberwacky

You could go with your overloaded function idea though.

Come to think of it, there must be a better way.  Didn't Jon do it somehow with DllCall?

Edited by jaberwacky

Share this post


Link to post
Share on other sites
JohnOne

Cannot judge by native functions, because it's all handled in the interpreter.

Closest I'm going to get is in my other dll thread.

if (!param || !Param[0]){

    //provide a default;

}


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
Richard Robertson

The above is correct. Native functions do not have optional parameters. The headers may indicate default values which the precompiler stage will read and fill in right before compilation.

Example

void method(int parameter = 0)
{
}

int main()
{
    method();
    return 0;
}

// becomes

void method(int)
{
}

int main()
{
    method(0);
    return 0;
}

Share this post


Link to post
Share on other sites
trancexx

I'm not sure what jaberwacky meant, but DllCall doesn't provide way to omit default parameters.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.