Exemple #1
0
GLDEF_C TInt E32Main()
	{     
	CTrapCleanup::New();

	RWin32Stream::StartServer();	// arrange for access to Win32 stdin/stdout/stderr
	SpawnPosixServerThread();	// arrange for multi-threaded operation

	int argc=0;
	wchar_t** wargv=0;
	wchar_t** wenvp=0;


	__crt0(argc,wargv,wenvp);			// get args & environment from somewhere

#ifndef EKA2
	// Cause the graphical Window Server to come into existence
	RSemaphore sem;
	sem.CreateGlobal(_L("WsExeSem"),0);
	RegisterWsExe(sem.FullName());
#endif

	int ret=wmain(argc, wargv, wenvp);		// go

	// no need to explicitly delete the cleanup stack here as all memory used by
	// the process will be released by RProcess::Terminate(), called from inside exit().

	exit(ret);	// to get atexit processing, eventually terminates this process

	return(KErrNone);
	}
Exemple #2
0
extern "C" int
WinMainCRTStartup()
{
  int iArgc;
  LPWSTR *iArgv = CommandLineToArgvW(GetCommandLineW(), &iArgc);
  ExitProcess(wmain(iArgc, iArgv));
}
Exemple #3
0
void __F_NAME(__NTMain,__wNTMain)( void )
/***************************************/
{

   init_heap();

    __process_fini = &__FiniRtns;
   __InitRtns( 255 );
   __CommonInit();
   __initPOSIXHandles();
   __appcwdlen = strrchr(_LpPgmName, '/') - _LpPgmName + 1;
   __appcwdlen = __appcwdlen > 512 ? 512 : __appcwdlen;
   __appcwd= (char*)malloc(__appcwdlen);
   strncpy(__appcwd, _LpPgmName, __appcwdlen);
   __appcwd[__appcwdlen] = 0;
   ___Argv[0] = _LpPgmName;
   if( *_LpCmdLine != 0)
   {
      ___Argc = 2;
      ___Argv[1] = _LpCmdLine;
   } else ___Argc = 1;

   #ifdef __WIDECHAR__
      exit( wmain( ___wArgc, ___wArgv ) );
   #else
      exit( main( ___Argc, ___Argv ) );
   #endif
}
Exemple #4
0
void __F_NAME(__NTMain,__wNTMain)( void )
/***************************************/
{
#if defined(__SW_BR)
  #if defined(_M_IX86)
    REGISTRATION_RECORD rr;

    __NewExceptionFilter( &rr );
  #endif
    __process_fini = __FiniRtns;
    __InitRtns( 255 );
    __CommonInit();
    exit( __F_NAME(main( ___Argc, ___Argv ),wmain( ___wArgc, ___wArgv )) );
#else
    REGISTRATION_RECORD     rr;
    thread_data             *tdata;

    __InitRtns( INIT_PRIORITY_THREAD );
    tdata = __alloca( __ThreadDataSize );
    memset( tdata, 0, __ThreadDataSize );
    // tdata->__allocated = 0;
    tdata->__data_size = __ThreadDataSize;

    __InitThreadData( tdata );
    __NTMainInit( &rr, tdata );
    __F_NAME(__CMain,__wCMain)();
#endif
}
int main()
{
	wchar_t **enpv, **argv;
	int argc, si = 0;
	__wgetmainargs(&argc, &argv, &enpv, _CRT_glob, &si);
	return wmain(argc, argv);
}
Exemple #6
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow) {
  int argc;
  wchar_t** argv = CommandLineToArgvW(GetCommandLine(), &argc);
  wmain(argc, argv);

  return 0;
}
Exemple #7
0
/*
 *	real entry point
 */
