1
- 我有一個區域設置爲韓國(韓文)
- 我創建了一個GDIPLUS C++包裝的圖像壓縮(PNG,JPG Windows上運行遺留應用程序失敗等)在舊版應用程序中使用。
- 該應用程序有2個進程A和B.進程B是A的子進程。
- 進程B生成一個位圖並通過包裝壓縮它:Bitmap-> Save(Hangul-file-name.png)。
- 進程A嘗試打開Hangul-file-name.png並失敗,錯誤代碼爲123(卷,路徑或文件名無效)。
- 什麼是使用Bitmap-> Save()使WIN API成功創建Hangul-file-name.png的WIN API?我會認爲 Bitmap-> Save()最終必須調用CreateFile()?
- 是否有任何可以添加到CreateFile()的標誌來解決此問題?
// 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;
}
這兩個程序很可能使用不同的文件名。進程監視器會告訴你有什麼區別,這可能會幫助你找出原因。 http://technet.microsoft.com/en-us/sysinternals/bb896645 – 2012-02-14 22:12:17