CMyWinApp::InitInstance is never called in console app.

Hello,

I'm using MFC, MSVC60. I created simple console application with MFC
support with MSVC wizard. Everything is cool and working. However, if
I inherit from CWinApp and override InitInstance, it doesn't have any
effect. The method is never called.

I searched sources of MFC and noticed that InitInstance is called
either from DLLMain or AfxWinMain. Both of them obviously don't exist
in console application.

Now my quaestions are: Should I call InitInstance manually? Should I
somehow to cause the MFC to call InitInstance indirectly? Or should I
abandon InitInstance at all and put application initialization stuff
in _tmain instead?

TIA
Alex


0
Alex
11/1/2004 3:49:37 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
1082 Views

Similar Articles

[PageSpeed] 50

Hi Alex,

Have a look at:

http://www.codeguru.com/Cpp/misc/misc/consoleapps/article.php/c243/

M

"Alex Blekhman" <tkfx^NOSPAM^@yahoo.com> wrote in message 
news:O1NSmpCwEHA.3896@TK2MSFTNGP09.phx.gbl...
> Hello,
>
> I'm using MFC, MSVC60. I created simple console application with MFC
> support with MSVC wizard. Everything is cool and working. However, if
> I inherit from CWinApp and override InitInstance, it doesn't have any
> effect. The method is never called.
>
> I searched sources of MFC and noticed that InitInstance is called
> either from DLLMain or AfxWinMain. Both of them obviously don't exist
> in console application.
>
> Now my quaestions are: Should I call InitInstance manually? Should I
> somehow to cause the MFC to call InitInstance indirectly? Or should I
> abandon InitInstance at all and put application initialization stuff
> in _tmain instead?
>
> TIA
> Alex
>
> 


0
11/1/2004 5:16:10 PM
"M" <ihatespam.0.a101888@spamgourmet.com> wrote in message
news:ubuhd.1002$Fu2.828@fe1.news.blueyonder.co.uk...
> Hi Alex,
>
> Have a look at:
>
> http://www.codeguru.com/Cpp/misc/misc/consoleapps/article.php/c243/

That is what I did eventually (more or less). I looked at AfxWinMain
and did similar things in _tmain. However, solution at CodeGuru is
cleaner. I'll switch to that one.

Thanks.


0
Alex
11/1/2004 6:40:17 PM
Reply:

Similar Artilces:

Problem Refreshing Contact Form from External .NET App
I created a custom ASP.NET app that is launched from the CRM Contact form. It is configured (isv.config) to only be launched while editing an existing contact (not new). My custom app modifies data on the CRM Contact form. It them refreshs the data on the Contact form before the custom form closes. My custom app works fine if I open up an existing contact. If I create a new contact and press the save button the toolbar button that lauches my app on the contact form is displayed. If I then launch my custom app from this button and save the data on my custom form, a problem occurrs on...

Default console app with MFC won't compile
Howdy, I am runinng MS Visual C++ 2003, version 7.1.3088. When I generate using the wizard a console app with MFC support I get the following error: c:\Documents and Settings\jhoward\My Documents\EapolTests\DeleteThis\DeleteThis.cpp(18) : error C2731: 'main' : function cannot be overloaded c:\Documents and Settings\jhoward\My Documents\EapolTests\DeleteThis\DeleteThis.cpp(17) : see declaration of 'main' This is with NO changes added by me. WTF? Ji m Howard ...

is it possible to add a MACRO to a Spreadsheet from VB app??
...

Running a MFC-app as a system service
Hi, I want to run an MFC-app as a XP-system service. I made a wrapper service which is started as a service upon boot and the launches the mfc app. When started manually everything is fine but when the service starts after boot, the mfc pops up a message box which states that there "was an error creating an empty document". I tracked down that ProcessShellCommand in InitInstance fails. Whats wrong? Do I have to delay the appstart until all other services (designs et al.) are running, i.e. make it dependant from above services? Withdraw my question.... ...

Making an App wait 3 minutes without using sleep() function...
I'm trying to get create an process killer mfc app that checks every 5 min. for a process and kills it when it found it running... I'm trying to disable yahoo messenger chatting to my students while on a lab time. So instead of playing to the cat and mouse i want to run the app at startup and make it check for "YPager.exe" every 3 minutes... Since Sleep() make the PC work instaead of really sleeping, I want to avoid overuse of resources (CPU specially) Any clues? Best regards, Abu Abdillah. Try human engineering instead. Tell the little beggars that if they use IM in la...

What windwos API call to close all the open windows
Hi, All, I want to close the active program in the windows except the current windows, what is the windows system API call should use? Thank you! closelate > I want to close the active program in the windows except the current > windows, what is the windows system API call should use? Thank you! Use EnumWindows to enumerate all top level windows. If the window is not the window you want to close, use PostMessage with WM_CLOSE to close it. --- Ajay Thanks Ajay, I use EnumWindows and WM_CLOSE, it close all the windows but reboot, what if I don't want window to restart? Ajay K...

