ReactOS 0.4.16-dev-197-g92996da
fileutils.c File Reference
#include "precomp.h"
Include dependency graph for fileutils.c:

Go to the source code of this file.

Functions

static HGLOBAL ClipboardReadMemoryBlock (HANDLE hFile, DWORD dwOffset, DWORD dwLength)
 
static BOOL ClipboardReadMemory (HANDLE hFile, DWORD dwFormat, DWORD dwOffset, DWORD dwLength, WORD FileIdentifier, PVOID lpFormatName)
 
static BOOL ClipboardWriteMemory (HANDLE hFile, DWORD dwFormat, DWORD dwOffset, PDWORD pdwLength)
 
static BOOL ClipboardReadPalette (HANDLE hFile, DWORD dwOffset, DWORD dwLength)
 
static BOOL ClipboardReadMetafile (HANDLE hFile, DWORD dwOffset, DWORD dwLength)
 
static BOOL ClipboardReadEnhMetafile (HANDLE hFile, DWORD dwOffset, DWORD dwLength)
 
static BOOL ClipboardReadBitmap (HANDLE hFile, DWORD dwOffset, DWORD dwLength)
 
void ReadClipboardFile (LPCWSTR lpFileName)
 
void WriteClipboardFile (LPCWSTR lpFileName, WORD wFileIdentifier)
 

Function Documentation

◆ ClipboardReadBitmap()

static BOOL ClipboardReadBitmap ( HANDLE  hFile,
DWORD  dwOffset,
DWORD  dwLength 
)
static

Definition at line 234 of file fileutils.c.

235{
236 HGLOBAL hData;
238 LPBITMAP lpBitmap;
239
241 if (!hData)
242 {
243 return FALSE;
244 }
245
246 lpBitmap = GlobalLock(hData);
247 if (!lpBitmap)
248 {
249 GlobalFree(hData);
250 return FALSE;
251 }
252
253 lpBitmap->bmBits = lpBitmap + sizeof(BITMAP) + 1;
254
255 hBitmap = CreateBitmapIndirect(lpBitmap);
256
257 GlobalUnlock(hData);
258 GlobalFree(hData);
259
260 if (!hBitmap)
261 {
263 return FALSE;
264 }
265
267 {
269 return FALSE;
270 }
271
272 return TRUE;
273}
static HGLOBAL ClipboardReadMemoryBlock(HANDLE hFile, DWORD dwOffset, DWORD dwLength)
Definition: fileutils.c:11
#define CF_BITMAP
Definition: constants.h:397
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static HBITMAP hBitmap
Definition: timezone.c:26
#define SetLastError(x)
Definition: compat.h:752
static DWORD DWORD * dwLength
Definition: fusion.c:86
pKey DeleteObject()
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
static HBITMAP
Definition: button.c:44
_In_ HANDLE hFile
Definition: mswsock.h:90
_In_ DWORD _In_ DWORD dwOffset
Definition: ntgdi.h:2033
#define BITMAP
Definition: pedump.c:503
LPVOID bmBits
Definition: wingdi.h:1427
HBITMAP WINAPI CreateBitmapIndirect(_In_ const BITMAP *pbm)
HANDLE WINAPI SetClipboardData(_In_ UINT, _In_opt_ HANDLE)

Referenced by ReadClipboardFile().

◆ ClipboardReadEnhMetafile()

static BOOL ClipboardReadEnhMetafile ( HANDLE  hFile,
DWORD  dwOffset,
DWORD  dwLength 
)
static

Definition at line 195 of file fileutils.c.

196{
197 HENHMETAFILE hEmf;
198 HGLOBAL hData;
199 LPVOID lpData;
200
202 if (!hData)
203 {
204 return FALSE;
205 }
206
207 lpData = GlobalLock(hData);
208 if (!lpData)
209 {
210 GlobalFree(hData);
211 return FALSE;
212 }
213
214 hEmf = SetEnhMetaFileBits(dwLength, lpData);
215
216 GlobalUnlock(hData);
217 GlobalFree(hData);
218
219 if (!hEmf)
220 {
222 return FALSE;
223 }
224
226 {
227 DeleteEnhMetaFile(hEmf);
228 return FALSE;
229 }
230
231 return TRUE;
232}
#define CF_ENHMETAFILE
Definition: constants.h:409
BOOL WINAPI DeleteEnhMetaFile(_In_opt_ HENHMETAFILE)
HENHMETAFILE WINAPI SetEnhMetaFileBits(_In_ UINT nSize, _In_reads_bytes_(nSize) const BYTE *pb)

