Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Function Prototype

Posted on 2000-05-11
5
Medium Priority
?
571 Views
Last Modified: 2013-11-20
I am a newbie trying to learn MFC through self-study.  Came across this section of code from the MSDN library, on which I have some questions.  Would appreciate help.  Thanks.

Referring to the code appended:

Question 1:
What is the return type of InitInstance() and InitApplication()?  When is it legal to declare the prototype without a return type?

Question 2:
Why must the prototypes of these two functions be declared?  If the code had #included <afxwin.h> (and therefore the two functions would have been implemented as member functions of MFC class WinApp), would there be a need to declare the prototypes of these two functions, or could I just have used CWinApp::InitInstance() straight without the prototype declaration?  Is the prototype declarations made necessary because InitInstance() and InitApplication() are overridden?

==========================

#include <windows.h>

// Global variable
HINSTANCE hinst;

// Function prototypes.
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
InitApplication(HINSTANCE);     //<-- ?
InitInstance(HINSTANCE, int);   //<-- ?
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);

// Application entry point.
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{...}
0
Comment
Question by:teeyushg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:jacobkristensen
ID: 2799191
The declarations for InitInstance is as follows:

virtual BOOL InitInstance();

The CWinApp::InitApplication member function is obsolete in MFC. An initialization that you would have done in InitApplication should be moved to InitInstance!

Regarding your second question, as you can see InitInstance() is a virtual function which means that it must be overridden, therefore you must also declare it in your header file.

Jacob
0
 
LVL 4

Accepted Solution

by:
captainkirk earned 200 total points
ID: 2800627
A1a) The return type of InitInstance() is a BOOL (a boolean true/false value)

A1b) If you declare a prototype without a return type, the compiler will assume the return type is an "int".

A2) The prototypes are necessary because, as you have noted, they are overridden. Now you have a class DERIVED from CWinApp, say, CWinYourApp. You will need a CWinYourApp::InitInstance() function.
0
 

Author Comment

by:teeyushg
ID: 2801160
Would appreciate if you could explain a little further:

I copied the code verbatim from MSDN online.  The only #include file is Windows.h

1.  I can't seem to find any declaration of the "virtual BOOL InitInstance()" in Windows.h or in the files #included in it.  Where is it declared, in the case of this code? (I find it declared in afxwin.h though, but afxwin.h is not #included in this piece of code)

2.  As you mentioned, return type for InitInstance() is BOOL; and also that where return type not stated, type is INT.  So what is the reason for the omission of the return type from the function prototype?

Thank you!
0
 

Author Comment

by:teeyushg
ID: 2801166
Thanks to Jacob too! :)
0
 
LVL 4

Expert Comment

by:captainkirk
ID: 2801216
1) the prototype for InitInstance() is indeed in AfxWin.h... someone correct me if I'm wrong, but I believe the sample you found relates to older Windows versions... now the framework uses the AfxWin.h prototype and the implementation of the CWinApp::InitInstance() function is in appcore.cpp


2) if indeed the sample is from an older version of Windows, the return type may have been "int" and has since changed to "BOOL"
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question