QUERY: apps still looking like Win95/98 styles... woes :S
Is MFC the main thing behind how your window application will look like? Am wondering what is the easiest way to update an application you are developing, which is still using old Windows 95/98 style windows, menus and toolbars. Update to say Windows 2000 or XP style. Do I need to use a newer version of the MFC? I am using the lastest version of MS PlatformSDK that is compatible for Visual C++ 6.0 (PlatformSDK Feb2003 release). You need to add a manifest file. -- Vipin Aravind MVP "KevinGPO" <kevingpo@hotmail.com> wrote in message news:efv66MCGGHA.3936@TK2MSFTNGP12...

256 Character Limit on Edit Box Control/ODBC MFC App
Hi I’m developing a SDI project that allows a user to edit text in a MSSQL7 database table. This is achieved via ODBC through an edit box control. I'm using Visual C++ 6 on Windows 2000 Server, but will shortly be carrying on the project on NT4 workstatio The data type on the db field is varchar (2000) and the VC++ member variable type for the edit control is CString value with validation - again 2000 characters However I've found that whenever over 256 characters are entered an error is returned i.e: 'Please enter no more than 256 characters. Using the debugger I've tra...

SaveBarState fails when it is called from a thread
Hi, In my application, I use SaveBarState() for persisting control bar state. The code fragment is something like this. void CMainFrame::OnSavePersistance() { SaveBarState(_T("My Persistence")); // Saves some information to an xml file } Since my xml saving takes some time I changed the code to execute in a thread UINT ThreadFn(LPVOID pParam) { CMainFrame* pThis = (CMainFrame*)pParam; pThis->SaveBarState(_T("My Persistence")); return 0; } void CMainFrame::OnCntrlbartst() { AfxBeginThread( ThreadFn, this ); } But, now in the thread function SaveBarState...

pie chart for win32 app
I wanna draw some pie chart in a win32/sdk application where could I get some sample code . 3d pie chart is better thanks Good news: there's an example of how to do this in the code for our book "Win32 Programming" Bad news: its a 13MB download Sort-of-bad news: it is written in pseudo-C++ (I was trying to show how to write C code, but I wasn't going to write the whole app in C, that takes far too much effort), so you'll have to do do a bit of fairly trivial translation to get it into pure MFC code. www.flounder.com/downloads.htm joe On Thu, 4 Dec 2008 11:37:2...

Access the call stack
In a debug build, is there a way for me to get a list of functions on the call stack? I.e., I have a function that is getting passed incorrect data and I want to display the call stack so I can find out who called this function. Oh yeah, this is happening on a beta tester's computer, so I can't just set a breakpoint. Note it is NOT crashing so I don't really need the post mortem Watson-type setup... I am hoping there is a call that gets the call stack info... Thanks, Steve > In a debug build, is there a way for me to get a list of functions on > the call stack? I.e., I h...

phone calls in outlook 2007 crm integration
Hello, Am I correct in assuming that there is no way to designate who a phone call is to if you are using the default Outlook (task) form to track a phone call? If I am calling in regard to an opportunity, I usually want to set the 'regarding' field to the opportunity, so as far as I can tell there is no way to set the 'to' field? Thanks! On Aug 18, 4:47=A0pm, "jpop" <a...@afd.com> wrote: > Hello, > > Am I correct in assuming that there is no way to designate who a phone ca= ll > is to if you are using the default Outlook (task) form to tra...

Can I set up a phone log for each call received?
yes -- David Biddulph "Nicky" <Nicky@discussions.microsoft.com> wrote in message news:245737AB-ACAE-4339-97E2-893A818E6B4A@microsoft.com... > ...

use child class as base class in service call
Hi, I know this is basic OO concept , and not a problem in local calls. I know The base type can specify the derived class as a known type using the KnownTypeAttribute. What about the opposite? I want to use a derived class instance as parameter to a WCF service method, and all properties I need is really in base class, so I just want to use it as base class, but I get an error: "....is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types p...

Change monitor resolution with API call
This may be going out on a limb, but I need to make a button that changes the monitor resolution based on a previously set variable. I've been reading about API calls that can do this but I'm not sure which to use and how to implement this. Can some one point me in the right direction? Thanks -Will This is not something you should do. When you change resolution, it affects all apps, not just yours. It is likely all you will accomplish is making your users angry. They have their resolutions set to their own preferences. -- Dave Hargis, Microsoft Access MVP "rc51wv"...

