问题标签 [lpcwstr]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
7249 浏览

c++ - LPCWSTR 到 char* 反之亦然

我正在使用 DirectX9 开发一个简单的项目。我在一些数据类型的转换上遇到了一些麻烦,我做了一些研究,但没有发现任何特别有用的东西。让我们从代码开始:

在第 6 行,我收到变量文件名的错误:

IntelliSense:“char *”类型的参数与“LPCWSTR”类型的参数不兼容

尝试使用 MessageBox 时,我还在第二个和第三个参数处得到完全相同的错误消息:

我以前使用过完全一样的代码并且没有问题。不知道发生了什么 - 特别是因为 LPCWSTR 和 char* 本质上是同一件事......

任何帮助表示赞赏!谢谢

0 投票
1 回答
923 浏览

winapi - 将 wstringstream 转换为 LPCWSTR

我是 Winapi 的初学者,我正在尝试像这样(在 WM_PAINT 内部)将 wstringstream 转换为 LPCWSTR:

它只会产生垃圾,有人可以帮忙吗?谢谢你。

0 投票
1 回答
346 浏览

c++ - 如何转换 LPCWSTR 和 char?

它显示了 char* 无法转换为 LPCWSTR 的错误。我该如何解决?

0 投票
1 回答
383 浏览

c++ - 如何使用 FindFirstFile

我不断收到底部行的编译错误

编译器不断抛出error C2664 back at me, : cannot convert argument 1 from 'const char *' to 'LPCWSTR'

如何将 LPCWSTR 创建到 std::string 以传递给 FindFirstFile?

这部分代码供参考。

实际代码如下。

0 投票
1 回答
946 浏览

c++ - C++ 如何使用保存在字符串中的文件路径创建带时间戳的目录?

我正在尝试设置一个程序,该程序可以在每次用于填充数据时创建一个新目录。我希望文件夹的名称是创建时间的时间戳。我已经编写了一个创建时间戳并将其作为字符串返回的函数。

这个位工作正常,并给了我一个带有当前时间戳的字符串。我还有第二个字符串,其中包含文件夹位置的路径,我将其结合起来以字符串形式给出完整路径和新文件夹名称,例如“C:\\Users\\Daniel\\Documents\\VS17\\25.5.2017- 16:47:51"

我知道我可以使用

当我有一个像我的字符串中保存的文件路径但采用 LPCWSTR 格式的文件路径时创建一个目录。所以我的问题是

  • 如何将我的字符串转换为 LPCWSTR 格式以在 CreateDirectory 中使用

  • 还有其他我只是想念的方式吗

0 投票
1 回答
79 浏览

c++ - '不能添加两个指针'添加 LPCWSTR 和 WCHAR

我声明了两个变量,例如:

第一个变量用于返回 SQLite 错误消息,第二个变量用于 MessageBox 文本。我尝试并编写了以下代码:

但类似这样的消息显示: ScreenShot

如果我删除 w_ErrorMessage 变量后面的 WCHAR,我会得到“错误:无法添加两个指针”。

我想要 MessageBox 显示错误:SQLite Error: %TheActualErrorMessage%。我怎样才能做到这一点?

0 投票
1 回答
340 浏览

c - 努力将 LPBYTE 转换为 char* 或 C 中的任何类似内容(中文输出?)

我有一个正在处理的 C 项目,但遇到了问题。该程序读取由 .php 页面回显的字符串。它使用此代码读取数据并将其指定给一个变量,该变量被发送到 Commands() 函数:

如您所见,数据被发送到 Commands() 函数,该函数接收 LPBYTE szBuffer(在函数中命名为“command”)和 DWORD dwRead(在函数中命名为“size”)。

