Use Unicode and Hide the Console in Windows

 If one would like to make his program being able to accept the arguments which is not English, the Unicode is requisite. That would make your software be more international. ( For me, it is instinct to use Chinese as file name and so forth.)

 

   To use Unicode in windows, One could set your program as unicode in Visual Studio:

 

 

 

 

That your could use unicode in your code.

 

If your program arguments could be Chinese, the main should be the form:

 

 

int wmain(int argc, wchar_t *argv[]) 

 

 

in windows with unicode.

 

 

but, if you would like to hide console (for example, if you use Qt librarie with Visual Studio), the well-known solution :

 

 

#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")

 

 

would not work.

 

there would be :

 

 

error LNK2001: unresolved external symbol _main

 

 

To solve it as valid is very tricky, that is :

 

 

#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:wmainCRTStartup")

 

 

To demostrate i, the code be :

 

 

#include <windows.h>

#include <locale.h>
#include <wchar.h>



#ifndef _DEBUG
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:wmainCRTStartup")
#endif

int wmain(int argc, wchar_t *argv[]) 
{
 int k;
 
 k = 1;
 while(k < argc)
 { 
  wchar_t bufferW[256];
  memset(&bufferW[0], 0, 256*sizeof(wchar_t));
  wcsncpy(&bufferW[0], argv[k], 256);  

#ifdef _DEBUG  
  setlocale(LC_ALL, "");
  wprintf(TEXT("%s\n"), &bufferW[0]);
  
#else
  MessageBox(NULL, &bufferW[0], TEXT("參數"), MB_OK);
#endif
  k++;
 }/*while*/

 return 0;
}/*wmain*/

 

 

and set the input argument as :

 

 

 

(Of course, do not forget set the character set as Unicode in the configuration properties -> General)

 

In the debug mode, the output would be in the console :

 

 

 

In the release mode, the console would be hidden, and the output be :

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值