int __stdcall wWinMain(HINSTANCE instance, HINSTANCE prev_instance, 
                       LPWSTR cmd_line, int show_cmd)
{
	extern wchar_t ** __wargv;
	extern int __argc;
	
	return wmain(__argc, __wargv);
}
Exemple #8
0
int
WinMainCRTStartup()
{
  LPWSTR wczCmdLine = GetCommandLine();
  int argc = 0;
  LPWSTR *argv = CommandLineToArgvW(wczCmdLine, &argc);
  ExitProcess(wmain(argc, argv));
}
Exemple #9
0
extern "C" int mainCRTStartup()
{
	int argc = 0;
	WCHAR* *argv;

	argv = CommandLineToArgvW(GetCommandLine(), &argc);

	return wmain(argc, argv);
}
Exemple #10
0
 void __wCMain( void )
 {
     #if !defined(__OSI__)
         /* allocate alternate stack for F77 */
         __ASTACKPTR = (char *)__alloca( __ASTACKSIZ ) + __ASTACKSIZ;
     #endif
     __CommonInit();
     exit( wmain( ___wArgc, ___wArgv ) );
 }
Exemple #11
0
void wmainCRTStartup(void)
{
    DWORD Argc;
    PWSTR *Argv;

    Argv = CommandLineToArgvW(GetCommandLineW(), &Argc);
    if (0 == Argv)
        ExitProcess(GetLastError());

    ExitProcess(wmain(Argc, Argv));
}
Exemple #12
0
int main(int argc, char **argv)
{
  LPWSTR commandLine = GetCommandLineW();
  int argcw = 0;
  LPWSTR *argvw = CommandLineToArgvW(commandLine, &argcw);
  if (!argvw)
    return 127;

  int result = wmain(argcw, argvw);
  LocalFree(argvw);
  return result;
}
Exemple #13
0
int
wmainCRTStartup()
{
  int argc;
  LPWSTR *argv = CommandLineToArgvW(GetCommandLine(), &argc);
  if (argv == NULL)
    {
      fputs("This program requires Windows NT.\r\n", stderr);
      exit(-1);
    }
  else
    exit(wmain(argc, argv));
}
Exemple #14
0
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int)
{
    int argc = 0;
    const boo::SystemChar** argv = (const wchar_t**)(CommandLineToArgvW(lpCmdLine, &argc));
    static boo::SystemChar selfPath[1024];
    GetModuleFileNameW(nullptr, selfPath, 1024);
    static const boo::SystemChar* booArgv[32] = {};
    booArgv[0] = selfPath;
    for (int i=0 ; i<argc ; ++i)
        booArgv[i+1] = argv[i];

    logvisor::CreateWin32Console();
    return wmain(argc+1, booArgv);
}
Exemple #15
0
int
wmainCRTStartup()
{
    int argc = 0;
    LPWSTR *argv = CommandLineToArgvW(GetCommandLine(), &argc);
    if (argv == NULL)
    {
        MessageBoxA(NULL, "This program requires Windows NT.",
                    "Incompatible Windows version", MB_ICONEXCLAMATION);
        ExitProcess((UINT) -1);
    }
    else
        exit(wmain(argc, argv));
}
Exemple #16
0
__declspec(dllexport) wchar_t * powershell_reflective_mimikatz(LPCWSTR input)
{
	int argc = 0;
	wchar_t ** argv;
	
	if(argv = CommandLineToArgvW(input, &argc))
	{
		outputBufferElements = 0xff;
		if(outputBuffer = (wchar_t *) LocalAlloc(LPTR, outputBufferElements))
			wmain(argc, argv);
		LocalFree(argv);
	}
	return outputBuffer;
}
Exemple #17
0
int WINAPI WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{
    int argc;
    wchar_t **argv;

    argv = CommandLineToArgvW(GetCommandLine(),&argc);
    wmain(argc,argv);

    // memory leak from malloc, wcsdup
    return 0;
}
Exemple #18
0
	int mainCRTStartup()
	{
		TraceFunc();

		prolog();

		int argc = 0;
		wchar_t ** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);

		int ret = wmain(argc, argv);

		::LocalFree(argv);

		TraceFunc();
		return epilog(ret);
	}
