VirtualBox

Ignore:
Timestamp:
Mar 29, 2009 3:07:18 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
45360
Message:

VBoxNetDHCP: Attempt at simplifying WinMain a bit...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp

    r18462 r18510  
    4949#include <vector>
    5050#include <string>
     51
     52#ifdef RT_OS_WINDOWS /* WinMain */
     53# include <Windows.h>
     54# include <stdlib.h>
     55#endif
    5156
    5257
     
    20372042
    20382043
    2039 
    20402044#ifndef VBOX_WITH_HARDENING
    20412045
     
    20532057
    20542058# ifdef RT_OS_WINDOWS
    2055 
    2056 #include <windows.h>
    2057 #include <iprt/mem.h>
    2058 
    2059 int WINAPI WinMain(          HINSTANCE hInstance,
    2060     HINSTANCE hPrevInstance,
    2061     LPSTR lpCmdLine,
    2062     int nCmdShow
    2063 )
    2064 {
    2065     int rc = RTR3InitAndSUPLib();
    2066     if (RT_FAILURE(rc))
    2067     {
    2068         RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: RTR3InitAndSupLib failed, rc=%Rrc\n", rc);
    2069         return 1;
    2070     }
    2071 
    2072 /** @todo r=bird: crt0.c is already doing all this stuff for us. It's available thru stdlib.h __argv and __argc IIRC. */
    2073 
    2074     LPWSTR lpwCmd = GetCommandLineW();
    2075     size_t size = wcslen(lpwCmd);
    2076     size++; /* for null terminator */
    2077 
    2078     int argc;
    2079     int ret = 1;
    2080 
    2081     LPWSTR * pwArgs = CommandLineToArgvW(lpwCmd,&argc);
    2082     if(pwArgs)
    2083     {
    2084         size+=argc-1; /* null terminators */
    2085         char **argv = (char**)RTMemTmpAlloc(size + argc*sizeof(char*));
    2086         if(argv)
    2087         {
    2088             char *pBuf = (char*)(argv+argc);
    2089             int i;
    2090             for(i = 0; i < argc; i++)
    2091             {
    2092                 argv[i] = pBuf;
    2093 
    2094                 int num = WideCharToMultiByte(
    2095                         CP_ACP, /*UINT CodePage*/
    2096                         0, /*DWORD dwFlags*/
    2097                         pwArgs[i],
    2098                         -1, /*int cchWideChar */
    2099                         argv[i], /*LPSTR lpMultiByteStr*/
    2100                         size, /*int cbMultiByte*/
    2101                         NULL, /*LPCSTR lpDefaultChar*/
    2102                         FALSE/*LPBOOL lpUsedDefaultChar*/
    2103                     );
    2104                 if(num <= 0)
    2105                     break;
    2106 
    2107                 size-=num;
    2108                 pBuf+=num;
    2109             }
    2110 
    2111             if(i == argc)
    2112             {
    2113                 ret = TrustedMain(argc, argv, NULL);
    2114             }
    2115             RTMemFree(argv);
    2116         }
    2117 
    2118         LocalFree(pwArgs);
    2119     }
    2120 
    2121     return ret;
    2122 }
    2123 
    2124 # endif
     2059/** (We don't want a console usually.) */
     2060int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
     2061{
     2062    NOREF(hInstance); NOREF(hPrevInstance); NOREF(lpCmdLine); NOREF(nCmdShow);
     2063    return main(__argc, __argv, environ);
     2064}
     2065# endif /* RT_OS_WINDOWS */
    21252066
    21262067#endif /* !VBOX_WITH_HARDENING */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette