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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
KangaRooCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.