Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

default args c++


  • Please log in to reply
8 replies to this topic

#1 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 11,277 posts

Posted 21 February 2012 - 10:31 AM

I'm having problems where autoit is crashing when calling a function in a dll file.

I am trying to give the function optional parameters.
From what I have read, it seems you can do it in much
the same way as autoit.

I have tried in a number of ways including

//prototype
//declaration

void add(int i = 0);
void add(int i = 0){
//stuff
}

void add(int i);
void add(int i = 0){
//stuff
}

void add(int);
void add(int i = 0){
//stuff
}

etc...

in all cases I get a crash if I do not pass it something.

Is there a specific way of achieving this for libraries, like overloading?

EDIT:

func is __stdcall if that makes any difference.

Edited by JohnOne, 21 February 2012 - 10:36 AM.








#2 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 10,194 posts

Posted 21 February 2012 - 10:51 AM

Optional parameters are not knowable at runtime. They are compile time constants ONLY. The reason they work in C++ when you include a header is because the header declares it so the compiler inserts it if you ignore it. If you are using a non-C++ language or not using the header which declares the default value, you must specify it like a normal parameter.

#3 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 11,277 posts

Posted 21 February 2012 - 11:06 AM

Yes the prototype is in a header file, and I'mm using VC++ VS2010.

AutoIt exits with -1073741819

Edited by JohnOne, 21 February 2012 - 11:07 AM.


#4 shanet

shanet

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 313 posts

Posted 21 February 2012 - 01:02 PM

JohnOne, it is my understanding that the prototype is where you declare defaults and the actual function does not have defaults. Eg:

int main(int a = 42, char b = 'a');  /* Prototype */ int main(int a, char <img src='http://aut1.autoit-cdn.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' /> {  /* Function */   /* blah blah */ }

In my (little) experience, this is the correct way to do this.
My code does not have bugs! It just develops random features.My ProjectsPure randomness
  • Small Minds.......................................................................................................Simple progress bar that changes direction at either sides.
  • ChristmasIt AutoIt Christmas Theme..........................................................I WAS BOOOORED!
  • DriveToy..............................................................................................................Simple joke script. Trick your friends into thinking their computer drive is haywire!
In Development
  • Your Background Task Organiser
  • AInstall Second Generation
BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

#5 Shaggi

Shaggi

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 309 posts

Posted 21 February 2012 - 01:14 PM

Johnone, what you are trying to do is impossible. Optional parameters is only syntactic sugar resolved at compiletime as richard says. The function still expects the last parameter, hence you are corrupting the stack.

Normally, when you have default parameters, you set them to 0 - and the called function recognizes this as a default parameters. Eg:
void foo(int a, char * string) {     if(!string) { // user called it like foo(5, NULL);         //handle     } else {         //work with it     }     ... }

Else you have to get into variadic functions, or passing an array of parameters and a count.

E: I guess you could overload the functions, afaik _stdcall gets exported as _[name]@[parameters_in_bytes]. However, you would still have to choose the right one.

JohnOne, it is my understanding that the prototype is where you declare defaults and the actual function does not have defaults. Eg:

int main(int a = 42, char b = 'a');  /* Prototype */ int main(int a, char <img src='http://aut1.autoit-cdn.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' /> {  /* Function */   /* blah blah */ }

In my (little) experience, this is the correct way to do this.

You can also do it in the definition.

Edited by Shaggi, 21 February 2012 - 01:17 PM.

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

#6 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 10,194 posts

Posted 21 February 2012 - 07:17 PM

Yes the prototype is in a header file, and I'mm using VC++ VS2010.

AutoIt exits with -1073741819

............................................________........................
....................................,.-‘”...................``~.,..................
.............................,.-”...................................“-.,............
.........................,/...............................................”:,........
.....................,?......................................................,.....
.................../...........................................................,}....
................./......................................................,:`^`..}....
.............../...................................................,:”........./.....
..............?.....__.........................................:`.........../.....
............./__.(.....“~-,_..............................,:`........../........
.........../(_....”~,_........“~,_....................,:`........_/...........
..........{.._$;_......”=,_.......“-,_.......,.-~-,},.~”;/....}...........
...........((.....*~_.......”=-._......“;,,./`..../”............../............
...,,,___.`~,......“~.,....................`.....}............../.............
............(....`=-,,.......`........................(......;_,,-”...............
............/.`~,......`-...................................../...................
.............`~.*-,.....................................|,./.....,__...........
,,_..........}.>-._...................................|..............`=~-,....
.....`=~-,__......`,.........................................................
...................`=~-,,.,......................................................
................................`:,,...........................`..............__..
.....................................`=-,...................,%`>--==``.......
........................................_..........._,-%.......`...............
...................................,<`.._|_,-&``................`..............

  • funkey and Mat like this

#7 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 21 February 2012 - 07:27 PM

That was good..

#8 jchd

jchd

    Whatever your capacity, resistance is futile.

  • MVPs
  • 4,571 posts

Posted 22 February 2012 - 12:03 AM

No, Jave (wild guess).
Good anyway!

SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!

SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)

An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work

 

PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

RegExp tutorial: enough to get started

Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here


#9 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 11,277 posts

Posted 22 February 2012 - 12:14 AM

Cheers for the info gentlebodes.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users