Exemple #19
0
int
WinMainCRTStartup()
{
  int iArgc;
  LPWSTR *wszArgv = CommandLineToArgvW(GetCommandLineW(), &iArgc);
  if (wszArgv == NULL)
    {
      MessageBoxA(NULL,
		  "This program requires Windows NT.",
		  "msgboxW",
		  MB_ICONSTOP);
      ExitProcess((DWORD) -1);
    }

  ExitProcess(wmain(iArgc, wszArgv));
}
Exemple #20
0
GLDEF_C TInt E32Main()
	{     
	//Create Cleanup Stack
	CTrapCleanup* pCleanup = CTrapCleanup::New();
	if( pCleanup )
		{
		int argc=0;
		wchar_t** wargv=0;
		wchar_t** wenvp=0;
#ifdef SYMBIAN_OE_POSIX_SIGNALS
		sigenable();
#endif
		// get args & environment from somewhere

		//coverity[alloc_fn]

		__crt0(argc,wargv,wenvp);

		//Call user(application)'s main
		int ret = 0;
		
		//coverity[leave_without_push] 
			
		TRAPD(retVal, ret = wmain(argc, wargv, wenvp));

		if(!ret)
			{
			ret = retVal;
			}

		// finish with atexit processing which terminates this process
		exit(ret);
		if (wenvp)
			{
			for (int i = 0; wenvp[i]; ++i)
				{
				User::Free(wenvp[i]);
				}
			User::Free(wenvp);
			}
		delete pCleanup;
		}
	else
		return KErrNoMemory;

	return(KErrNone);
	}
Exemple #21
0
int __cdecl main(int argc, char *argv[])
{
    WCHAR **argvW = HeapAlloc(GetProcessHeap(),0,argc*sizeof(LPWSTR));
    UINT cp = GetConsoleCP();
    int len = 0;
    int i = 0;
//    BREAK_POINT
//    reg_printfW(L"argc=%d\r\n", argc);
    for(i = 0; i < argc; i++)
    {
        len = strlen(argv[i]) + 1;
        argvW[i] = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
        //RtlZeroMemory(argvW[i], (len + 1)*sizeof(WCHAR));
        MultiByteToWideChar(cp, 0, argv[i], len, argvW[i], len);
//    printf("argv[%d]:%S\r\n", i, argvW[i]);
    }
    return wmain(argc, argvW);
}
int main (int argc, char *argv[])
{
  wchar_t **wargv = (wchar_t **) malloc (argc * sizeof (wchar_t *));
  int inx;
  char *locale = setlocale (LC_ALL, "");
  /* !!!!WARNING!!!! There's a GCC bug : if the *first* output call is not wide (wprintf/fwprintf)
     then *all* the subsequent wide output functions will *not* work */
  if (locale)
    wprintf (L"Locale=%s\n", setlocale (LC_ALL, ""));
  else
    wprintf (L"Can't apply the system locale. "
	L"Possibly wrong setting for LANG environment variable. "
	L"Using the C locale instead.\n");
  for (inx = 0 ; inx < argc; inx++)
    {
      wargv[inx] = malloc_narrow_as_wide (argv[inx]);
    }
  return wmain (argc, wargv);
}
Exemple #23
0
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int) {
  signal(SIGABRT, abortHandler);
  signal(SIGSEGV, abortHandler);
  signal(SIGILL, abortHandler);
  signal(SIGFPE, abortHandler);

  int argc = 0;
  const boo::SystemChar** argv;
  if (lpCmdLine[0])
    argv = (const wchar_t**)(CommandLineToArgvW(lpCmdLine, &argc));
  static boo::SystemChar selfPath[1024];
  GetModuleFileNameW(nullptr, selfPath, 1024);
  static const boo::SystemChar* booArgv[32] = {};
  booArgv[0] = selfPath;
  for (int i = 0; i < argc; ++i)
    booArgv[i + 1] = argv[i];

  logvisor::CreateWin32Console();
  SetConsoleOutputCP(65001);
  return wmain(argc + 1, booArgv);
}
Exemple #24
0
int main(int argc, char* argv[])
{
	// convert input to wstring
	std::vector<std::wstring> wideStrings;
	for (int i = 0; i < argc; i++)
	{
		std::wstring str = convertUtf8ToWString(argv[i]);
		wideStrings.push_back(str);
	}

	// create argv replacement
	wchar_t** wargv = new wchar_t*[argc];
	for (int i = 0; i < argc; i++)
	{
		wargv[i] = (wchar_t*) wideStrings[i].c_str();
	}

	int result = wmain(argc,wargv);

	delete[] wargv;
	return result;
}
Exemple #25
0
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
    return wmain();
}
Exemple #26
0
__declspec(noinline) int
__tmainCRTStartup (void)
{
  _TCHAR *lpszCommandLine = NULL;
  STARTUPINFO StartupInfo;
  WINBOOL inDoubleQuote = FALSE;
  memset (&StartupInfo, 0, sizeof (STARTUPINFO));
  
  if (mingw_app_type)
    GetStartupInfo (&StartupInfo);
  {
    void *lock_free = NULL;
    void *fiberid = ((PNT_TIB)NtCurrentTeb())->StackBase;
    int nested = FALSE;
    while((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock,
							  fiberid, 0)) != 0)
      {
	if (lock_free == fiberid)
	  {
	    nested = TRUE;
	    break;
	  }
	Sleep(1000);
      }
    if (__native_startup_state == __initializing)
      {
	_amsg_exit (31);
      }
    else if (__native_startup_state == __uninitialized)
      {
	__native_startup_state = __initializing;
	_initterm ((_PVFV *)(void *)__xi_a, (_PVFV *)(void *) __xi_z);
      }
    else
      has_cctor = 1;

    if (__native_startup_state == __initializing)
      {
	_initterm (__xc_a, __xc_z);
	__native_startup_state = __initialized;
      }
    _ASSERTE(__native_startup_state == __initialized);
    if (! nested)
      (VOID)InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0);
    
    if (__dyn_tls_init_callback != NULL)
      __dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL);
    
    _pei386_runtime_relocator ();
    __mingw_oldexcpt_handler = SetUnhandledExceptionFilter (_gnu_exception_handler);
