src/main/epoc/SDL_main.cpp
author Sam Lantinga <slouken@libsdl.org>
Tue, 05 Mar 2002 19:55:32 +0000
changeset 292 eadc0746dfaf
parent 252 e8157fcb3114
child 297 f6ffac90895c
permissions -rw-r--r--
Added SDL_LockRect() and SDL_UnlockRect()
Incorporated XFree86 extension libraries into the source
slouken@173
     1
/*
slouken@173
     2
    SDL - Simple DirectMedia Layer
slouken@173
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
slouken@173
     4
slouken@173
     5
    This library is free software; you can redistribute it and/or
slouken@173
     6
    modify it under the terms of the GNU Library General Public
slouken@173
     7
    License as published by the Free Software Foundation; either
slouken@173
     8
    version 2 of the License, or (at your option) any later version.
slouken@173
     9
slouken@173
    10
    This library is distributed in the hope that it will be useful,
slouken@173
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@173
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@173
    13
    Library General Public License for more details.
slouken@173
    14
slouken@173
    15
    You should have received a copy of the GNU Library General Public
slouken@173
    16
    License along with this library; if not, write to the Free
slouken@173
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@173
    18
slouken@173
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@173
    21
*/
slouken@173
    22
slouken@173
    23
/*
slouken@173
    24
    SDL_main.cpp
slouken@173
    25
    The Epoc executable startup functions 
slouken@173
    26
slouken@173
    27
    Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi)
slouken@173
    28
*/
slouken@173
    29
slouken@173
    30
#include <e32std.h>
slouken@173
    31
#include <e32def.h>
slouken@173
    32
#include <e32svr.h>
slouken@173
    33
#include <e32base.h>
slouken@173
    34
#include <estlib.h>
slouken@173
    35
#include <stdlib.h>
slouken@173
    36
#include <stdio.h>
slouken@173
    37
#include <w32std.h>
slouken@173
    38
#include <apgtask.h>
slouken@173
    39
slouken@173
    40
#include "SDL_error.h"
slouken@173
    41
slouken@173
    42
#ifndef EXPORT_C
slouken@173
    43
# ifdef __VC32__
slouken@173
    44
#  define IMPORT_C __declspec(dllexport)
slouken@173
    45
#  define EXPORT_C __declspec(dllexport)
slouken@173
    46
# endif
slouken@173
    47
# ifdef __GCC32__
slouken@173
    48
#  define IMPORT_C
slouken@173
    49
#  define EXPORT_C __declspec(dllexport)
slouken@173
    50
# endif
slouken@173
    51
#endif
slouken@173
    52
slouken@173
    53
#if defined(__WINS__)
slouken@173
    54
#include <estw32.h>
slouken@173
    55
IMPORT_C void RegisterWsExe(const TDesC &aName);
slouken@173
    56
#endif
slouken@173
    57
slouken@173
    58
/* The prototype for the application's main() function */
slouken@173
    59
#define main	SDL_main
slouken@173
    60
extern "C" int main (int argc, char *argv[], char *envp[]);
slouken@173
    61
extern "C" void exit (int ret);
slouken@173
    62
slouken@173
    63
slouken@173
    64
/* Epoc main function */
slouken@173
    65
slouken@173
    66
GLDEF_C TInt E32Main() 
slouken@173
    67
    {
slouken@173
    68
    /*  Get the clean-up stack */
slouken@173
    69
	CTrapCleanup* cleanup = CTrapCleanup::New();
slouken@173
    70
slouken@173
    71
    #if defined(__WINS__)
slouken@173
    72
    /* arrange for access to Win32 stdin/stdout/stderr */
slouken@173
    73
   	RWin32Stream::StartServer();	
slouken@173
    74
    #endif
slouken@173
    75
slouken@173
    76
    /* Arrange for multi-threaded operation */
slouken@173
    77
	SpawnPosixServerThread();	
slouken@173
    78
slouken@173
    79
    /* Get args and environment */
slouken@173
    80
	int argc=0;
slouken@173
    81
	char** argv=0;
slouken@173
    82
	char** envp=0;
slouken@173
    83
	__crt0(argc,argv,envp);	
slouken@173
    84
slouken@173
    85
    #if defined(__WINS__)
slouken@173
    86
	/* Cause the graphical Window Server to come into existence */
slouken@173
    87
	RSemaphore sem;
slouken@173
    88
	sem.CreateGlobal(_L("WsExeSem"),0);
slouken@173
    89
	RegisterWsExe(sem.FullName());
slouken@173
    90
    #endif
slouken@173
    91
slouken@173
    92
slouken@173
    93
    /* Start the application! */
slouken@173
    94
slouken@173
    95
    /* Create stdlib */
slouken@173
    96
    _REENT;
slouken@173
    97
slouken@173
    98
    /* Set process and thread priority */
slouken@173
    99
    RThread currentThread;
slouken@173
   100
slouken@173
   101
    currentThread.Rename(_L("SdlProgram"));
slouken@173
   102
    currentThread.SetProcessPriority(EPriorityLow);
slouken@173
   103
    currentThread.SetPriority(EPriorityMuchLess);
slouken@173
   104
slouken@173
   105
    /* Call stdlib main */
slouken@173
   106
    int ret = main(argc, argv, envp); /* !! process exits here if there is "exit()" in main! */	
slouken@173
   107
slouken@173
   108
    /* Call exit */
slouken@173
   109
    exit(ret); /* !! process exits here! */			
slouken@173
   110
slouken@173
   111
    /* Free resources and return */
slouken@173
   112
    CloseSTDLIB();
slouken@173
   113
   	delete cleanup;									
slouken@173
   114
    return(KErrNone);
slouken@173
   115
    }
slouken@173
   116
slouken@173
   117
/* Epoc dll entry point */
slouken@173
   118
#if defined(__WINS__)
slouken@173
   119
GLDEF_C TInt E32Dll(TDllReason)
slouken@173
   120
	{
slouken@173
   121
	return(KErrNone);
slouken@173
   122
	}
slouken@173
   123
slouken@173
   124
EXPORT_C TInt WinsMain(TAny *)
slouken@173
   125
	{
slouken@173
   126
    E32Main();
slouken@173
   127
	return KErrNone;
slouken@173
   128
	}
slouken@173
   129
#endif