calling a form
I am trying to call a new form I added to my MFC project from the application main menu. (Sort of like calling the "About" dialog box). How can I do this? -- hf Dont know what exactly you want, but something like the following will show your dialog as a modal dialog: CMyDialog dlg; dlg.DoModal(); -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com "hfontanez" <hfontanez@discussions.microsoft.com> wrote in message news:D058509C-387B-4E58-8222-A93EE2B8E8CE@microsoft.com... > I am trying to call a new form I added to my MFC project from the application > main m...

Excel 2007 embedded in VB app
I have a VB6 application that has an OLE container with an embedded Excel chart. Our office updated to Excel 2007 and now although the app works the charts looks like crap. Since the app is fairly large my goal is to keep the devlopement in VB6 but am open to any ideas or suggestions. What i want to do is: 1. Keep my app in VB6 and find a workaround for the crappy looking charts. the charts now look very blocky and the grid lines and bars look like they have bolded outlines. The x-axis also used to show dates that were sideways and very readable and now they just look like text that is ...

Consolication of data
Anyone have a quick way of taking a set of data (x value of time) tha is presented in 10-minute bins (data point every 10-minutes) an consolidate to 30-minute binned data sets (essentially sum every 10-minute bins to each 30-minute bin). Thanks. Mik -- Message posted from http://www.ExcelForum.com My data actually starts in B9, does that changes how things are done i the formula? Mik -- Message posted from http://www.ExcelForum.com My data actually starts in B9, does that changes how things are done i the formula? Mik -- Message posted from http://www.ExcelForum.com Hi Mike Using...

installing SQL 2008 express and database with my vb app
Hi I have built a application in vb.net pro 2008 that uses a SQL express database I have been able to create an installation application project that installs the application perfect, but I am having to manually setup SQL express and my database I have had a look on the web with no luck, but would like to be able to have my application instalation also install the SQL express product as well as my database Is this possible and where can I find a guide on how to do this ... Thanks <address_is@invalid.invalid> wrote in message news:515824539294325110.892775addre...

Error Handling in Excel Based App
Hello: I am trying to handle exceptions in my code. Here the the code i have Code: Dim XLFileConn As New OleDbConnection 'New OleDbConnection object XLFileConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filename & _ ";Extended Properties=""Excel 8.0;HDR=YES;IMEX=1""" 'New connection string Try Try XLFileConn.Open() 'Open a connection to the choosen Excel file Catch ex As Exception 'Code to detect and handle an exception generated by ...

*Best* app to share Outlook Calendar and Contacts without Exchange
Hi there, We're a dozen people team wanting to share calendar, contacts, and maybe files & news, for our projects. I want to avoid big MS Exchange and would prefer a lean (& cheap) solution. Our users are either located in 2 different offices linked by a VPN, or are road warriors that have no VPN access (only web & mail access), so I guess e-mail borne systems may be the solution of choice for us. Clients are : Outlook 2000 SP3 & Outlook 2003 SP1 - so bug-ridden Netfolders is not a choice for us. I've seen an interesting list at http://www.slipstick.com/outlook/shar...

Calling DialogBox() in C#
Hi All, I have created a Windows Form that I wish to display as a Dialog Box (i.e. calling the Windows API function DialogBox). I have two questions: - How do I get the WndProc of that form - How do I get the Dialog Template name or identifier of that form? Thanks, Kodjo __________ Information from ESET NOD32 Antivirus, version of virus signature database 4798 (20100122) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com Hello, > I have created a Windows Form that I wish to display as a Dialog Box (i.e. > calling the...

Could not complete Ph calls after upgrade to version 3.0
After upgrading to version 3.0 Could not complete Phone Calls Activities, When you try to complete it, it comes up with the followin errors. Any ideas, how we could fix this issues, thanks. Regards, Kyaw Microsoft CRM Unhandled Error Details: Server Error in '/' Application. ------------------------------------------------------------------------ Server was unable to process request. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the cod...

How to pass all input to windows under my App?
My app is (optionally) full screen and On Top. But I want to pass all keyboard and mouse input to whatever is under it as if it wasn't there. Is it possible? How? TIA, Harvey On Mar 21, 5:15 am, "Harvey" <harve...@juno.com> wrote: > My app is (optionally) full screen and On Top. But I want to pass all > keyboard and mouse input to whatever is under it as if it wasn't > there. > Is it possible? How? > TIA, > Harvey Thoughts anyone? Harvey ...

EXtending the CRM 3.0 Application to other ASP.NET apps
Anyone have the best practice for this? Is Web Services the bet way or the ASP.NET Asseblies? Thanks in Advance for any and all help. You might want to refer to the SDK for CRM: http://www.microsoft.com/downloads/details.aspx?FamilyID=9C178B68-3A06-4898-BC83-BD14B74308C5&displaylang=en -- Matt Wittemann http://icu-mscrm.blogspot.com "JP123" wrote: > Anyone have the best practice for this? Is Web Services the bet way or the > ASP.NET Asseblies? > > Thanks in Advance for any and all help. ...