0

I was wondering if there is a way to make specified code, most likely a function, run before the program quits out due to the user logging out etc.

I'm writing a Win32 app with no window in Dev C++. (if that makes any difference)

I've been searching a bit but can't find anything close to what I'm looking for so any help would be greatly appreciated. If you need any more info just ask, since I have no idea what this would entail.

Thanks in advance.

2
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by GotCake
Featured Replies
  • Well for anyone else who has this problem after looking into the Dev c++ version of stdlib.h, I found that it uses _onexit() instead. Read More

0
#include <iostream>
#include <stdlib.h>
using namespace std;


int foo()
{
    cout << " World\n";

    return 1;
}

int main()
{
    onexit(foo);

    cout << "Hello\n";
}
0

That easy wow... lol... thanks

EDIT:
Hmm thought it was almost too good to be true...
Do you need any header file or library for this to work?
Apparently the function doesn't exist.

EDIT again:
well headers other than the ones listed obviously...

0
#include <iostream>
#include <stdlib.h>
using namespace std;


int foo()
{
    cout << " World\n";

    return 1;
}

int main()
{
    onexit(foo);

    cout << "Hello\n";
}

Well I did a bit of detective work and your code was correct... for a Console program with VC++, however I'm making this with Dev C++ and it's a win32 app =(

2

Well for anyone else who has this problem after looking into the Dev c++ version of stdlib.h, I found that it uses _onexit() instead.

Comments
good spot
Nice to know you do your own research :)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.