- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这有点烦人。我尝试将参数从 NPAPI
插件传递到 EXE。
第一条信息:可执行文件当前是一个占位符,仅将传递的参数作为消息框打印出来:
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {
/* Print out the arguments */
MessageBox(NULL, lpCmdLine, TEXT("World of RPG"), NULL);
/* Exit with return code 0x00 */
return 0;
}
当我尝试通过 Visual Studio 启动应用程序时(以参数“-console”启动),消息框将正确提示:
然而,我尝试从我的 NPAPI
插件执行可执行文件:
/* Javascript call: document.getElementById("myPlugin").startGame("-console"); */
std::string WoRPGAPI::startGame(const std::string& method_args) {
/* Define JSON result variables */
FB::VariantMap json;
Json::StyledWriter writer;
/* Define process variables*/
PROCESS_INFORMATION processInformation = { 0 };
STARTUPINFO startupInfo = { 0 };
startupInfo.cb = sizeof(startupInfo);
LPWSTR game_exe = LgetGamePath("World of RPG.exe").c_str(); // example: "C:\\Program Files (x86)\\World of RPG\\World of RPG.exe"
LPWSTR game_args = method_args.c_str(); // example: "-console"
/* Create the Process */
BOOL status = CreateProcess(game_exe, game_args, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInformation);
/* Check the process status */
if (!status) {
DWORD dLastError = GetLastError();
LPCTSTR strErrorMessage = NULL;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, dLastError, 0, (LPWSTR)&strErrorMessage, 0, NULL);
json["code"] = dLastError;
json["message"] = strErrorMessage;
}
json["status"] = status;
/* get JSON back to the browser */
return writer.write(FB::variantToJsonValue(json));
}
结果如下:
好的,尝试使用 startGame("This is a longer string!")
测试更长的字符串。你看,只有第一个词会被截断。我已经尝试了 30 多分钟来解决这个问题:
你能告诉我,我做错了什么吗?我已经尝试了很多转换示例来将 std::string
转换为 LPWSTR
但没有任何效果。其他方法给了我像汉字这样的神秘输出。
最佳答案
MessageBox
函数接受两个正确输入为 LPCTSTR
的参数。假设 unicode 等于 LPCWSTR
或 wchar_t const *
。std::string
。它基于 char
,您到处都需要基于 wchar_t
的字符串。std::wstring
基于 wchar_t
,因此您想使用它。MessageBox
将接受 std::wstring::c_str()
的结果而不进行转换。请注意,您代码中的许多转换都是不必要的。让我们开始:
/* convert/cast LPTSTR to LPCWSTR */
LPCWSTR test = (LPCWSTR) lpCmdLine;
LPCWSTR
是 wchar_t const *
如果你设置了 unicode(就像你看起来那样),LCTSTR
是 wchar_t *
。添加 const
是 C++ 中的隐式转换。所以
test = lpCmdLine;
会做同样的事情。没有选择 unicode 的错误风险,在这种情况下 LCTSTR
扩展为 char *
并且语句将失败并出现“无法转换为不兼容的指针类型”错误。通过强制转换,它可以编译,但由于 C 风格的强制转换会重新解释强制转换,即将内存内容视为请求的类型,因此结果是垃圾。
现在我不明白的是:
BOOL status = CreateProcess((LPWSTR) LgetGamePath("World of RPG.exe").c_str(), game_args, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInformation);
函数LgetGamePath
获取一个窄字符串(宽字面量有L
前缀,也可以用TEXT()
宏生成) , 所以我希望它返回一个 narrow 字符串(你似乎没有显示那个签名,所以我不确定)。现在你盲目地把它转换到宽,这会产生垃圾,它不应该能够启动这个过程。另一方面,只要字符串仅为 ASCII,参数的转换实际上似乎是正确的。
1对于可移植程序,wchar_t
仍然是一团糟,因为它在某些平台上是 4 个字节,而在其他平台上是 2 个字节(包括急切创建宽的窗口)当 2 个字节足够时所有接口(interface)的版本,当 Unicode 超过它时卡在 2 个字节)。至少对于输入和输出,您通常需要特定的编码,通常是 Utf-8(因为它向后兼容 ASCII,但 Windows 不支持它)。很多人,包括我,在编写可移植程序时只是准备转换函数以在某处调用系统接口(interface)并在 Utf-8(例如 Gtk)或 Utf-16(存储在 uint16_t
,而不是 wchar_t
,就像 Qt 或 ICU 一样)在内部。
关于c++ - 传递参数(将 std::string 转换为 LPWSTR 的概率),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23591748/
我正在尝试将一个字符串逐个字符地复制到另一个字符串中。目的不是复制整个字符串,而是复制其中的一部分(我稍后会为此做一些条件......) 但我不知道如何使用迭代器。 你能帮帮我吗? std::stri
我想将 void 指针转换为结构引用。 结构的最小示例: #include "Interface.h" class Foo { public: Foo() : mAddress((uint
这有点烦人:我有一个 div,它从窗口的左上角开始过渡,即使它位于文档的其他任何位置。我试过 usign -webkit-transform-origin 但没有成功,也许我用错了。有人可以帮助我吗?
假设,如果将 CSS3 转换/转换/动画分配给 DOM 元素,我是否可以检测到该过程的状态? 我想这样做的原因是因为我正在寻找类似过渡链的东西,例如,在前一个过渡之后运行一个过渡。 最佳答案 我在 h
最近我遇到了“不稳定”屏幕,这很可能是由 CSS 转换引起的。事实上,它只发生在 Chrome 浏览器 上(可能还有 Safari,因为一些人也报告了它)。知道如何让它看起来光滑吗?此外,您可能会注意
我正在开发一个简单的 slider ,它使用 CSS 过渡来为幻灯片设置动画。我用一些基本样式和一些 javascript 创建了一支笔 here .注意:由于 Codepen 使用 Prefixfr
我正在使用以下代码返回 IList: public IList FindCodesByCountry(string country) { var query =
如何设计像这样的操作: 计算 转化 翻译 例如:从“EUR”转换为“CNY”金额“100”。 这是 /convert?from=EUR&to=CNY&amount=100 RESTful 吗? 最佳答
我使用 jquery 组合了一个图像滚动器,如下所示 function rotateImages(whichHolder, start) { var images = $('#' +which
如何使用 CSS (-moz-transform) 更改一个如下所示的 div: 最佳答案 你可以看看Mozilla Developer Center .甚至还有例子。 但是,在我看来,您的具体示例不
我需要帮助我正在尝试在选中和未选中的汉堡菜单上实现动画。我能够为菜单设置动画,但我不知道如何在转换为 0 时为左菜单动画设置动画 &__menu { transform: translateX(
我正在为字典格式之间的转换而苦苦挣扎:我正在尝试将下面的项目数组转换为下面的结果数组。本质上是通过在项目第一个元素中查找重复项,然后仅在第一个参数不同时才将文件添加到结果集中。 var items:[
如果我有两个定义相同的结构,那么在它们之间进行转换的最佳方式是什么? struct A { int i; float f; }; struct B { int i; float f; }; void
我编写了一个 javascript 代码,可以将视口(viewport)从一个链接滑动到另一个链接。基本上一切正常,你怎么能在那里看到http://jsfiddle.net/DruwJ/8/ 我现在的
我需要将文件上传到 meteor ,对其进行一些图像处理(必要时进行图像转换,从图像生成缩略图),然后将其存储在外部图像存储服务器(s3)中。这应该尽可能快。 您对 nodejs 图像处理库有什么建议
刚开始接触KDB+,有一些问题很难从Q for Mortals中得到。 说,这里 http://code.kx.com/wiki/JB:QforMortals2/casting_and_enumera
我在这里的一个项目中使用 JSF 1.2 和 IceFaces 1.8。 我有一个页面,它基本上是一大堆浮点数字段的大编辑网格。这是通过 inputText 实现的页面上的字段指向具有原始值的值对象
ScnMatrix4 是一个 4x4 矩阵。我的问题是什么矩阵行对应于位置(ScnVector3),旋转(ScnVector4),比例(ScnVector3)。第 4 行是空的吗? 编辑: 我玩弄了
恐怕我是 Scala 新手: 我正在尝试根据一些简单的逻辑将 Map 转换为新 Map: val postVals = Map("test" -> "testing1", "test2" -> "te
输入: This is sample 1 This is sample 2 输出: ~COLOR~[Green]This is sample 1~COLOR~[Red]This is sam
我是一名优秀的程序员,十分优秀!