#ifdef _WIN64
    __mingw_init_ehandler ();
#endif
    __mingw_prepare_except_for_msvcr80_and_higher ();
    
    _fpreset ();

    if (mingw_app_type)
      {
#ifdef WPRFLAG
    lpszCommandLine = (_TCHAR *) _wcmdln;
#else
    lpszCommandLine = (char *) _acmdln;
#endif
    while (*lpszCommandLine > SPACECHAR || (*lpszCommandLine&&inDoubleQuote))
      {
	if (*lpszCommandLine == DQUOTECHAR)
	  inDoubleQuote = !inDoubleQuote;
#ifdef _MBCS
	if (_ismbblead (*lpszCommandLine))
	  {
	    if (lpszCommandLine) /* FIXME: Why this check? Should I check for *lpszCommandLine != 0 too? */
	      lpszCommandLine++;
	  }
#endif
	++lpszCommandLine;
      }
    while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR))
      lpszCommandLine++;

    __mingw_winmain_hInstance = (HINSTANCE) &__ImageBase;
    __mingw_winmain_lpCmdLine = lpszCommandLine;
    __mingw_winmain_nShowCmd = StartupInfo.dwFlags & STARTF_USESHOWWINDOW ?
				StartupInfo.wShowWindow : SW_SHOWDEFAULT;
    }
    duplicate_ppstrings (argc, &argv);
#ifdef WPRFLAG
    __winitenv = envp;
    /* C++ initialization.
       gcc inserts this call automatically for a function called main, but not for wmain.  */
    __main ();
    mainret = wmain (argc, argv, envp);
#else
    __initenv = envp;
    mainret = main (argc, argv, envp);