Referenced by ReadClipboardFile().

◆ ClipboardReadMemory()

static BOOL ClipboardReadMemory ( HANDLE  hFile,
DWORD  dwFormat,
DWORD  dwOffset,
DWORD  dwLength,
WORD  FileIdentifier,
PVOID  lpFormatName 
)
static

Definition at line 47 of file fileutils.c.

48{
49 HGLOBAL hData;
50 DWORD dwTemp = 0;
51
53 if (!hData)
54 return FALSE;
55
56 if ((dwFormat >= 0xC000) && (dwFormat <= 0xFFFF))
57 {
58 if (FileIdentifier == CLIP_FMT_31)
59 dwTemp = RegisterClipboardFormatA((LPCSTR)lpFormatName);
60 else if ((FileIdentifier == CLIP_FMT_NT) || (FileIdentifier == CLIP_FMT_BK))
61 dwTemp = RegisterClipboardFormatW((LPCWSTR)lpFormatName);
62
63 if (!dwTemp)
64 {
65 GlobalFree(hData);
66 return FALSE;
67 }
68 }
69 else
70 {
71 dwTemp = dwFormat;
72 }
73
74 if (!SetClipboardData(dwTemp, hData))
75 {
76 GlobalFree(hData);
77 return FALSE;
78 }
79
80 return TRUE;
81}
#define CLIP_FMT_31
Definition: fileutils.h:12
#define CLIP_FMT_NT
Definition: fileutils.h:13
#define CLIP_FMT_BK
Definition: fileutils.h:14
unsigned long DWORD
Definition: ntddk_ex.h:95
UINT WINAPI RegisterClipboardFormatW(_In_ LPCWSTR)
UINT WINAPI RegisterClipboardFormatA(_In_ LPCSTR)
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by ReadClipboardFile().

◆ ClipboardReadMemoryBlock()

static HGLOBAL ClipboardReadMemoryBlock ( HANDLE  hFile,
DWORD  dwOffset,
DWORD  dwLength 
)
static

Definition at line 11 of file fileutils.c.

12{
13 HGLOBAL hData;
14 LPVOID lpData;
15 DWORD dwBytesRead;
16
17 hData = GlobalAlloc(GHND, dwLength);
18 if (!hData)
19 return NULL;
20
21 lpData = GlobalLock(hData);
22 if (!lpData)
23 {
24 GlobalFree(hData);
25 return NULL;
26 }
27
29 {
30 GlobalUnlock(hData);
31 GlobalFree(hData);
32 return NULL;
33 }
34
35 if (!ReadFile(hFile, lpData, dwLength, &dwBytesRead, NULL))
36 {
37 GlobalUnlock(hData);
38 GlobalFree(hData);
39 return NULL;
40 }
41
42 GlobalUnlock(hData);
43
44 return hData;
45}
#define NULL
Definition: types.h:112
#define FILE_BEGIN
Definition: compat.h:761
#define INVALID_SET_FILE_POINTER
Definition: compat.h:732
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define SetFilePointer
Definition: compat.h:743
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define GHND
Definition: winbase.h:322

Referenced by ClipboardReadBitmap(), ClipboardReadEnhMetafile(), ClipboardReadMemory(), ClipboardReadMetafile(), and ClipboardReadPalette().

◆ ClipboardReadMetafile()

static BOOL ClipboardReadMetafile ( HANDLE  hFile,
DWORD  dwOffset,
DWORD  dwLength 
)
static

Definition at line 156 of file fileutils.c.

