找不到C ++ StringCchPrintf标识符 [英] C++ StringCchPrintf identifier not found
问题描述
所以,我对C ++很新,我正在尝试获取目录中的文件列表。我在这里找到了微软的解决方案:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365200(v = vs.85).aspx [ ^ ]
但是当我去构建它时我收到一个错误:
错误C3861:'StringCchPrintf' :找不到标识符
错误来自代码的这一部分:
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf)/ sizeof (TCHAR),
TEXT( %s失败,错误%d:%s),
lpszFunction,dw,lpMsgBuf);
MessageBox(NULL,(LPCTSTR)lpDisplayBuf,TEXT( 错误),MB_OK) ;
StringCchPrintf位于
< strsafe.h>
,我搜索过strsafe.h ,但我不知道问题是什么。它似乎是定义的。
如果有人可以帮我这个会很棒。
谢谢,
Mitch
奇怪。您的系统是否受支持?你有一个现代的编译器吗?
我刚编译了StringCchPrintf文档中的例子,即
#include < Windows.h >
#include < strsafe.h >
int main()
{
TCHAR pszDest [30];
size_t cchDest = 30;
LPCTSTR pszFormat = TEXT(%s%d +%d =%d。);
TCHAR * pszTxt = TEXT(答案是);
HRESULT hr = StringCchPrintf(pszDest,cchDest,pszFormat,pszTxt,1,2,3);
}
在使用Visual Studio 2012的Windows 8,64位系统上没有问题。
So, I am fairly new to C++ and I am trying to get a list of files in a directory. I found a solution from microsoft here:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365200(v=vs.85).aspx[^]
but when I go to build it I get an error:
error C3861: 'StringCchPrintf': identifier not found
The error is from this section of the code:
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("%s failed with error %d: %s"),
lpszFunction, dw, lpMsgBuf);
MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
StringCchPrintf is in
<strsafe.h>
and I have searched strsafe.h, but I dont know what the problem is. It appears to be defined.
If anyone could help me with this that would be great.
Thanks,
Mitch
Strange. Is your system supported? Have you a modern compiler?
I've just compiled the example found in StringCchPrintf documentation, namely
#include <Windows.h> #include <strsafe.h> int main() { TCHAR pszDest[30]; size_t cchDest = 30; LPCTSTR pszFormat = TEXT("%s %d + %d = %d."); TCHAR* pszTxt = TEXT("The answer is"); HRESULT hr = StringCchPrintf(pszDest, cchDest, pszFormat, pszTxt, 1, 2, 3); }
without problems on my Windows 8, 64 bit system, using Visual Studio 2012.
这篇关于找不到C ++ StringCchPrintf标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!