#endif
    if (!managedapp)
      exit (mainret);

    if (has_cctor == 0)
      _cexit ();
  }
  return mainret;
}
Exemple #27
0
int
__tmainCRTStartup(
    void
) {
#ifdef _WINMAIN_
    _TUCHAR* lpszCommandLine;
    STARTUPINFO StartupInfo;
    BOOL inDoubleQuote = FALSE;

    __try {
        /*
        Note: MSDN specifically notes that GetStartupInfo returns no error, and throws unspecified SEH if it fails, so
        the very general exception handler below is appropriate
        */
        GetStartupInfo(&StartupInfo);
    } __except (EXCEPTION_EXECUTE_HANDLER) {
        return 255;
    }

#endif  /* _WINMAIN_ */

    /*
     * Guard the initialization code and the call to user's main, or
     * WinMain, function in a __try/__except statement.
     */

    __try {
        /*
         * There is a possiblity that the module where this object is
         * linked into is a mixed module. In all the cases we gurantee that
         * native initialization will occur before managed initialization.
         * Also in anycase this code should never be called when some other
         * code is initializing native code, that's why we exit in that case.
         *
         * Do runtime startup initializers.
         *
         * Note: the only possible entry we'll be executing here is for
         * __lconv_init, pulled in from charmax.obj only if the EXE was
         * compiled with -J.  All other .CRT$XI* initializers are only
         * run as part of the CRT itself, and so for the CRT DLL model
         * are not found in the EXE.  For that reason, we call _initterm,
         * not _initterm_e, because __lconv_init will never return failure,
         * and _initterm_e is not exported from the CRT DLL.
         *
         * Note further that, when using the CRT DLL, executing the
         * .CRT$XI* initializers is only done for an EXE, not for a DLL
         * using the CRT DLL.  That is to make sure the -J setting for
         * the EXE is not overriden by that of any DLL.
         */
        void* lock_free = 0;
        void* fiberid = ((PNT_TIB)NtCurrentTeb())->StackBase;
        int nested = FALSE;

        while ((lock_free = InterlockedCompareExchangePointer((volatile PVOID*)&__native_startup_lock, fiberid, 0)) != 0) {
            if (lock_free == fiberid) {
                nested = TRUE;
                break;
            }

            /* some other thread is running native startup/shutdown during a cctor/domain unload.
                Should only happen if this DLL was built using the Everett-compat loader lock fix in vcclrit.h
            */
            /* wait for the other thread to complete init before we return */
            Sleep(1000);
        }

        if (__native_startup_state == __initializing) {
            _amsg_exit(_RT_CRT_INIT_CONFLICT);
        } else if (__native_startup_state == __uninitialized) {
            __native_startup_state = __initializing;
#ifndef _SYSCRT

            if (_initterm_e(__xi_a, __xi_z) != 0) {
                return 255;
            }

#else  /* _SYSCRT */
            _initterm((_PVFV*)(void*)__xi_a, (_PVFV*)(void*)__xi_z);
#endif  /* _SYSCRT */
        } else {
            has_cctor = 1;
        }

        /*
        * do C++ constructors (initializers) specific to this EXE
        */
        if (__native_startup_state == __initializing) {
            _initterm(__xc_a, __xc_z);
            __native_startup_state = __initialized;
        }

        _ASSERTE(__native_startup_state == __initialized);

        if (!nested) {
            /* For X86, the definition of InterlockedExchangePointer wrongly causes warning C4312 */
#pragma warning(push)
#pragma warning(disable:4312)
            InterlockedExchangePointer((volatile PVOID*)&__native_startup_lock, 0);
#pragma warning(pop)
        }

        /*
         * If we have any dynamically initialized __declspec(thread)
         * variables, then invoke their initialization for the primary
         * thread used to start the process, by calling __dyn_tls_init
         * through a callback defined in tlsdyn.obj.
         */
        if (__dyn_tls_init_callback != NULL &&
                _IsNonwritableInCurrentImage((PBYTE)&__dyn_tls_init_callback)) {
            __dyn_tls_init_callback(NULL, DLL_THREAD_ATTACH, NULL);
        }

        /* Enable buffer count checking if linking against static lib */
        _CrtSetCheckCount(TRUE);
#ifdef _WINMAIN_
        /*
         * Skip past program name (first token in command line).
         * Check for and handle quoted program name.
         */
#ifdef WPRFLAG

        /* OS may not support "W" flavors */
        if (_wcmdln == NULL) {
            return 255;
        }

        lpszCommandLine = (wchar_t*)_wcmdln;
#else  /* WPRFLAG */
        lpszCommandLine = (unsigned char*)_acmdln;
#endif  /* WPRFLAG */

        while (*lpszCommandLine > SPACECHAR ||
                (*lpszCommandLine && inDoubleQuote)) {
            /*
             * Flip the count from 1 to 0 or 0 to 1 if current character
             * is DOUBLEQUOTE
             */
            if (*lpszCommandLine == DQUOTECHAR) {
                inDoubleQuote = !inDoubleQuote;
            }

#ifdef _MBCS

            if (_ismbblead(*lpszCommandLine)) {
                if (lpszCommandLine) {
                    lpszCommandLine++;
                }
            }

#endif  /* _MBCS */
            ++lpszCommandLine;
        }

        /*
         * Skip past any white space preceeding the second token.
         */
        while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR)) {
            lpszCommandLine++;
        }

