Windows unicode命令行argv [英] Windows unicode commandline argv

查看:210
本文介绍了Windows unicode命令行argv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以进入新的千年我重写了我的c ++代码:

So getting into the new millenia I rewrote my c++ code with:

int main(int argc, wchar_t **argv)

如果使用Unicode或MBCS选项构建,那么当应用程序使用命令行arg运行时,直接或通过dbl单击传递给argv []的文件名不可读=在一些中文字体的混合。

If built with either Unicode or MBCS options then when the app is run with a commandline arg, either directly or by dbl-click the filenames passed to argv[] are unreadable = in some mixture of chinese fonts.

感谢您的评论 - 我将尝试和summaris

Thanks for the comments - I will try and summaris(z)e them here for the search engine.


  1. wmain(int argc,char ** argv)

int winMain(int argc, wchar_t ** argv)适用于gui(子系统:windows),但gui将其替换为它自己的入口点。在Qt的情况下这不工作

int winMain(int argc, wchar_t **argv) works for a gui (subsystem:windows) but the gui replaces it with it's own entry point. In the case of Qt this doesn't work

qtmaind.lib(qtmain_win.obj):错误LNK2019:未解析的外部符号_main在函数_WinMain @ 16中引用

qtmaind.lib(qtmain_win.obj) : error LNK2019: unresolved external symbol _main referenced in function _WinMain@16

解决方法似乎是使用 main(int arc,char ** argv)
main(int argc,wchar_t ** argv)但忽略argv。然后用argv或NULL调用QApplication:argv被忽略,因为Qt在内部调用GetCommandLine()。

然后使用app.arguments返回解析的参数。

然后可以转换回到wchar与Qt的字符串函数,如果需要。

The solution seems to be use main(int arc,char **argv) or main(int argc,wchar_t**argv) but ignore the argv. Then call QApplication with argv or NULL - the argv is ignored as Qt internally calls GetCommandLine().
Then use app.arguments to return the parsed arguments.
These can then be converted back into wchar with Qt's string functions if needed.

 QApplication app(argc, (char**)argv);  or  QApplication app(argc,NULL);  
 QStringList args = app.arguments();

对不起,我原来没有标记这个Qt,因为我不认为这是相关的。 >
如果有人想编辑这也包括如何在MFC中这样做 - 请做。

Sorry I didn't originally flag this Qt because I didn't think that was relevant.
If somebody wants to edit this to also include how to do this in MFC - please do.

推荐答案

您需要命名您的入口点 wmain http://msdn.microsoft.com/en-us/library/fzc2cy7w(VS.80) .aspx

You need to name your entry point wmain: http://msdn.microsoft.com/en-us/library/fzc2cy7w(VS.80).aspx

这篇关于Windows unicode命令行argv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