Where to put code

Im still new to the VC++ IDE. I have some code that counts files and updates some tables. I want the code to run automatically when the exe is launched. I got this to work by placing the code in the DDaoRecordView::OnInitialUpdate(). I placed it right after I sorted the recordset. It works fine, but should this code be elsewhere? Like maybe its own function and where should it be called from so that it runs automatically.. Thank you very much....
lgalmaAsked:
Who is Participating?
 
KangaRooConnect With a Mentor Commented:
That is also possible, but then it would get initialized in main(). I actually meant to place it outside of main()

//=========================================
bool Initialize() {/* Your Code */}
static bool isInitialized = Initialize();

int main() // or WinMain
{
  // ....
}
//=========================================
The static isInitialized will be initilaized before any code in the module is executed, that is, before main() is called.
0
 
KangaRooCommented:
static data is initialized before main is executed, for example:

bool Initialize() {/* Your Code */}
static bool isInitialized = Initialize();

There are several variants on this approach.
0
 
lgalmaAuthor Commented:
I think I see what youre saying(im not good at this).
soo.
Using your sample, You're saying I should call

static bool isInitialized = Initialize();

from inside main? right?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
lgalmaAuthor Commented:
Great, it works. I dont even have to load the form. I guess I was just scared to go into the mainfrm.cpp. Thanks.

PS. Im having some difficulty accessing the CDaoRecordsetView member functions from that source. If its something very simple, can you point me in the right direction? But thanks for the other answer.....
0
 
KangaRooCommented:
With MFC I'm not familiar, the static thing is common C++.
Errors when compiling?
0
 
lgalmaAuthor Commented:
I figured it out on the MFC stuff. Thank you very much..
0
All Courses

From novice to tech pro — start learning today.