#ifdef WPRFLAG
        mainret = wWinMain(
#else  /* WPRFLAG */
        mainret = WinMain(
#endif  /* WPRFLAG */
                      (HINSTANCE)&__ImageBase,
                      NULL,
                      lpszCommandLine,
                      StartupInfo.dwFlags & STARTF_USESHOWWINDOW
                      ? StartupInfo.wShowWindow
                      : SW_SHOWDEFAULT
                  );
#else  /* _WINMAIN_ */
#ifdef WPRFLAG
        __winitenv = envp;
        mainret = wmain(argc, argv, envp);
#else  /* WPRFLAG */
        __initenv = envp;
        mainret = main(argc, argv, envp);
#endif  /* WPRFLAG */
#endif  /* _WINMAIN_ */

        /*
         * Note that if the exe is managed app, we don't really need to
         * call exit or _c_exit. .cctor should be able to take care of
         * this.
         */
        if (!managedapp)
            exit(mainret);
        if (has_cctor == 0)
            _cexit();
    } __except (_XcptFilter(GetExceptionCode(), GetExceptionInformation())) {
        /*
         * Should never reach here
         */
        mainret = GetExceptionCode();

        /*
         * Note that if the exe is managed app, we don't really need to
         * call exit or _c_exit. .cctor should be able to take care of
         * this.
         */
        if (!managedapp) {
            _exit(mainret);
        }

        if (has_cctor == 0) {
            _cexit();
        }
    } /* end of try - except */

    return mainret;
}
Exemple #28
0
int main()
{
    return wmain();
}
Exemple #29
0
void __cdecl wmainCRTStartup()
{
    wchar_t *cl;
    char *clbuffer;
    int argc;
    int res;

    // check and init fpu if required,
    // exit if required, but not available
    if (_FPinit && (_FPinit() == 0)) ExitProcess(-2);

    // call c initialisers
    if (_initterm(__xi_a, __xi_z, 1)) ExitProcess(-3);

    // call c++ initialisers
    _initterm(__xc_a, __xc_z, 0);

    // get command line
    cl = GetCommandLine();
    if (cl == NULL) cl = L"";

    // parse command line into argv array
    {
        int clsize;

        clsize = wcrt_parse_argvw(cl, &argc, NULL, NULL);

        clbuffer = (char *) malloc(clsize);

        if (clbuffer)
        {
            wcrt_parse_argvw(
                cl,
                &argc,
                (wchar_t **) clbuffer,
                (wchar_t *) (clbuffer + (argc + 1)*sizeof(wchar_t *))
            );
        } else {
            argc = 0;
        }
    }

    // -WCRT- tag
    __asm {
        test  eax, 0x0a0d0a0d
        sub   eax, 0x54524357
        sub   eax, 0x0a0d0a0d
    }

    // call main
    if (clbuffer)
    {
        res = wmain(argc, (wchar_t **) clbuffer, 0);
        free(clbuffer);

    } else {

        res = wmain(0, 0, 0);
    }

    exit(res);
}
Exemple #30
0
/*
 * routine in DLL to do initialization (in this case, C++ constructors)
 */
extern void __cdecl _initterm(_PVFV *, _PVFV *);

#ifdef _WINMAIN_

