C++ How to _wfindfirst and _wfindclose on Win64 Win32

174 Views Asked by At

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

1

There are 1 best solutions below

0
Joshua On

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.