FindFirstFile error in compilation [modified]
-
Hi, Having a little trouble with FindFirst File function.... heres what ive got... include "stdafx.h" #include #include //#include "dirent.h" #include #include #include #include #define WIN32_LEAN_AND_MEAN #include #include #include #pragma comment(lib,"ws2_32") using namespace std; // Stuff....... char fileFound[256]; strcpy(fileFound, path1); WIN32_FIND_DATA FindFileData; HANDLE hp; hp = FindFirstFile(fileFound, &FindFileData); printf ("The first file found is %s\n", FindFileData.cFileName); FindClose(hp); The error i recieve is... error C2664: 'FindFirstFileW' : cannot convert parameter 1 from 'char [256]' to 'LPCWSTR' I know sometimes when compiling the error is not always what it seeems.. but have no idea.. Please help. TIA -- modified at 7:45 Saturday 3rd June, 2006
-
Hi, Having a little trouble with FindFirst File function.... heres what ive got... include "stdafx.h" #include #include //#include "dirent.h" #include #include #include #include #define WIN32_LEAN_AND_MEAN #include #include #include #pragma comment(lib,"ws2_32") using namespace std; // Stuff....... char fileFound[256]; strcpy(fileFound, path1); WIN32_FIND_DATA FindFileData; HANDLE hp; hp = FindFirstFile(fileFound, &FindFileData); printf ("The first file found is %s\n", FindFileData.cFileName); FindClose(hp); The error i recieve is... error C2664: 'FindFirstFileW' : cannot convert parameter 1 from 'char [256]' to 'LPCWSTR' I know sometimes when compiling the error is not always what it seeems.. but have no idea.. Please help. TIA -- modified at 7:45 Saturday 3rd June, 2006
can you tell me what type of application are you working on? MFC , Console or On something else because I tried executing your code in MFC application and apart from a very minor change I was able to get the result. Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_
-
can you tell me what type of application are you working on? MFC , Console or On something else because I tried executing your code in MFC application and apart from a very minor change I was able to get the result. Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_
Hi, Im using Visual Studio 2005 but ive figured that part out via searching long and hard on the web... however im stuck with another problem just the same.... heres what i got for that part.... std::wstring s2ws(const std::string& s){ int len; int slength = (int)s.length() + 1; len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); wchar_t* buf = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len); std::wstring r(buf); delete[] buf; return r; } #ifdef UNICODE std::wstring stemp = s2ws(ipp); // Temporary buffer is required LPCWSTR result = stemp.c_str(); #endif WIN32_FIND_DATA FindFileData; HANDLE hFind = INVALID_HANDLE_VALUE; char DirSpec[MAX_PATH + 1]; // directory specification DWORD dwError; hFind = FindFirstFile(result, &FindFileData); printf ("First file name is %s\n", FindFileData.cFileName); My problem is i cant seem to get the FindFileData function to return a readable string... but i need FindFileData to be string s; for example...
-
Hi, Im using Visual Studio 2005 but ive figured that part out via searching long and hard on the web... however im stuck with another problem just the same.... heres what i got for that part.... std::wstring s2ws(const std::string& s){ int len; int slength = (int)s.length() + 1; len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); wchar_t* buf = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len); std::wstring r(buf); delete[] buf; return r; } #ifdef UNICODE std::wstring stemp = s2ws(ipp); // Temporary buffer is required LPCWSTR result = stemp.c_str(); #endif WIN32_FIND_DATA FindFileData; HANDLE hFind = INVALID_HANDLE_VALUE; char DirSpec[MAX_PATH + 1]; // directory specification DWORD dwError; hFind = FindFirstFile(result, &FindFileData); printf ("First file name is %s\n", FindFileData.cFileName); My problem is i cant seem to get the FindFileData function to return a readable string... but i need FindFileData to be string s; for example...
Should get it now. strcat(result,"\0"); hFind=FindFirstFile(result,&FindFileData); Do you get the name of the file or not? Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_
-
Should get it now. strcat(result,"\0"); hFind=FindFirstFile(result,&FindFileData); Do you get the name of the file or not? Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_
//ok i fixed part of it but still need to get std::string out of it... //here is what should be a compilable version of the code fragment... #include #include #include std::wstring s2ws(const std::string& s){ int len; int slength = (int)s.length() + 1; len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); wchar_t* buf = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len); std::wstring r(buf); delete[] buf; return r; } int main(){ string ipp="c:\\"; #ifdef UNICODE std::wstring stemp = s2ws(ipp); // Temporary buffer is required LPCWSTR result = stemp.c_str(); #endif WIN32_FIND_DATA FindFileData; HANDLE hFind = INVALID_HANDLE_VALUE; char DirSpec[MAX_PATH + 1]; // directory specification DWORD dwError; hFind = FindFirstFile(result, &FindFileData); printf ("First file name is %s\n", FindFileData.cFileName); } //The Return is fine i get First file name is . //which is what i think im looking for... however //I still to need to get the string instead of the printed .
-
//ok i fixed part of it but still need to get std::string out of it... //here is what should be a compilable version of the code fragment... #include #include #include std::wstring s2ws(const std::string& s){ int len; int slength = (int)s.length() + 1; len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); wchar_t* buf = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len); std::wstring r(buf); delete[] buf; return r; } int main(){ string ipp="c:\\"; #ifdef UNICODE std::wstring stemp = s2ws(ipp); // Temporary buffer is required LPCWSTR result = stemp.c_str(); #endif WIN32_FIND_DATA FindFileData; HANDLE hFind = INVALID_HANDLE_VALUE; char DirSpec[MAX_PATH + 1]; // directory specification DWORD dwError; hFind = FindFirstFile(result, &FindFileData); printf ("First file name is %s\n", FindFileData.cFileName); } //The Return is fine i get First file name is . //which is what i think im looking for... however //I still to need to get the string instead of the printed .
what string do you need . The filename is in FindFileData.cFileName Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_
-
what string do you need . The filename is in FindFileData.cFileName Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_
heres all i could come up with with the find filedata... string s; s=(FindFileData.cFileName); cout << s; no luck.. error C2679: binary '=' : no operator found which takes a right-hand operand of type 'WCHAR [260]' (or there is no acceptable conversion)
-
heres all i could come up with with the find filedata... string s; s=(FindFileData.cFileName); cout << s; no luck.. error C2679: binary '=' : no operator found which takes a right-hand operand of type 'WCHAR [260]' (or there is no acceptable conversion)
char *s=new char[255]; strcpy(s,FindFileData.cFileName); cout<_AnShUmAn_
-
heres all i could come up with with the find filedata... string s; s=(FindFileData.cFileName); cout << s; no luck.. error C2679: binary '=' : no operator found which takes a right-hand operand of type 'WCHAR [260]' (or there is no acceptable conversion)
std::string stores char. You need to use std::wstring to store wchar_t. You probably need to read up on unicode. If it's not your intention to use unicode set your project to use multibyte character strings instead.
-
std::string stores char. You need to use std::wstring to store wchar_t. You probably need to read up on unicode. If it's not your intention to use unicode set your project to use multibyte character strings instead.
strcpy not working... researching info for converting wstring to string.... no luck yet...
-
strcpy not working... researching info for converting wstring to string.... no luck yet...
found it... wstring s= s; string ssss; s=FindFileData.cFileName; ssss.assign(s.begin(), s.end()); cout << ssss; Thnx for your help
-
found it... wstring s= s; string ssss; s=FindFileData.cFileName; ssss.assign(s.begin(), s.end()); cout << ssss; Thnx for your help
But then the question you should ask yourself is this. Why are you building a unicode application in the first place?
-
Hi, Having a little trouble with FindFirst File function.... heres what ive got... include "stdafx.h" #include #include //#include "dirent.h" #include #include #include #include #define WIN32_LEAN_AND_MEAN #include #include #include #pragma comment(lib,"ws2_32") using namespace std; // Stuff....... char fileFound[256]; strcpy(fileFound, path1); WIN32_FIND_DATA FindFileData; HANDLE hp; hp = FindFirstFile(fileFound, &FindFileData); printf ("The first file found is %s\n", FindFileData.cFileName); FindClose(hp); The error i recieve is... error C2664: 'FindFirstFileW' : cannot convert parameter 1 from 'char [256]' to 'LPCWSTR' I know sometimes when compiling the error is not always what it seeems.. but have no idea.. Please help. TIA -- modified at 7:45 Saturday 3rd June, 2006
your Character set is Unicode Character Set
LPTSTR lpc; lpc=(LPTSTR)LocalAlloc(LPTR,256); wsprintf(lpc,_T("%s"), _T("c:\\code.txt")); WIN32_FIND_DATA FindFileData; HANDLE hp; hp = FindFirstFile(lpc, &FindFileData); LocalFree(lpc);
_**
**_
whitesky