Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello World again, I´m working with my first C++ project, even without a previous experience in this language. So far by now I´ve read that a C++ project MUST have an initial function name "int Main", but this specific one just doesn´t have any.

Why ?. Is it posible to set another entry point for a C++ app ?. How can I do it ?, where can I find this particular function, if it´s a standard method ?

Thanks in advance.

What I have tried:

I have not tried nothing at all about this matter, the app works fine, so I´m very intrigued.
Posted
Updated 29-Jun-16 12:32pm
Comments
Dave Kreskowiak 29-Jun-16 13:49pm    
Library projects (compile down to .DLL) don't have a Main method.
Miguel Altamirano Morales 29-Jun-16 15:20pm    
Thanks a lot for answering me, Dave. The App is a native C++ project, developed with Visual Studio 2010, and it builds an .exe file, so I guess it´s not a Library Project, or is it ?.

Greetings from mexico City, sorry about my english.
Jochen Arndt 29-Jun-16 14:28pm    
You should tell us about your app, the platform / OS, and the used development tools.
Maybe the main function is hidden in some way (it is automatically added by your dev environment and calls another function which is presented as template).
Miguel Altamirano Morales 29-Jun-16 15:23pm    
Thanks a lot for your advice Jochen. The App is a native C++ project, developed with Visual Studio 2010, runs in Windows 7, and it builds an .exe file.

Greetings from mexico City, sorry about my english.
jeron1 29-Jun-16 15:49pm    
Have you tried searching for WinMain?

With Windows GUI applications, there is the WinMain entry point (Windows)[^] (see also Walkthrough: Creating Windows Desktop Applications (C++)[^]). This will be called by a hidden main function implementation that is added to your program upon building.

When creating a MFC application even a WinMain implementation is automatically added to your program. The implementation calls InitInstance of your CWinApp derived class which is then the "visible" entry point for MFC applications.

If you are going to write a Windows console program, you must implement a C/C++ style main function. However, there are the Microsoft specific extensions _tmain and wmain which can be used instead (they are again called by a hidden implementation that provides conversions between Unicode and multi byte character strings). See also main: Program Startup[^].
 
Share this answer
 
Comments
jeron1 29-Jun-16 15:58pm    
Good post. +5
Miguel Altamirano Morales 29-Jun-16 17:42pm    
Thanks a lot for your second answer Jochen, it´s very compleat. I´m going to see everything on it. You are a good person and I´m very grateful.

I didn´t see a Reply section for this answer, so I´m sending you this message expecting you´ll be able to see it.
phil.o 30-Jun-16 1:57am    
Making a comment to one's answer, or replying to an existing comment, and the author will automatically be warned of your message; first in the top bar on this site, and second by mail, if user has activated this option.
So, you did well in replying to Mr Arndt's comment.
Jochen Arndt 30-Jun-16 2:47am    
Thank you for your feedback and accepting the solution.

As already said by phil.o, you have replied to my answer. With quick answer questions and solutions the button is just named "Have a question or comment".
First of all, please see: Entry point — Wikipedia, the free encyclopedia.

Your question suggests that your concern is the return int value. Even if it is not the case, knowing what it does is something good to know.

This is mostly a matter of history. There is a tradition for entry-level functions to return 0 in all cases except the cases of abnormal termination. In all (or almost all) OS, there are the libraries uses to check up the status of the process. When a process is terminated, your code can read this value from the status. Also, when the application is executed synchronously in one or another kind of a batch file, the starting command can return this value, which can be assigned to some kind of the batch/script variable which can further be used, for example, to fork further execution. At the same time, this is just the tradition or culture, not any kind of standard. The tradition to return 0 is stable enough, and all other values are totally application-dependent; if they are essential, they can be described in application-specific documentation. If the entry point function used the return is void, 0 is still returned to the runtime system; this is the default.

