Jump to content

Optionad dll parameters


JohnOne
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
}
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...