157{
158 HMETAFILE hMf;
159 HGLOBAL hData;
160 LPVOID lpData;
161
163 if (!hData)
164 {
165 return FALSE;
166 }
167
168 lpData = GlobalLock(hData);
169 if (!lpData)
170 {
171 GlobalFree(hData);
172 return FALSE;
173 }
174
175 hMf = SetMetaFileBitsEx(dwLength, lpData);
176
177 GlobalUnlock(hData);
178 GlobalFree(hData);
179
180 if (!hMf)
181 {
183 return FALSE;
184 }
185
187 {
188 DeleteMetaFile(hMf);
189 return FALSE;
190 }
191
192 return TRUE;
193}
#define CF_METAFILEPICT
Definition: constants.h:398
BOOL WINAPI DeleteMetaFile(_In_ HMETAFILE)
HMETAFILE WINAPI SetMetaFileBitsEx(_In_ UINT cbBuffer, _In_reads_bytes_(cbBuffer) CONST BYTE *lpData)

Referenced by ReadClipboardFile().

◆ ClipboardReadPalette()

static BOOL ClipboardReadPalette ( HANDLE  hFile,
DWORD  dwOffset,
DWORD  dwLength 
)
static

Definition at line 116 of file fileutils.c.

117{
118 LPLOGPALETTE lpPalette;
119 HPALETTE hPalette;
120 HGLOBAL hData;
121
123 if (!hData)
124 {
125 return FALSE;
126 }
127
128 lpPalette = GlobalLock(hData);
129 if (!lpPalette)
130 {
131 GlobalFree(hData);
132 return FALSE;
133 }
134
135 hPalette = CreatePalette(lpPalette);
136 if (!hPalette)
137 {
138 GlobalUnlock(hData);
139 GlobalFree(hData);
141 return FALSE;
142 }
143
144 GlobalUnlock(hData);
145 GlobalFree(hData);
146
147 if (!SetClipboardData(CF_PALETTE, hPalette))
148 {
149 DeleteObject(hPalette);
150 return FALSE;
151 }
152
153 return TRUE;
154}
#define CF_PALETTE
Definition: constants.h:404
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)

Referenced by ReadClipboardFile().

◆ ClipboardWriteMemory()

static BOOL ClipboardWriteMemory ( HANDLE  hFile,
DWORD  dwFormat,
DWORD  dwOffset,
PDWORD  pdwLength 
)
static

Definition at line 83 of file fileutils.c.

84{
85 HGLOBAL hData;
86 LPVOID lpData;
87 DWORD dwBytesWritten;
88
89 hData = GetClipboardData(dwFormat);
90 if (!hData)
91 return FALSE;
92
93 lpData = GlobalLock(hData);
94 if (!lpData)
95 return FALSE;
96
97 *pdwLength = GlobalSize(hData);
98
100 {
101 GlobalUnlock(hData);
102 return FALSE;
103 }
104
105 if (!WriteFile(hFile, lpData, *pdwLength, &dwBytesWritten, NULL))
106 {
107 GlobalUnlock(hData);
108 return FALSE;
109 }
110
111 GlobalUnlock(hData);
112
113 return TRUE;
114}
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
SIZE_T NTAPI GlobalSize(HGLOBAL hMem)
Definition: heapmem.c:1090
HANDLE WINAPI GetClipboardData(_In_ UINT)

Referenced by WriteClipboardFile().

◆ ReadClipboardFile()

void ReadClipboardFile ( LPCWSTR  lpFileName)

Definition at line 275 of file fileutils.c.

