Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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:

C++
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
C++
<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
Posted
Comments
Richard MacCutchan 21-Aug-15 12:13pm    
Are you sure you #included strsafe.h correctly?

1 solution

Strange. Is your system supported? Have you a modern compiler?
I've just compiled the example found in StringCchPrintf documentation, namely
XML
#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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900