Menu

Using_WinMain_and_OwlMain

ObjectWindows provides a default WinMain function that provides extensive error checking and exception handling. This WinMain function sets up the application and calls the OwlMain function.

Although you can use your own WinMain by placing it in a source file, there is little reason to do so. Everything you would otherwise do in WinMain you can do in OwlMain or in TApplication initialization member functions. In the following example, OwlMain checks to see whether the use specified any parameters on the application's command line. If so, OwlMain creates the application object and uses the first parameter as the application name. If not, OwlMain creates the application object and uses Wow! as the application name.

#include <owl\applicat.h>
#include <string.h>

class TMyApplication: public owl::TApplication
{
public:
 TMyApplication(const owl::tstring& name = owl::tstring()) : TApplication(name) {}
};

int
OwlMain(int argc, char* argv[])
{
 char title[30];
 if(argc >= 2)
  strcpy(title, argv[1]);
 else
  strcpy(title, "Wow!");
 return TMyApplication(title).Run();
}

If you do decide to provide your own WinMain, TApplication supports passing traditional WinMain function parameters with another constructor. The following example shows how to use that constructor to pass WinMain parameters to the TApplication object:

#include <owl\applicat.h>

class TMyApplication : public owl::TApplication
{
public:
 TMyApplication (const owl::tstring& name,
   HINSTANCE instance,
   HINSTANCE prevInstance,
   const owl::tstring& cmdLine,
   int cmdShow)
  : TApplication (name, instance, prevInstance, cmdLine, cmdShow){}
};

int
PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  LPSTR lpszCmdLine, int nCmdShow)
{
 return TMyApplication("MyApp", hInstance, hPrevInstance, lpszCmdLine, nCmdShow).Run();
}

Related

Wiki: Application_and_module_objects
Wiki: Initializing_the_application

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.