ReactOS 0.4.15-dev-5667-ged97270
fileutils.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _CLIPFILEHEADER
 
struct  _CLIPFORMATHEADER
 
struct  _NTCLIPFILEHEADER
 
struct  _NTCLIPFORMATHEADER
 

Macros

#define CLIP_FMT_31   0xC350
 
#define CLIP_FMT_NT   0xC351
 
#define CLIP_FMT_BK   0xC352
 
#define MAX_FMT_NAME_LEN   79
 

Typedefs

typedef struct _CLIPFILEHEADER CLIPFILEHEADER
 
typedef struct _CLIPFORMATHEADER CLIPFORMATHEADER
 
typedef struct _NTCLIPFILEHEADER NTCLIPFILEHEADER
 
typedef struct _NTCLIPFORMATHEADER NTCLIPFORMATHEADER
 

Functions

void ReadClipboardFile (LPCWSTR lpFileName)
 
void WriteClipboardFile (LPCWSTR lpFileName, WORD wFileIdentifier)
 

Macro Definition Documentation

◆ CLIP_FMT_31

#define CLIP_FMT_31   0xC350

Definition at line 12 of file fileutils.h.

◆ CLIP_FMT_BK

#define CLIP_FMT_BK   0xC352

Definition at line 14 of file fileutils.h.

◆ CLIP_FMT_NT

#define CLIP_FMT_NT   0xC351

Definition at line 13 of file fileutils.h.

◆ MAX_FMT_NAME_LEN

#define MAX_FMT_NAME_LEN   79

Definition at line 16 of file fileutils.h.

Typedef Documentation

◆ CLIPFILEHEADER

◆ CLIPFORMATHEADER

◆ NTCLIPFILEHEADER

◆ NTCLIPFORMATHEADER

Function Documentation

◆ 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_METAFILEPICT
Definition: constants.h:398
#define CF_BITMAP
Definition: constants.h:397
#define CF_PRIVATELAST
Definition: constants.h:419
#define CF_PALETTE
Definition: constants.h:404
#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_ENHMETAFILE
Definition: constants.h:409
#define CF_PRIVATEFIRST
Definition: constants.h:418
struct _CLIPFORMATHEADER CLIPFORMATHEADER
#define CLIP_FMT_31
Definition: fileutils.h:12
#define CLIP_FMT_NT
Definition: fileutils.h:13
struct _CLIPFILEHEADER CLIPFILEHEADER
struct _NTCLIPFILEHEADER NTCLIPFILEHEADER
struct _NTCLIPFORMATHEADER NTCLIPFORMATHEADER
#define CLIP_FMT_BK
Definition: fileutils.h:14
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define FILE_BEGIN
Definition: compat.h:761
#define INVALID_SET_FILE_POINTER
Definition: compat.h:732
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define SetFilePointer
Definition: compat.h:743
#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 long DWORD
Definition: ntddk_ex.h:95
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
_In_ HANDLE hFile
Definition: mswsock.h:90
static const WCHAR szName[]
Definition: powrprof.c:45
HINSTANCE hInstance
Definition: precomp.h:43
_In_ LPCSTR lpFileName
Definition: winbase.h:3058
#define MB_OK
Definition: winuser.h:784
#define MB_ICONSTOP
Definition: winuser.h:797
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 TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#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:1670
UINT WINAPI EnumClipboardFormats(_In_ UINT)
int WINAPI CountClipboardFormats(void)
Definition: ntwrapper.h:184

Referenced by SaveClipboardToFile().