当前位置:   article > 正文

GetCommandLine CommandLineToArgvW_getcommandlinea commandlinetoargvw

getcommandlinea commandlinetoargvw
  1. // CmdLine.cpp : Defines the entry point for the application.
  2. //
  3. #include "stdafx.h"
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include <shellapi.h>
  7. int APIENTRY WinMain(HINSTANCE hInstance,
  8. HINSTANCE hPrevInstance,
  9. LPSTR lpCmdLine,
  10. int nCmdShow)
  11. {
  12. // TODO: Place code here.
  13. LPTSTR str=GetCommandLine();
  14. MessageBox(NULL,str,TEXT("str"),MB_OK);
  15. /*
  16. 然后调用
  17. LPWSTR * CommandLineToArgvW(
  18. LPCWSTR lpCmdLine, // pointer to a command-line string
  19. int *pNumArgs // receives the argument count
  20. );
  21. */
  22. int numArgs;
  23. LPWSTR *argv=CommandLineToArgvW(
  24. str, // pointer to a command-line string
  25. &numArgs // receives the argument count
  26. );
  27. for(int i=0;i<numArgs;i++)
  28. {
  29. MessageBox(NULL,argv[i],TEXT("argv"),MB_OK);
  30. }
  31. LocalFree(argv);
  32. return 0;
  33. }
  34. /*
  35. LPWSTR *szArglist;
  36. int nArgs;
  37. int i;
  38. szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
  39. if( NULL == szArglist )
  40. {
  41. wprintf(L"CommandLineToArgvW failed\n");
  42. return 0;
  43. }
  44. else for( i=0; i<nArgs; i++) printf("%d: %ws\n", i, szArglist[i]);
  45. // Free memory allocated for CommandLineToArgvW arguments.
  46. LocalFree(szArglist);
  47. */

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/467184
推荐阅读
相关标签
  

闽ICP备14008679号