且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找不到C ++ StringCchPrintf标识符

更新时间:2023-11-17 10:51:22

奇怪。您的系统是否受支持?你有一个现代的编译器吗?

我刚编译了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.