int _cdecl LCSort(const void *el1,const void *el2) { char Str1[]={*reinterpret_cast<const char*>(el1),L'\0'}, Str2[]={*reinterpret_cast<const char*>(el2),L'\0'}; OemToCharBuffA(Str1,Str1,1); OemToCharBuffA(Str2,Str2,1); return(CompareStringA(Opt.LCIDSort,NORM_IGNORENONSPACE|SORT_STRINGSORT|NORM_IGNORECASE,Str1,1,Str2,1)-2); }
ZIPINLINE void ZipPlatform::AnsiOem(CZipAutoBuffer& buffer, bool bAnsiToOem) { if (bAnsiToOem) CharToOemBuffA(buffer, buffer, buffer.GetSize()); else OemToCharBuffA(buffer, buffer, buffer.GetSize()); }
int WINAPI LocalIsalphanum(unsigned Ch) { if (Ch>=256) return FALSE; char CvtCh=Ch; OemToCharBuffA(&CvtCh,&CvtCh,1); return(IsCharAlphaNumericA(CvtCh)); }
const CHAR CConvOem::fromOemA(const CHAR chSrc) { if (m_blInvalidBuff) { SetLastError(ERROR_INVALID_ADDRESS); return EOF; } OemToCharBuffA(&chSrc, m_szBuff, 1); return *m_szBuff; }
void IntToExt(const char *Src,char *Dest,size_t DestSize) { #ifdef _WIN_ALL // OemToCharBuff does not stop at 0, so let's check source length. size_t SrcLength=strlen(Src)+1; if (DestSize>SrcLength) DestSize=SrcLength; OemToCharBuffA(Src,Dest,(DWORD)DestSize); Dest[DestSize-1]=0; #else if (Dest!=Src) strncpyz(Dest,Src,DestSize); #endif }
void IntToExt(const char *Src,char *Dest,size_t DestSize) { #ifdef _WIN_ALL OemToCharBuffA(Src,Dest,(DWORD)DestSize); Dest[DestSize-1]=0; #elif defined(_ANDROID) wchar DestW[NM]; JniCharToWide(Src,DestW,ASIZE(DestW),true); WideToChar(DestW,Dest,DestSize); #else if (Dest!=Src) strncpyz(Dest,Src,DestSize); #endif }
void IntToExt(const char *Src,char *Dest,size_t DestSize) { #ifdef _WIN_ALL // OemToCharBuff does not stop at 0, so let's check source length. size_t SrcLength=strlen(Src)+1; if (DestSize>SrcLength) DestSize=SrcLength; OemToCharBuffA(Src,Dest,(DWORD)DestSize); Dest[DestSize-1]=0; //#elif defined(_ANDROID) // wchar DestW[NM]; // JniCharToWide(Src,DestW,ASIZE(DestW),true); // WideToChar(DestW,Dest,DestSize); #else if (Dest!=Src) strncpyz(Dest,Src,DestSize); #endif }
ZIPINLINE void ZipPlatform::AnsiOem(CZipAutoBuffer& buffer, bool bAnsiToOem) { #ifdef _ZIP_SAFE_WINDOWS_API UINT cpIn, cpOut; if (bAnsiToOem) { cpIn = CP_ACP; cpOut = CP_OEMCP; } else { cpIn = CP_OEMCP; cpOut = CP_ACP; } CZipAutoBuffer interBuffer; int size = buffer.GetSize(); // iLen doesn't include terminating character int iLen = MultiByteToWideChar(cpIn, MB_PRECOMPOSED, buffer, size, NULL, 0); if (iLen <= 0) return; interBuffer.Allocate(iLen * sizeof(wchar_t)); LPWSTR lpszWide = (LPWSTR)(char*)interBuffer; iLen = MultiByteToWideChar(cpIn, MB_PRECOMPOSED, buffer, size, lpszWide, iLen); ASSERT(iLen != 0); // iLen does not include terminating character size = WideCharToMultiByte(cpOut, 0, lpszWide, iLen, NULL, 0, NULL, NULL); if (size <= 0) return; buffer.Allocate(size); size = WideCharToMultiByte(cpOut, 0, lpszWide, iLen, buffer, size, NULL, NULL); ASSERT(size != 0); #else if (bAnsiToOem) CharToOemBuffA(buffer, buffer, buffer.GetSize()); else OemToCharBuffA(buffer, buffer, buffer.GetSize()); #endif }
/*********************************************************************** * OemToAnsiBuff (KEYBOARD.135) */ void WINAPI OemToAnsiBuff16( LPCSTR s, LPSTR d, UINT16 len ) { if (len != 0) OemToCharBuffA( s, d, len ); }
HANDLE PASCAL RAROpenArchiveEx(struct RAROpenArchiveDataEx *r) { DataSet *Data=NULL; try { r->OpenResult=0; Data=new DataSet; Data->Cmd.DllError=0; Data->OpenMode=r->OpenMode; Data->Cmd.FileArgs.AddString(L"*"); char AnsiArcName[NM]; *AnsiArcName=0; if (r->ArcName!=NULL) { strncpyz(AnsiArcName,r->ArcName,ASIZE(AnsiArcName)); #ifdef _WIN_ALL if (!AreFileApisANSI()) { OemToCharBuffA(r->ArcName,AnsiArcName,ASIZE(AnsiArcName)); AnsiArcName[ASIZE(AnsiArcName)-1]=0; } #endif } wchar ArcName[NM]; GetWideName(AnsiArcName,r->ArcNameW,ArcName,ASIZE(ArcName)); Data->Cmd.AddArcName(ArcName); Data->Cmd.Overwrite=OVERWRITE_ALL; Data->Cmd.VersionControl=1; Data->Cmd.Callback=r->Callback; Data->Cmd.UserData=r->UserData; // Open shared mode is added by request of dll users, who need to // browse and unpack archives while downloading. Data->Cmd.OpenShared = true; if (!Data->Arc.Open(ArcName,FMF_OPENSHARED)) { r->OpenResult=ERAR_EOPEN; delete Data; return NULL; } if (!Data->Arc.IsArchive(false)) { if (Data->Cmd.DllError!=0) r->OpenResult=Data->Cmd.DllError; else { RAR_EXIT ErrCode=ErrHandler.GetErrorCode(); if (ErrCode!=RARX_SUCCESS && ErrCode!=RARX_WARNING) r->OpenResult=RarErrorToDll(ErrCode); else r->OpenResult=ERAR_BAD_ARCHIVE; } delete Data; return NULL; } r->Flags=0; if (Data->Arc.Volume) r->Flags|=0x01; if (Data->Arc.Locked) r->Flags|=0x04; if (Data->Arc.Solid) r->Flags|=0x08; if (Data->Arc.NewNumbering) r->Flags|=0x10; if (Data->Arc.Signed) r->Flags|=0x20; if (Data->Arc.Protected) r->Flags|=0x40; if (Data->Arc.Encrypted) r->Flags|=0x80; if (Data->Arc.FirstVolume) r->Flags|=0x100; Array<wchar> CmtDataW; if (r->CmtBufSize!=0 && Data->Arc.GetComment(&CmtDataW)) { Array<char> CmtData(CmtDataW.Size()*4+1); memset(&CmtData[0],0,CmtData.Size()); WideToChar(&CmtDataW[0],&CmtData[0],CmtData.Size()-1); size_t Size=strlen(&CmtData[0])+1; r->Flags|=2; r->CmtState=Size>r->CmtBufSize ? ERAR_SMALL_BUF:1; r->CmtSize=(uint)Min(Size,r->CmtBufSize); memcpy(r->CmtBuf,&CmtData[0],r->CmtSize-1); if (Size<=r->CmtBufSize) r->CmtBuf[r->CmtSize-1]=0; } else r->CmtState=r->CmtSize=0; Data->Extract.ExtractArchiveInit(Data->Arc); return (HANDLE)Data; } catch (RAR_EXIT ErrCode) { if (Data!=NULL && Data->Cmd.DllError!=0) r->OpenResult=Data->Cmd.DllError; else r->OpenResult=RarErrorToDll(ErrCode); if (Data != NULL) delete Data; return NULL; } catch (std::bad_alloc&) // Catch 'new' exception. { r->OpenResult=ERAR_NO_MEMORY; if (Data != NULL) delete Data; } return NULL; // To make compilers happy. }
bool Archive::GetComment(Array<wchar> *CmtData) { if (!MainComment) return false; SaveFilePos SavePos(*this); #ifndef SFX_MODULE ushort CmtLength; if (Format==RARFMT14) { Seek(SFXSize+SIZEOF_MAINHEAD14,SEEK_SET); CmtLength=GetByte(); CmtLength+=(GetByte()<<8); } else #endif { if (MainHead.CommentInHeader) { // Old style (RAR 2.9) archive comment embedded into the main // archive header. Seek(SFXSize+SIZEOF_MARKHEAD3+SIZEOF_MAINHEAD3,SEEK_SET); ReadHeader(); } else { // Current (RAR 3.0+) version of archive comment. Seek(GetStartPos(),SEEK_SET); return SearchSubBlock(SUBHEAD_TYPE_CMT)!=0 && ReadCommentData(CmtData); } #ifndef SFX_MODULE // Old style (RAR 2.9) comment header embedded into the main // archive header. if (BrokenHeader) { uiMsg(UIERROR_CMTBROKEN,FileName); return false; } CmtLength=CommHead.HeadSize-SIZEOF_COMMHEAD; #endif } #ifndef SFX_MODULE if (Format==RARFMT14 && MainHead.PackComment || Format!=RARFMT14 && CommHead.Method!=0x30) { if (Format!=RARFMT14 && (CommHead.UnpVer < 15 || CommHead.UnpVer > VER_UNPACK || CommHead.Method > 0x35)) return(false); ComprDataIO DataIO; DataIO.SetTestMode(true); uint UnpCmtLength; if (Format==RARFMT14) { #ifdef RAR_NOCRYPT return(false); #else UnpCmtLength=GetByte(); UnpCmtLength+=(GetByte()<<8); CmtLength-=2; DataIO.SetCmt13Encryption(); CommHead.UnpVer=15; #endif } else UnpCmtLength=CommHead.UnpSize; DataIO.SetFiles(this,NULL); DataIO.EnableShowProgress(false); DataIO.SetPackedSizeToRead(CmtLength); DataIO.UnpHash.Init(HASH_CRC32,1); Unpack CmtUnpack(&DataIO); CmtUnpack.Init(0x10000,false); CmtUnpack.SetDestSize(UnpCmtLength); CmtUnpack.DoUnpack(CommHead.UnpVer,false); if (Format!=RARFMT14 && (DataIO.UnpHash.GetCRC32()&0xffff)!=CommHead.CommCRC) { uiMsg(UIERROR_CMTBROKEN,FileName); return false; } else { byte *UnpData; size_t UnpDataSize; DataIO.GetUnpackedData(&UnpData,&UnpDataSize); #ifdef _WIN_ALL OemToCharBuffA((char *)UnpData,(char *)UnpData,(DWORD)UnpDataSize); #endif CmtData->Alloc(UnpDataSize+1); memset(CmtData->Addr(0),0,CmtData->Size()*sizeof(wchar)); CharToWide((char *)UnpData,CmtData->Addr(0),UnpDataSize); CmtData->Alloc(wcslen(CmtData->Addr(0))); } } else { Array<byte> CmtRaw(CmtLength); Read(&CmtRaw[0],CmtLength); if (Format!=RARFMT14 && CommHead.CommCRC!=(~CRC32(0xffffffff,&CmtRaw[0],CmtLength)&0xffff)) { uiMsg(UIERROR_CMTBROKEN,FileName); return false; } CmtData->Alloc(CmtLength+1); CmtRaw.Push(0); #ifdef _WIN_ALL OemToCharA((char *)&CmtRaw[0],(char *)&CmtRaw[0]); #endif CharToWide((char *)&CmtRaw[0],CmtData->Addr(0),CmtLength); CmtData->Alloc(wcslen(CmtData->Addr(0))); } #endif return CmtData->Size() > 0; }
bool Archive::GetComment(Array<byte> *CmtData,Array<wchar> *CmtDataW) { if (!MainComment) return(false); SaveFilePos SavePos(*this); #ifndef SFX_MODULE ushort CmtLength; if (OldFormat) { Seek(SFXSize+SIZEOF_OLDMHD,SEEK_SET); CmtLength=GetByte(); CmtLength+=(GetByte()<<8); } else #endif { if (NewMhd.Flags & MHD_COMMENT) { // Old style (RAR 2.9) archive comment embedded into the main // archive header. Seek(SFXSize+SIZEOF_MARKHEAD+SIZEOF_NEWMHD,SEEK_SET); ReadHeader(); } else { // Current (RAR 3.0+) version of archive comment. Seek(SFXSize+SIZEOF_MARKHEAD+NewMhd.HeadSize,SEEK_SET); return(SearchSubBlock(SUBHEAD_TYPE_CMT)!=0 && ReadCommentData(CmtData,CmtDataW)!=0); } #ifndef SFX_MODULE // Old style (RAR 2.9) comment header embedded into the main // archive header. if (CommHead.HeadCRC!=HeaderCRC) { Log(FileName,St(MLogCommHead)); Alarm(); return(false); } CmtLength=CommHead.HeadSize-SIZEOF_COMMHEAD; #endif } #ifndef SFX_MODULE if (OldFormat && (OldMhd.Flags & MHD_PACK_COMMENT) || !OldFormat && CommHead.Method!=0x30) { if (!OldFormat && (CommHead.UnpVer < 15 || CommHead.UnpVer > UNP_VER || CommHead.Method > 0x35)) return(false); ComprDataIO DataIO; Unpack Unpack(&DataIO); Unpack.Init(); DataIO.SetTestMode(true); uint UnpCmtLength; if (OldFormat) { #ifdef RAR_NOCRYPT return(false); #else UnpCmtLength=GetByte(); UnpCmtLength+=(GetByte()<<8); CmtLength-=2; DataIO.SetCmt13Encryption(); #endif } else UnpCmtLength=CommHead.UnpSize; DataIO.SetFiles(this,NULL); DataIO.EnableShowProgress(false); DataIO.SetPackedSizeToRead(CmtLength); Unpack.SetDestSize(UnpCmtLength); Unpack.DoUnpack(CommHead.UnpVer,false); if (!OldFormat && ((~DataIO.UnpFileCRC)&0xffff)!=CommHead.CommCRC) { Log(FileName,St(MLogCommBrk)); Alarm(); return(false); } else { byte *UnpData; size_t UnpDataSize; DataIO.GetUnpackedData(&UnpData,&UnpDataSize); CmtData->Alloc(UnpDataSize); memcpy(&((*CmtData)[0]),UnpData,UnpDataSize); } } else { CmtData->Alloc(CmtLength); Read(&((*CmtData)[0]),CmtLength); if (!OldFormat && CommHead.CommCRC!=(~CRC(0xffffffff,&((*CmtData)[0]),CmtLength)&0xffff)) { Log(FileName,St(MLogCommBrk)); Alarm(); CmtData->Reset(); return(false); } } #endif #if defined(_WIN_ALL) && !defined(_WIN_CE) if (CmtData->Size()>0) { size_t CmtSize=CmtData->Size(); char *DataA=(char *)CmtData->Addr(); OemToCharBuffA(DataA,DataA,(DWORD)CmtSize); if (CmtDataW!=NULL) { CmtDataW->Alloc(CmtSize+1); CmtData->Push(0); CharToWide(DataA,CmtDataW->Addr(),CmtSize+1); CmtData->Alloc(CmtSize); CmtDataW->Alloc(wcslen(CmtDataW->Addr())); } } #endif return(CmtData->Size()>0); }
/*********************************************************************** * OemToCharA (USER32.@) */ BOOL WINAPI OemToCharA( LPCSTR s, LPSTR d ) { return OemToCharBuffA( s, d, strlen( s ) + 1 ); }
UINT COEMFile::Read(void FAR* lpBuf, UINT nCount) { UINT n = CTrackFile::Read(lpBuf, nCount); OemToCharBuffA((const char*)lpBuf, (char*)lpBuf, n); return n; }
int PASCAL ProcessFile(HANDLE hArcData,int Operation,char *DestPath,char *DestName,wchar *DestPathW,wchar *DestNameW) { DataSet *Data=(DataSet *)hArcData; try { Data->Cmd.DllError=0; if (Data->OpenMode==RAR_OM_LIST || Data->OpenMode==RAR_OM_LIST_INCSPLIT || Operation==RAR_SKIP && !Data->Arc.Solid) { if (Data->Arc.Volume && Data->Arc.GetHeaderType()==HEAD_FILE && Data->Arc.FileHead.SplitAfter) if (MergeArchive(Data->Arc,NULL,false,'L')) { Data->Arc.Seek(Data->Arc.CurBlockPos,SEEK_SET); return ERAR_SUCCESS; } else return ERAR_EOPEN; Data->Arc.SeekToNext(); } else { Data->Cmd.DllOpMode=Operation; *Data->Cmd.ExtrPath=0; *Data->Cmd.DllDestName=0; if (DestPath!=NULL) { char ExtrPathA[NM]; #ifdef _WIN_ALL OemToCharBuffA(DestPath,ExtrPathA,ASIZE(ExtrPathA)-2); #else strncpyz(ExtrPathA,DestPath,ASIZE(ExtrPathA)-2); #endif CharToWide(ExtrPathA,Data->Cmd.ExtrPath,ASIZE(Data->Cmd.ExtrPath)); AddEndSlash(Data->Cmd.ExtrPath,ASIZE(Data->Cmd.ExtrPath)); } if (DestName!=NULL) { char DestNameA[NM]; #ifdef _WIN_ALL OemToCharBuffA(DestName,DestNameA,ASIZE(DestNameA)-2); #else strncpyz(DestNameA,DestName,ASIZE(DestNameA)-2); #endif CharToWide(DestNameA,Data->Cmd.DllDestName,ASIZE(Data->Cmd.DllDestName)); } if (DestPathW!=NULL) { wcsncpy(Data->Cmd.ExtrPath,DestPathW,ASIZE(Data->Cmd.ExtrPath)); AddEndSlash(Data->Cmd.ExtrPath,ASIZE(Data->Cmd.ExtrPath)); } if (DestNameW!=NULL) wcsncpyz(Data->Cmd.DllDestName,DestNameW,ASIZE(Data->Cmd.DllDestName)); wcscpy(Data->Cmd.Command,Operation==RAR_EXTRACT ? L"X":L"T"); Data->Cmd.Test=Operation!=RAR_EXTRACT; bool Repeat=false; Data->Extract.ExtractCurrentFile(&Data->Cmd,Data->Arc,Data->HeaderSize,Repeat); // Now we process extra file information if any. // // Archive can be closed if we process volumes, next volume is missing // and current one is already removed or deleted. So we need to check // if archive is still open to avoid calling file operations on // the invalid file handle. Some of our file operations like Seek() // process such invalid handle correctly, some not. while (Data->Arc.IsOpened() && Data->Arc.ReadHeader()!=0 && Data->Arc.GetHeaderType()==HEAD_SERVICE) { Data->Extract.ExtractCurrentFile(&Data->Cmd,Data->Arc,Data->HeaderSize,Repeat); Data->Arc.SeekToNext(); } Data->Arc.Seek(Data->Arc.CurBlockPos,SEEK_SET); } } catch (RAR_EXIT ErrCode) { return Data->Cmd.DllError!=0 ? Data->Cmd.DllError : RarErrorToDll(ErrCode); } return Data->Cmd.DllError; }
int tempzip_make(HWND hwndDlg, TCHAR *fn) { TCHAR buf[MAX_PATH]; GetTempPath(MAX_PATH,buf); GetTempFileName(buf,_T("z2e"),GetTickCount(),tempzip_path); if (!CreateDirectory(tempzip_path,NULL)) { GetTempPath(MAX_PATH,tempzip_path); _tcscat(tempzip_path,_T("\\nsi")); if (!CreateDirectory(tempzip_path,NULL)) { tempzip_path[0]=0; MessageBox(hwndDlg,_T("Error creating temporary directory"),g_errcaption,MB_OK|MB_ICONSTOP); return 1; } } FILE *fp=_tfopen(fn,_T("rb")); if (fp) { fseek(fp,0,SEEK_END); g_zipfile_size=ftell(fp); fclose(fp); } else g_zipfile_size=0; unzFile f; f = unzOpen(fn); if (!f || unzGoToFirstFile(f) != UNZ_OK) { if (f) unzClose(f); MessageBox(hwndDlg,_T("Error opening ZIP file"),g_errcaption,MB_OK|MB_ICONSTOP); return 1; } int nf=0, nkb=0; g_extracting=1; do { char filenameA[MAX_PATH]; unz_file_info info; // ZREAD uses byte size, not TCHAR length. unzGetCurrentFileInfo(f,&info,filenameA,sizeof(filenameA),NULL,0,NULL,0); // was zip created on MS-DOS/Windows? if ((info.version & 0xFF00) == 0) { OemToCharBuffA(filenameA, filenameA, (DWORD)strlen(filenameA)); } #ifdef _UNICODE TCHAR filename[MAX_PATH]; if (MultiByteToWideChar(CP_ACP, 0, filenameA, -1, filename, MAX_PATH) == 0) { if (f) unzClose(f); MessageBox(hwndDlg,_T("Error converting filename to Unicode"), g_errcaption, MB_OK|MB_ICONSTOP); return 1; } #else char* filename = filenameA; #endif if (filename[0] && filename[_tcslen(filename)-1] != _T('\\') && filename[_tcslen(filename)-1] != _T('/')) { TCHAR *pfn=filename; while (*pfn) { if (*pfn == _T('/')) *pfn=_T('\\'); pfn++; } pfn=filename; if (pfn[1] == _T(':') && pfn[2] == _T('\\')) pfn+=3; while (*pfn == _T('\\')) pfn++; TCHAR out_filename[1024]; lstrcpy(out_filename,tempzip_path); lstrcat(out_filename,_T("\\")); lstrcat(out_filename,pfn); if (_tcsstr(pfn,_T("\\"))) { TCHAR buf[1024]; lstrcpy(buf,out_filename); TCHAR *p=buf+_tcslen(buf); while (p > buf && *p != _T('\\')) p--; *p=0; if (buf[0]) doMKDir(buf); } if (unzOpenCurrentFile(f) == UNZ_OK) { SendDlgItemMessage(hwndDlg,IDC_ZIPINFO_FILES,LB_ADDSTRING,0,(LPARAM)pfn); FILE *fp; int l; fp = _tfopen(out_filename,_T("wb")); if (fp) { do { // Jim Park: Local buf, no need to TCHAR char buf[1024]; l=unzReadCurrentFile(f,buf,sizeof(buf)); if (l > 0) { if (fwrite(buf,1,l,fp) != (unsigned int)l) { unzClose(f); fclose(fp); MessageBox(hwndDlg,_T("Error writing output file(s)"),g_errcaption,MB_OK|MB_ICONSTOP); g_extracting=0; return 1; } nkb++; } } while (l > 0); fclose(fp); { // set file time HANDLE hf = CreateFile(out_filename, GENERIC_WRITE, 0, 0, OPEN_ALWAYS, 0, 0); if (hf != INVALID_HANDLE_VALUE) { FILETIME ft, lft; DosDateTimeToFileTime(HIWORD(info.dosDate), LOWORD(info.dosDate), &ft); LocalFileTimeToFileTime(&ft, &lft); SetFileTime(hf, 0, 0, &lft); CloseHandle(hf); } } } else { unzClose(f); MessageBox(hwndDlg,_T("Error opening output file(s)"),g_errcaption,MB_OK|MB_ICONSTOP); g_extracting=0; return 1; } nf++; wsprintf(buf,_T("Extracting: %d files, %dKB"),nf,nkb); SetDlgItemText(hwndDlg,IDC_ZIPINFO_SUMMARY,buf); MSG msg; int quit=0; while (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if (msg.message == WM_DESTROY && msg.hwnd == g_hwnd) { quit++; break; } TranslateMessage(&msg); DispatchMessage(&msg); } unzCloseCurrentFile(f); if (quit) break; } else { unzClose(f); MessageBox(hwndDlg,_T("Error extracting from ZIP file"),g_errcaption,MB_OK|MB_ICONSTOP); g_extracting=0; return 1; } } } while (unzGoToNextFile(f) == UNZ_OK); g_extracting=0; wsprintf(buf,_T("Extracted: %d files, %dKB"),nf,nkb); SetDlgItemText(hwndDlg,IDC_ZIPINFO_SUMMARY,buf); unzClose(f); return 0; }
/* * @implemented */ HANDLE WINAPI GetClipboardData(UINT uFormat) { HANDLE hData = NULL; PVOID pData = NULL; DWORD cbData = 0; GETCLIPBDATA gcd; hData = NtUserGetClipboardData(uFormat, &gcd); if (!hData) return NULL; if (gcd.fGlobalHandle) { HANDLE hGlobal; NtUserCreateLocalMemHandle(hData, NULL, 0, &cbData); hGlobal = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, cbData); pData = GlobalLock(hGlobal); NtUserCreateLocalMemHandle(hData, pData, cbData, NULL); hData = hGlobal; } if (gcd.uFmtRet != uFormat) { SETCLIPBDATA scd = {FALSE, FALSE}; HANDLE hNewData = NULL; PVOID pNewData = NULL; /* Synthesize requested format */ switch (uFormat) { case CF_TEXT: if (gcd.uFmtRet == CF_UNICODETEXT) pNewData = IntSynthesizeMultiByte(pData, cbData, uFormat == CF_OEMTEXT); else // CF_OEMTEXT OemToCharBuffA(pData, pData, cbData); break; case CF_OEMTEXT: if (gcd.uFmtRet == CF_UNICODETEXT) pNewData = IntSynthesizeMultiByte(pData, cbData, uFormat == CF_OEMTEXT); else CharToOemBuffA(pData, pData, cbData); break; case CF_UNICODETEXT: pNewData = IntSynthesizeWideChar(pData, cbData, gcd.uFmtRet == CF_OEMTEXT); break; default: FIXME("Format: %u != %u\n", uFormat, gcd.uFmtRet); } /* Is it a global handle? */ if (pNewData) hNewData = GlobalHandle(pNewData); if (hNewData) { /* Free old data */ if (pData) { GlobalUnlock(hData); GlobalFree(hData); } hData = hNewData; pData = pNewData; } /* Save synthesized format in clibboard */ if (pData) { HANDLE hMem; scd.fGlobalHandle = TRUE; hMem = NtUserConvertMemHandle(pData, GlobalSize(hData)); NtUserSetClipboardData(uFormat, hMem, &scd); } else if (hData) NtUserSetClipboardData(uFormat, hData, &scd); } /* Unlock global handle */ if (pData) GlobalUnlock(hData); return hData; }