With time, the importance of this technique goes down; most applications simply ignore the possibility to return anything. There are two important reasons for that: structural exception handling and then graphics UI, and, to certain extent, threading. The dreaded technique of returning "status" from the function is eliminated; using it would be just silly. Exceptions are much more powerful. Normally, all applications catch all exceptions in all threads and show much more informative diagnostics of the problems in the application itself. Throwing the exceptions into the runtime system, execution environment, is relatively rare, used only in the simplest application or are indicative of low-tech. Moreover, event-oriented UI applications (that means, nearly all of them, if you take only the decent ones) catch all exceptions in the UI main event and show the problem diagnostics immediately.

—SA
 
Share this answer
 
Comments
Miguel Altamirano Morales 29-Jun-16 18:46pm    
Thank you very much Sergey, and yes, it´s good and very valuable to know what the return value of the entry point does.
My very detailed concern in what I´m doing is to know the right flow (or thread ?) of execution of this app. What I have to do is to display an image, like a full portrait on the screen that should appear right before the first GUI dialog. And I say GUI dialog because I can see now that this kind of projects don´t have windows forms.
As you suppose, I don´t know WHERE to display this portrait (PORTADA in spanish) or WHERE to include it in order to be properly displayed at runtime.
Miguel Altamirano Morales 29-Jun-16 18:55pm    
I feel a litlle bit ashamed because maybe I´m asking a very naive question, specially for people like you, but please, understand this is my very first assignation with a native C++ project. I am lucky I could be able to solve a few things in two weeks by now, but it gets more complicated for me each day. At least I honestly gave a warning about it to my clientes.
Maybe they hired me because they could´t find anybody else, but I know for sure I´ll get what they want, I just only need time for investigation.
Sergey Alexandrovich Kryukov 29-Jun-16 20:20pm    
There is nothing wrong with this question. We have a lot of stupid questions, but they are usually stupid due to the logical contradiction, most typically wrong baseless assumptions and inadequate ambitions; in other way, false knowledge is stupid, but lack of knowledge isn't. Your question is nothing like that; it's natural on the certain level of learning. Please don't hesitate to ask.

Here is the thing: answering your question heavily depends on 1) your exact platform; 2) UI/graphics framework/library you are using. So answering in too much detail won't make sense until you specify that. Most usual approach is this: the UI is event oriented; the OS provides an event used to handle some graphics rendering event. You handle this event, use the graphical context reference/pointer/handler to draw an image or something else. The OS makes sure there are no redundant calls. For example, if you hide your window behind some some other window or an edge of the screen and then show again, the re-rendering event may be triggered, but not if you simply move the window around. This mechanism may seem overcomplicated, but this is not so; it's very reasonable and efficient. Now, some libraries may do it internally, so you only need to place some object in some container, then it will be rendered. It seems to be much simpler, but it's not necessarily better. Also, modern libraries transparently use hardware acceleration.

With these hints of the background, you would need to ask a separate question, as soon as you provide the required information. If you want me to participate, please give me a link to your new question by adding a comment to this comment.

—SA
Miguel Altamirano Morales 30-Jun-16 10:25am    
Good morning Sergey (it´s 9:14 am in México City).

The platform I´m working with is Visual Studio 2010, the App is a native C++ one, but I still cannot determine what kind of project is, (if it´s a MFC or a Win32), but it generates an .EXE file, not a .DLL, though it seems to have MFC classes. How can I check this for sure ?

About what you ask for the UI/graphics framework, I just don´t know, let me see if I can solve this and I´ll tell you.

Thank you Sergey.

Спасибо !!!
Sergey Alexandrovich Kryukov 30-Jun-16 10:42am    
That is enough, thank you.

In this environment, you use raw Windows API (perhaps with a very thing MFC wrapper (see MFC documentation: CImage), or combining it with raw Windows API). The approach I described in my previous comment fully applies. The role of the event handler is played by your handler of the event WM_PAINT. Look the documentation on this event and handling it. See also the Windows API methods Invalidate*..., for completeness.

If you need more detail or cannot find all ends, please post a separate question, on a separate question page. You can give me a link to this question by commenting on this comment; I'll try to answer quickly.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900