在 Commands() 函数中,它应该读取从 .php 页面读取的字符串。但是,由于数据似乎存储为 LPBYTE,因此我做了很多事情试图将其转换为 char*。然而,当我认为我终于得到它时,我尝试使用 MessageBox 输出它(查看它是否显示它应该读取的字符串)。但是,这会返回我中文字符(而原始字符串应该是这样的:

"TASKci=0C73CCFD206BBD011E7087CE0806E6F6E69630,job=dlex,ti=AD62A5950B76F3812C542C24040EACE9,pr=https,ur=//test.com/test.txt,cl="。

它返回给我的截图:http: //prntscr.com/h0p5iw

Commands() 中的代码看起来如何:

我是 C 的新手(我以前只用 C# 写过东西),所以如果我问任何愚蠢的问题,我很抱歉,我真的尽力了,但我自己似乎找不到任何解决方案。

另外,请记住,除了Commands()函数内部的内容之外的所有内容都不是由我编写的,而是由更有经验的人编写的。该代码应该没问题,我确信它正在从页面读取数据,可能只是我在某处搞砸了转换。

0 投票
2 回答
192 浏览

c++ - 代码c ++ VS 2010中的LPCWSTR到字符串转换问题

我正在尝试查找具有特定名称的文件并在 C++ 中删除它们,因为如果我将直接桌面路径提供给它 L"path//",则此代码可以正常工作,但是由于不同的用户和系统,桌面的路径不同所以我是什么我在顶部做的是在字符串变量中获取桌面路径并分配它而不是直接路径。

我收到以下错误

错误 4 错误 C2664:“FindFirstFileW”:无法将参数 1 从“std::string”转换为“LPCWSTR”

我已经尝试过使用 wstring 和 wchar 但它再次给出错误。谁能帮我解决这个问题。在代码中寻找更正

0 投票
1 回答
40 浏览

c++ - c++ 在参数中将字符串转换为 LPCWSTR

我可以看到我可以在这样的参数中将字符串类型转换为 LPCWSTR:

但是假设这次我想将一个字符串作为变量传递,我将如何像上面那样轻松地转换它(不转换变量):

我尝试了一些方法,例如:

0 投票
1 回答
149 浏览

c++ - C++: Native to Managed String Conversion Problem (Maybe Character Set)?

I'm having a problem returning a native string in the correct character-set. I convert from a string to a wstring to an LPCWSTR to pass back to managed. For the string to wide-string, the s2ws method produces a very small string return because it seems to stop at my first would-be terminator (in managed), which is ';'. So, before you mention s2ws, I've alreday tried it to no avail.

String stuff:

Later string stuff:

How do I know it's a character set/encoding problem? Well, when the LPCWSTR is returned to managed and I use Marshal to Unicode string, I get a wall of null/empty characters. When I try it in ANSI, this is what I get (reduced in size/scale for readability):

ÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝ

The s2ws method is supposed to address the ANSI/UNICODE nightmare that is std::string->std::wstring but that makes the return far too short - far shorter than it should be - but doesn't address the actual charset problem.

Result (to ANSI, again - no reducing done on my part): ÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝ

When I check in native, wprintf_s shows me that the string is valid/good before the LPCWSTR conversion happens in the export method; so, I need to understand:

  1. Is there a way for me to tell what the byte size of the characters actually are? (I'm thinking that this is an 8byte versus 16byte scenario?)
  2. Since wprintf_s works on the wide string, I checked it against the LPCWSTR and it printed the same (expected) data; so, the issue doesn't appear to be in the .ctor() of the LPCWSTR. Yet, I want to double-check my maths: Am I LPCWSTR'ing correctly?
  3. Since everything in native is telling me that the string is good, how can I check it's character-set (in native)?

The return, itself, is about 8 lines of text, with a delimiter ';' used so that I can split the string in managed and do magic with it. The only issue is getting the string to render as a valid string in managed, with the correct characters in it.

I feel like, maybe, I'm missing something obvious here but I cannot figure out what it is and just need a fresh pair of eyes to tell me where and how I'm failing at life.