1

I have a piece of code to run on Windows that uses char const for a filename:

 char const * filename
 _finddata_t fi;
 intptr_t n;
 if ((n = _findfirst(filename, &fi)) != -1) {
   _findclose(n);
   return TRUE;
 }

Now I want this to use this code using const wchar_t for a filename (it should still run on Windows). I would assume this would be the way to do (see below). But in the description of _wfindclose it says _wfindclose is only usable for Win NT. Since one should use _wfindclose() to close the handle: **How do I close the handle in Win64? **

 wchar_t const * filename
 _wfinddata_t fi;
 intptr_t n;
 if ((n = _wfindfirst(filename, &fi)) != -1) {
   _wfindclose(n);
   return TRUE;
 }

enter image description here

user3443063
  • 1,455
  • 4
  • 23
  • 37
  • 1
    `_findclose` requires only an argument of type `intptr_t`. Nothing related to text formats, so you should be able to use it (no need for a `'w'` "flavor"). – wohlstad Oct 10 '22 at 16:04
  • 2
    Another option would be to use [std::filesystem::directory_iterator](https://en.cppreference.com/w/cpp/filesystem/directory_iterator) – BoP Oct 10 '22 at 16:15

1 Answers1

2

Looks like you're missing a library. No matter.

If you #include <windows.h> you can drop it.

_finddata_t is WIN32_FIND_DATAA
_wfinddata_t is WIN32_FIND_DATAW
_findfirst is FindFirstFileA
_wfindfirst is FindFirstFileW
??? is FindNextFileA
??? is FindNextFileW
_findclose is FindClose
_wfindclose is FindClose

With a library as silly as this one I recommend dropping it. A better abstraction can finally be written if you really case.

Joshua
  • 40,822
  • 8
  • 72
  • 132