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.

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


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

    return 1;
}

int main()
{
    onexit(foo);

    cout << "Hello\n";
}

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...

#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 =(

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.