/// @file SrcChangeMainProgEntry.cpp
/// @brief 用编译指示改变主程序入口点
/// VS2008控制台程序
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <stdio.h> ///< for getchar
#include <crtdbg.h> ///< for _ASSERT
#include <locale.h> ///< for LC_CTYPE
/// if we want to call original _tmain
/// please define CALL_MAIN_ORG
#define CALL_MAIN_ORG
int fnChangeProgEntry()
{
int iRc = 0;
wchar_t szACP[_MAX_PATH]; ///< for unicode print
/**
You can either use /ENTRY:WinMain to override the default name,
or compile with /MT so the compiler will mark the object files in such a
way that the linker grabs the runtime library (which provides
an entry point).
The runtime library entry point does some nice things like run global
constructors set up a global exception handler so you get a dialog box in
case of uncaught exceptions, but nothing it does is absolutely necessary.
-------------------------------------------------------------------------
NOTE: If you don't use the library entry point, no arguments are available
. You have to use the OS functions such as GetCurrentProcess and
GetCommandLine and GetStartupInfo instead to get the information normally
available as WinMain arguments. You weren't using any of that anyway.
But think twice about using your own entry point,
a lot of stuff depends on the library initialization and you'd better be
very sure you aren't using it.
*/
#pragma comment(linker, "/entry:fnChangeProgEntry")
_tprintf(L"Prog main Entry is fnChangeProgEntry\r\n");
wsprintf(szACP, _T(".%d"), GetACP());
_tsetlocale(LC_CTYPE, szACP);
#ifdef CALL_MAIN_ORG
{
int iArgc = 0;
LPWSTR * lpszArgv = NULL;
lpszArgv = CommandLineToArgvW(GetCommandLineW(), &iArgc);
/// forword declare
int _tmain(int argc, _TCHAR* argv[]);
iRc = _tmain(iArgc, lpszArgv);
GlobalFree(lpszArgv);
}
#endif
_tprintf(L"END, press any key to quit\r\n");
/** run result
on cmd line run : SrcChangeMainProgEntry.exe param1
output below:
Prog main Entry is fnChangeProgEntry
>> _tmain
argc = 2
argv[0] = [SrcChangeMainProgEntry.exe]
argv[1] = [param1]
<< _tmain
END, press any key to quit
*/
getchar();
return iRc;
}
int _tmain(int argc, _TCHAR* argv[])
{
int iIndex = 0;
_tprintf(L">> _tmain\r\n");
_tprintf(L"argc = %d\r\n", argc);
for (iIndex = 0; iIndex < argc; iIndex++)
_tprintf(L"argv[%d] = [%s]\r\n", iIndex, argv[iIndex]);
_tprintf(L"<< _tmain\r\n");
return 0;
}