276{
277 CLIPFILEHEADER ClipFileHeader;
278 CLIPFORMATHEADER ClipFormatArray;
279 NTCLIPFILEHEADER NtClipFileHeader;
280 NTCLIPFORMATHEADER NtClipFormatArray;
281 PVOID pClipFileHeader;
282 PVOID pClipFormatArray;
283 DWORD SizeOfFileHeader, SizeOfFormatHeader;
284
285 WORD wFileIdentifier;
286 WORD wFormatCount;
287 DWORD dwFormatID;
288 DWORD dwLenData;
289 DWORD dwOffData;
291
293 DWORD dwBytesRead;
294 BOOL bResult;
295 int i;
296
297 /* Open the file for read access */
301 {
303 goto done;
304 }
305
306 /* Just read enough bytes to get the clipboard file format ID */
307 if (!ReadFile(hFile, &wFileIdentifier, sizeof(wFileIdentifier), &dwBytesRead, NULL))
308 {
310 goto done;
311 }
312
313 /* Set data according to the clipboard file format ID */
314 switch (wFileIdentifier)
315 {
316 case CLIP_FMT_31:
317 SizeOfFileHeader = sizeof(CLIPFILEHEADER);
318 SizeOfFormatHeader = sizeof(CLIPFORMATHEADER);
319 pClipFileHeader = &ClipFileHeader;
320 pClipFormatArray = &ClipFormatArray;
321 break;
322
323 case CLIP_FMT_NT:
324 case CLIP_FMT_BK:
325 SizeOfFileHeader = sizeof(NTCLIPFILEHEADER);
326 SizeOfFormatHeader = sizeof(NTCLIPFORMATHEADER);
327 pClipFileHeader = &NtClipFileHeader;
328 pClipFormatArray = &NtClipFormatArray;
329 break;
330
331 default:
333 goto done;
334 }
335
336 /* Completely read the header */
338 if (!ReadFile(hFile, pClipFileHeader, SizeOfFileHeader, &dwBytesRead, NULL) ||
339 dwBytesRead != SizeOfFileHeader)
340 {
342 goto done;
343 }
344
345 /* Get header data */
346 switch (wFileIdentifier)
347 {
348 case CLIP_FMT_31:
349 assert(wFileIdentifier == ((CLIPFILEHEADER*)pClipFileHeader)->wFileIdentifier);
350 wFormatCount = ((CLIPFILEHEADER*)pClipFileHeader)->wFormatCount;
351 break;
352
353 case CLIP_FMT_NT:
354 case CLIP_FMT_BK:
355 assert(wFileIdentifier == ((NTCLIPFILEHEADER*)pClipFileHeader)->wFileIdentifier);
356 wFormatCount = ((NTCLIPFILEHEADER*)pClipFileHeader)->wFormatCount;
357 break;
358 }
359
360 /* Loop through the format data array */
361 for (i = 0; i < wFormatCount; i++)
362 {
363 if (SetFilePointer(hFile, SizeOfFileHeader + i * SizeOfFormatHeader, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
364 {
366 goto done;
367 }
368
369 if (!ReadFile(hFile, pClipFormatArray, SizeOfFormatHeader, &dwBytesRead, NULL))
370 {
372 goto done;
373 }
374
375 /* Get format data */
376 switch (wFileIdentifier)
377 {
378 case CLIP_FMT_31:
379 dwFormatID = ((CLIPFORMATHEADER*)pClipFormatArray)->dwFormatID;
380 dwLenData = ((CLIPFORMATHEADER*)pClipFormatArray)->dwLenData;
381 dwOffData = ((CLIPFORMATHEADER*)pClipFormatArray)->dwOffData;
382 szName = ((CLIPFORMATHEADER*)pClipFormatArray)->szName;
383 break;
384
385 case CLIP_FMT_NT:
386 case CLIP_FMT_BK:
387 dwFormatID = ((NTCLIPFORMATHEADER*)pClipFormatArray)->dwFormatID;
388 dwLenData = ((NTCLIPFORMATHEADER*)pClipFormatArray)->dwLenData;
389 dwOffData = ((NTCLIPFORMATHEADER*)pClipFormatArray)->dwOffData;
390 szName = ((NTCLIPFORMATHEADER*)pClipFormatArray)->szName;
391 break;
392 }
393
394 switch (dwFormatID)
395 {
396 case CF_OWNERDISPLAY:
397 {
398 break;
399 }
400
401 case CF_DSPBITMAP:
402 case CF_BITMAP:
403 {
404 bResult = ClipboardReadBitmap(hFile, dwOffData, dwLenData);
405 break;
406 }
407
409 case CF_METAFILEPICT:
410 {
411 bResult = ClipboardReadMetafile(hFile, dwOffData, dwLenData);
412 break;
413 }
414
416 case CF_ENHMETAFILE:
417 {
418 bResult = ClipboardReadEnhMetafile(hFile, dwOffData, dwLenData);
419 break;
420 }
421
422 case CF_PALETTE:
423 {
424 bResult = ClipboardReadPalette(hFile, dwOffData, dwLenData);
425 break;
426 }
427
428 default:
429 {
430 if ((dwFormatID < CF_PRIVATEFIRST) || (dwFormatID > CF_PRIVATELAST))
431 {
432 bResult = ClipboardReadMemory(hFile, dwFormatID, dwOffData, dwLenData, wFileIdentifier, szName);
433 }
434 break;
435 }
436 }
437
438 if (!bResult)
440 }
441
442done:
445
446 return;
447}
static BOOL ClipboardReadPalette(HANDLE hFile, DWORD dwOffset, DWORD dwLength)
Definition: fileutils.c:116
static BOOL ClipboardReadBitmap(HANDLE hFile, DWORD dwOffset, DWORD dwLength)
Definition: fileutils.c:234
static BOOL ClipboardReadEnhMetafile(HANDLE hFile, DWORD dwOffset, DWORD dwLength)
Definition: fileutils.c:195
static BOOL ClipboardReadMemory(HANDLE hFile, DWORD dwFormat, DWORD dwOffset, DWORD dwLength, WORD FileIdentifier, PVOID lpFormatName)
Definition: fileutils.c:47
static BOOL ClipboardReadMetafile(HANDLE hFile, DWORD dwOffset, DWORD dwLength)
Definition: fileutils.c:156
#define ERROR_INVALID_FILE_FORMAT
Definition: resources.h:47
#define CF_PRIVATELAST
Definition: constants.h:419
#define CF_DSPENHMETAFILE
Definition: constants.h:417
#define CF_OWNERDISPLAY
Definition: constants.h:413
#define CF_DSPMETAFILEPICT
Definition: constants.h:416
#define CF_DSPBITMAP
Definition: constants.h:415
#define CF_PRIVATEFIRST
Definition: constants.h:418
struct _CLIPFORMATHEADER CLIPFORMATHEADER
struct _CLIPFILEHEADER CLIPFILEHEADER
struct _NTCLIPFILEHEADER NTCLIPFILEHEADER
struct _NTCLIPFORMATHEADER NTCLIPFORMATHEADER
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
#define assert(x)
Definition: debug.h:53
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned short WORD
Definition: ntddk_ex.h:93
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static const WCHAR szName[]
Definition: powrprof.c:45
HINSTANCE hInstance
Definition: precomp.h:43
_In_ LPCSTR lpFileName
Definition: winbase.h:3095
#define MB_OK
Definition: winuser.h:793
#define MB_ICONSTOP
Definition: winuser.h:806
int MessageBoxRes(HWND hWnd, HINSTANCE hInstance, UINT uText, UINT uCaption, UINT uType)
Definition: winutils.c:49
void ShowLastWin32Error(HWND hwndParent)
Definition: winutils.c:11

Referenced by LoadClipboardDataFromFile().

◆ WriteClipboardFile()

void WriteClipboardFile ( LPCWSTR  lpFileName,
WORD  wFileIdentifier 
)

Definition at line 449 of file fileutils.c.

450{
451 CLIPFILEHEADER ClipFileHeader;
452 CLIPFORMATHEADER ClipFormatArray;
453 NTCLIPFILEHEADER NtClipFileHeader;
454 NTCLIPFORMATHEADER NtClipFormatArray;
455 PVOID pClipFileHeader;
456 PVOID pClipFormatArray;
457 DWORD SizeOfFileHeader, SizeOfFormatHeader;
458
459 WORD wFormatCount;
460 DWORD dwFormatID;
461 DWORD dwLenData;
462 DWORD dwOffData;
463 // PVOID szName;
464
466 DWORD dwBytesWritten;
467 int i;
468
469 /* Create the file for write access */
473 {
475 goto done;
476 }
477
478 wFormatCount = CountClipboardFormats();
479
480 /* Select the file format and setup the header according to the clipboard file format ID */
481 switch (wFileIdentifier)
482 {
483 case CLIP_FMT_31:
484 SizeOfFileHeader = sizeof(CLIPFILEHEADER);
485 SizeOfFormatHeader = sizeof(CLIPFORMATHEADER);
486 pClipFileHeader = &ClipFileHeader;
487 pClipFormatArray = &ClipFormatArray;
488
489 ClipFileHeader.wFileIdentifier = CLIP_FMT_31; // wFileIdentifier
490 ClipFileHeader.wFormatCount = wFormatCount;
491 break;
492
493 case CLIP_FMT_NT:
494 case CLIP_FMT_BK:
495 SizeOfFileHeader = sizeof(NTCLIPFILEHEADER);
496 SizeOfFormatHeader = sizeof(NTCLIPFORMATHEADER);
497 pClipFileHeader = &NtClipFileHeader;
498 pClipFormatArray = &NtClipFormatArray;
499
500 NtClipFileHeader.wFileIdentifier = CLIP_FMT_NT; // wFileIdentifier
501 NtClipFileHeader.wFormatCount = wFormatCount;
502 break;
503
504 default:
506 goto done;
507 }
508
509 /* Write the header */
511 if (!WriteFile(hFile, pClipFileHeader, SizeOfFileHeader, &dwBytesWritten, NULL) ||
512 dwBytesWritten != SizeOfFileHeader)
513 {
515 goto done;
516 }
517
518 /* Compute where the data should start (after the file header and the format array) */
519 dwOffData = SizeOfFileHeader + wFormatCount * SizeOfFormatHeader;
520
521 /* Loop through each format and save the data */
522 i = 0;
523 dwFormatID = EnumClipboardFormats(0);
524 while (dwFormatID)
525 {
526 if (i >= wFormatCount)
527 {
528 /* Must never happen! */
529 assert(FALSE);
530 break;
531 }
532
533 /* Write the clipboard data at the specified offset, and retrieve its length */
534 if (!ClipboardWriteMemory(hFile, dwFormatID, dwOffData, &dwLenData))
535 goto Cont;
536
537 /* Write the format data header */
538 switch (wFileIdentifier)
539 {
540 case CLIP_FMT_31:
541 ZeroMemory(pClipFormatArray, sizeof(CLIPFORMATHEADER));
542 ((CLIPFORMATHEADER*)pClipFormatArray)->dwFormatID = dwFormatID;
543 ((CLIPFORMATHEADER*)pClipFormatArray)->dwLenData = dwLenData;
544 ((CLIPFORMATHEADER*)pClipFormatArray)->dwOffData = dwOffData;
546 dwFormatID,
547 FALSE,
548 ((CLIPFORMATHEADER*)pClipFormatArray)->szName,
549 ARRAYSIZE(((CLIPFORMATHEADER*)pClipFormatArray)->szName));
550 break;
551
552 case CLIP_FMT_NT:
553 case CLIP_FMT_BK:
554 ZeroMemory(pClipFormatArray, sizeof(NTCLIPFORMATHEADER));
555 ((NTCLIPFORMATHEADER*)pClipFormatArray)->dwFormatID = dwFormatID;
556 ((NTCLIPFORMATHEADER*)pClipFormatArray)->dwLenData = dwLenData;
557 ((NTCLIPFORMATHEADER*)pClipFormatArray)->dwOffData = dwOffData;
559 dwFormatID,
560 TRUE,
561 ((NTCLIPFORMATHEADER*)pClipFormatArray)->szName,
562 ARRAYSIZE(((NTCLIPFORMATHEADER*)pClipFormatArray)->szName));
563 break;
564 }
565
566 if (SetFilePointer(hFile, SizeOfFileHeader + i * SizeOfFormatHeader, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
567 {
569 goto done;
570 }
571
572 if (!WriteFile(hFile, pClipFormatArray, SizeOfFormatHeader, &dwBytesWritten, NULL))
573 {
575 goto done;
576 }
577
578 /* Adjust the offset for the next data stream */
579 dwOffData += dwLenData;
580
581Cont:
582 i++;
583 dwFormatID = EnumClipboardFormats(dwFormatID);
584 }
585
586done:
589
590 return;
591}
static BOOL ClipboardWriteMemory(HANDLE hFile, DWORD dwFormat, DWORD dwOffset, PDWORD pdwLength)
Definition: fileutils.c:83
void RetrieveClipboardFormatName(HINSTANCE hInstance, UINT uFormat, BOOL Unicode, PVOID lpszFormat, UINT cch)
Definition: cliputils.c:95
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define CREATE_ALWAYS
Definition: disk.h:72
#define GENERIC_WRITE
Definition: nt_native.h:90
WORD wFormatCount
Definition: fileutils.h:25
WORD wFileIdentifier
Definition: fileutils.h:24
WORD wFileIdentifier
Definition: fileutils.h:42
#define ZeroMemory
Definition: winbase.h:1736
UINT WINAPI EnumClipboardFormats(_In_ UINT)
int WINAPI CountClipboardFormats(void)
Definition: ntwrapper.h:184

Referenced by SaveClipboardToFile().