#ifdef WPRFLAG
int wWinMainCRTStartup(
#else  /* WPRFLAG */
int WinMainCRTStartup(
#endif  /* WPRFLAG */

#else  /* _WINMAIN_ */

#ifdef WPRFLAG
int wmainCRTStartup(
#else  /* WPRFLAG */
int mainCRTStartup(
#endif  /* WPRFLAG */

#endif  /* _WINMAIN_ */
        void
        )
{
        int argc = 0;   /* three standard arguments to main */
        _TSCHAR **argv = NULL;
        _TSCHAR **envp = NULL;

        int argret = 0;

#ifdef _WINMAIN_
        _TUCHAR *lpszCommandLine;
        STARTUPINFO StartupInfo;
#endif  /* _WINMAIN_ */

#ifdef WPRFLAG
	int envp_count = 0;
#endif

        //_startupinfo    startinfo;

        /*
         * Determine if this is a managed application
         */
        //managedapp = check_managed_app();

	/*
	 * Set __app_type properly
	 */
#ifdef _WINMAIN_
	//__set_app_type(_GUI_APP);
#else  /* _WINMAIN_ */
	//__set_app_type(_CONSOLE_APP);
#endif  /* _WINMAIN_ */

#ifdef _WINMAIN_
#ifdef WPRFLAG
	dbgmsg("wWinMainCRTStartup()");
#else
	dbgmsg("WinMainCRTStartup()");
#endif
#else
#ifdef WPRFLAG
	dbgmsg("wmainCRTStartup()");
#else
	dbgmsg("mainCRTStartup()");
#endif
#endif
	/*
	 * Mark this module as an EXE file so that atexit/_onexit
	 * will do the right thing when called, including for C++
	 * d-tors.
	 */
	__onexitbegin = __onexitend = (_PVFV *)(-1);
	    
	dbgmsg("OK1b");

	/*
	 * Propogate the _fmode and _commode variables to the DLL
	 * (crash in crtdll.dll...?)
	 */
	//*_IMP___FMODE = _fmode;
	dbgmsg("OK1c");
	//*_IMP___COMMODE = _commode;
	dbgmsg("OK1d");
	
#ifdef _M_IX86
	/*
	 * Set the local copy of the Pentium FDIV adjustment flag
	 * (not supported by crtdll.dll)
	 */
	
	//_adjust_fdiv = * _imp___adjust_fdiv;
#endif  /* _M_IX86 */
	
	dbgmsg("OK2");

	/*
	 * Run the RTC initialization code for this DLL
	 */
#ifdef _RTC
	_RTC_Initialize();
#endif  /* _RTC */
	
	/*
	 * Call _setargv(), which will trigger a call to __setargv() if
	 * SETARGV.OBJ is linked with the EXE.  If SETARGV.OBJ is not
	 * linked with the EXE, a dummy _setargv() will be called.
	 */
#ifdef WPRFLAG
	//_wsetargv();
#else  /* WPRFLAG */
	//_setargv();
#endif  /* WPRFLAG */

	/*
	 * If the user has supplied a _matherr routine then set
	 * __pusermatherr to point to it.
	 */
	//            if ( !__defaultmatherr )
	//    __setusermatherr(_matherr);
	
#ifdef _M_IX86
	//_setdefaultprecision();
#endif  /* _M_IX86 */

	/*
	 * Do runtime startup initializers.
	 *
	 * Note: the only possible entry we'll be executing here is for
	 * __lconv_init, pulled in from charmax.obj only if the EXE was
	 * compiled with -J.  All other .CRT$XI* initializers are only
	 * run as part of the CRT itself, and so for the CRT DLL model
	 * are not found in the EXE.  For that reason, we call _initterm,
	 * not _initterm_e, because __lconv_init will never return failure,
	 * and _initterm_e is not exported from the CRT DLL.
	 *
	 * Note further that, when using the CRT DLL, executing the
	 * .CRT$XI* initializers is only done for an EXE, not for a DLL
	 * using the CRT DLL.  That is to make sure the -J setting for
	 * the EXE is not overriden by that of any DLL.
	 */
	//_initterm( __xi_a, __xi_z );

#ifdef _RTC
	atexit(_RTC_Terminate);
#endif  /* _RTC */

	/*
	 * Get the arguments for the call to main. Note this must be
	 * done explicitly, rather than as part of the dll's
	 * initialization, to implement optional expansion of wild
	 * card chars in filename args
	 */

	dbgmsg("OK3");

	//startinfo.newmode = 0;

#ifdef WPRFLAG
	_wcmdln = GetCommandLineW();
	argv = (_TSCHAR**)CommandLineToArgvW(_wcmdln, &argc);
	if (argv == NULL)
	  FatalAppExitA(0, "This application requires Windows NT.");

	_wpgmptr = (wchar_t*)argv[0];
	__wargv = (wchar_t**)argv;
	__argc = argc;
	_wenviron[0] = GetEnvironmentStringsW();
	while ((_wenviron[envp_count][0] != 0) &
	       (envp_count < MAX_WENVIRON_COUNT))
	  {
	    _wenviron[envp_count+1] = _wenviron[envp_count]+
	      wcslen(_wenviron[envp_count])+1;
	    envp_count++;
	  }
	
	if ((argv == NULL) | (envp_count >= MAX_WENVIRON_COUNT))
	  argret = -1;

	if (argret < 0)
	  _amsg_exit(_RT_SPACEARG);

	_wenviron[envp_count] = NULL;
	envp = (_TSCHAR**)_wenviron;

#else  /* WPRFLAG */
	argret = __GetMainArgs(&argc, &argv, &envp,
			       0, NULL /*&startinfo*/);

	if (argv == NULL)
	  _amsg_exit(_RT_SPACEARG);

	__argc = argc;
	__argv = argv;
	_environ = envp;
	_pgmptr = argv[0];
#endif
	dbgmsg("OK4");

	/*
	 * do C++ constructors (initializers) specific to this EXE
	 */
	//_initterm( __xc_a, __xc_z );
	
#ifdef _WINMAIN_
	/*
	 * Skip past program name (first token in command line).
	 * Check for and handle quoted program name.
	 */
#ifdef WPRFLAG
	/* OS may not support "W" flavors */

	if (_wcmdln == NULL)
	  FatalAppExitA(0, "This application requires Windows NT.");

	lpszCommandLine = (wchar_t *)_wcmdln;

#else  /* WPRFLAG */
	lpszCommandLine = (unsigned char *)_acmdln;
#endif  /* WPRFLAG */
	
	if ( *lpszCommandLine == DQUOTECHAR ) {
	  /*
	   * Scan, and skip over, subsequent characters until
	   * another double-quote or a null is encountered.
	   */
	  while ( *++lpszCommandLine && (*lpszCommandLine
					 != DQUOTECHAR) );
	  /*
	   * If we stopped on a double-quote (usual case), skip
	   * over it.
	   */
	  if ( *lpszCommandLine == DQUOTECHAR )
	    lpszCommandLine++;
	}

	while (*lpszCommandLine > SPACECHAR)
	  lpszCommandLine++;

	if (*lpszCommandLine >= SPACECHAR)
	  lpszCommandLine++;

	dbgmsg("OK5");

	/*
	 * Skip past any white space preceeding the second token.
	 */
	while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR)) {
	  lpszCommandLine++;
	}

	StartupInfo.dwFlags = 0;
	GetStartupInfo( &StartupInfo );

#ifdef WPRFLAG
	    __winitenv = (wchar_t**)envp;
	    exit(wWinMain(
#else  /* WPRFLAG */
            __initenv = envp;
	    exit(WinMain(
#endif  /* WPRFLAG */
                       GetModuleHandleA(NULL),
                       NULL,
                       (LPTSTR)lpszCommandLine,
                       StartupInfo.dwFlags & STARTF_USESHOWWINDOW
                        ? StartupInfo.wShowWindow
                        : SW_SHOWDEFAULT
		       ));

#else  /* _WINMAIN_ */

#ifdef WPRFLAG
	    dbgmsg("OK6");
            exit(wmain(argc, (wchar_t**)argv, (wchar_t**)envp));
#else  /* WPRFLAG */
	    dbgmsg("OK6");
            exit(main(argc, argv, envp));
#endif  /* WPRFLAG */

#endif  /* _WINMAIN_ */
}