CreateFile on Windows set to East Asian Locale
-
Tuesday, February 14, 2012 12:55 PM
1. I have a legacy application running on Windows with locale set to Korea (Hangul)
2. I created a GDIPLUS C++ wrapper for image compression (png, jpg,etc) to use in the legacy App.
3. The application has 2 processes A and B. Process B is a child of A.
4. Process B generates a bitmap and compresses it via the wrapper: Bitmap->Save(Hangul-file-name.png).
5. Process A attempts to open Hangul-file-name.png and fails with error code 123 (volume, path or filename invalid).
6. What is the WIN API used by Bitmap->Save() that enables it to successfully create Hangul-file-name.png? I would think
that the Bitmap->Save() must eventually call CreateFile()??
7. Are there any flags I can add to the CreateFile() that would resolve this problem?
// Called from legacy application.
// pszFileName - contains a DBCS ANSI Hangul path name "자동연결기능수행_(perform_autolink_functions)_ffbd" volume info left out.
BOOL SavePng(char * pszFileName, HBITMAP bmhandle, HPALETTE palette, int quality)
{
if(pszFileName == NULL)
return FALSE;
// Convert the smalltalk DBCS ANSI string to unicode.
int slength = strlen(pszFileName);
wchar_t *uFilename = new wchar_t[slength + 1];
uFilename[slength] = L'\0';
MultiByteToWideChar(CP_ACP, 0, pszFileName, -1, uFilename, slength);BOOL result = SaveImage(uFilename, L"image/png", bmhandle, palette, quality);
delete uFilename;
return result;
}// Create a compressed image file
BOOL SaveImage(LPCWSTR pszFileName, LPCWSTR encoding, HBITMAP bmhandle, HPALETTE palette, int quality)
{
CLSID encoderClsid;
if( GetEncoderClsid(encoding, &encoderClsid) > 0)
{
EncoderParameters encoderParameters;
encoderParameters.Count = 1;
encoderParameters.Parameter[0].Guid = EncoderQuality;
encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
encoderParameters.Parameter[0].NumberOfValues = 1;
encoderParameters.Parameter[0].Value = &quality;
Bitmap* bm = new Bitmap(bmhandle, palette);
bm->Save(pszFileName,&encoderClsid, &encoderParameters);
delete bm;
return TRUE;
}
return FALSE;
}// Attempt to open file for reading
// pszFileName: "C:\CORE2net80\users\Administrator\자동연결기능수행_(perform_autolink_functions).png" (sample)
HANDLE OpenReadOnly(char * pszFileName)
{
// Convert the smalltalk DBCS ansi string to unicode.
int slength = strlen(pszFileName);int lenw = MultiByteToWideChar(CP_ACP, 0, pszFileName, slength, 0, 0);
if(lenw > 0)
{
wchar_t *uFilename = new wchar_t[lenw + 1];
uFilename[lenw] = L'\0';MultiByteToWideChar(CP_ACP, 0, pszFileName, slength, uFilename, lenw);
HANDLE h = CreateFile(uFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if( h == INVALID_HANDLE_VALUE)
{
DWORD en = GetLastError(); // Error 123 (volume, path or filename invalid)
return 0;
}
return h;
}
return 0;
}
All Replies
-
Tuesday, February 14, 2012 7:20 PM
I would suggest you check what is in uFileName after you converted it.
This is a signature
Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.


