我在一個空白項目(visual studio)中使用了一些代碼,它使用Windows.h 我想將這個程序放入我的C++ windows窗體應用程序中。 所以我爲它做了一堂課。奇怪的是代碼給我一個錯誤Windows.h在Windows窗體中的行爲不同於C++
#include "ImageCompiler.h"
ImageCompiler::ImageCompiler()
{
}
void ImageCompiler::find_images()
{
}
std::vector<string> ImageCompiler::get_all_files_names_within_folder(string folder)
{
std::vector<std::string> names;
std::string search_path = folder + "/*.*";
WIN32_FIND_DATA fd;
HANDLE hFind = ::FindFirstFile(search_path.c_str(), &fd);
if (hFind != INVALID_HANDLE_VALUE) {
do {
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
names.push_back(fd.cFileName);
}
} while (::FindNextFile(hFind, &fd));
::FindClose(hFind);
}
return names;
}
它說,SEARCH_PATH(爲const char *)不匹配參數(LPCWSTR) 沒有什麼特別在頭文件(只#包括WINDOWS.H) 和其他一些課堂事物。
如果我創建一個空的程序只有windows.h和這個代碼它將工作。 ,但不在Windows窗體應用程序中,即使它在另一個文件中,也不在 之間。我不明白這一點。 我其實很愚蠢和糟糕的編程,所以它可能是一個愚蠢的 錯誤。我希望有一個人可以幫助我。我可以給你從 Myform.h的代碼,但我不認爲這會有所幫助。
UNICODE總是在C++/CLI #define的應用程序。使用std :: wstring或FindFirstFileA()或System :: IO :: Directory :: GetFiles() –
如果您使用的是.Net,您應該避免直接在任何情況下使用Win API。 – Clifford
.Net?贏得API我不知道這兩個。 – JamesT