V
V
vvafree2016-07-26 16:54:07
C++ / C#
vvafree, 2016-07-26 16:54:07

What is the correct way to set the filename for FIndFIrstFile(c++)?

Good afternoon. I can't run the FindFirstFile example.

#include "stdafx.h"
#include <windows.h>
#include <iostream>

using namespace std;


void main()
{
  WIN32_FIND_DATA FindFileData;
  HANDLE hf;
  hf = FindFirstFile("//*.jpg", &FindFileData);
  if (hf != INVALID_HANDLE_VALUE)
  {
    do
    {
      cout << FindFileData.cFileName << endl;
    } while (FindNextFile(hf, &FindFileData) != 0);
    FindClose(hf);
  }
}

Writes error:
Error C2664 "HANDLE FindFirstFileW(LPCWSTR,LPWIN32_FIND_DATAW)": cannot convert argument 1 from "const char [4]" to "LPCWSTR" findfile c:\c++\2\findfile\findfile\findfile.cpp 21

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2016-07-26
@vvafree

LPCWSTR - Long Pointer to Constant Wide STRing
hf = FindFirstFile(L"//*.jpg", &FindFileData);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question