ReactOS  0.4.12-dev-102-g4b7f1e0
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.

Referenced by ClipboardReadMemory(), ReadClipboardFile(), and WriteClipboardFile().

◆ CLIP_FMT_BK

#define CLIP_FMT_BK   0xC352

Definition at line 14 of file fileutils.h.

Referenced by ClipboardReadMemory(), ReadClipboardFile(), and WriteClipboardFile().

◆ CLIP_FMT_NT

#define CLIP_FMT_NT   0xC351

◆ MAX_FMT_NAME_LEN

#define MAX_FMT_NAME_LEN   79

Definition at line 16 of file fileutils.h.

Referenced by UpdateDisplayMenu().

Typedef Documentation

◆ CLIPFILEHEADER

◆ CLIPFORMATHEADER

◆ NTCLIPFILEHEADER

◆ NTCLIPFORMATHEADER

Function Documentation

◆ ReadClipboardFile()

void ReadClipboardFile ( LPCWSTR  lpFileName)

Definition at line 275 of file fileutils.c.

Referenced by LoadClipboardDataFromFile().

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;
290  PVOID szName;
291 
292  HANDLE hFile;
293  DWORD dwBytesRead;
294  BOOL bResult;
295  int i;
296 
297  /* Open the file for read access */
300  if (hFile == INVALID_HANDLE_VALUE)
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 */
337  SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
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 
408  case CF_DSPMETAFILEPICT:
409  case CF_METAFILEPICT:
410  {
411  bResult = ClipboardReadMetafile(hFile, dwOffData, dwLenData);
412  break;
413  }
414 
415  case CF_DSPENHMETAFILE:
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 
442 done:
443  if (hFile != INVALID_HANDLE_VALUE)
444  CloseHandle(hFile);
445 
446  return;
447 }
#define CloseHandle
Definition: compat.h:398
#define INVALID_SET_FILE_POINTER
Definition: winbase.h:115
#define CF_ENHMETAFILE
Definition: constants.h:409
#define CF_DSPMETAFILEPICT
Definition: constants.h:416
static BOOL ClipboardReadEnhMetafile(HANDLE hFile, DWORD dwOffset, DWORD dwLength)
Definition: fileutils.c:195
struct _NTCLIPFILEHEADER NTCLIPFILEHEADER
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define assert(x)
Definition: debug.h:53
#define MB_ICONSTOP
Definition: winuser.h:797
#define CF_METAFILEPICT
Definition: constants.h:398
#define CLIP_FMT_NT
Definition: fileutils.h:13
#define FILE_SHARE_READ
Definition: compat.h:125
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
void ShowLastWin32Error(HWND hwndParent)
Definition: winutils.c:11
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define CLIP_FMT_31
Definition: fileutils.h:12
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define CF_OWNERDISPLAY
Definition: constants.h:413
#define ERROR_INVALID_FILE_FORMAT
Definition: resources.h:47
#define CF_DSPENHMETAFILE
Definition: constants.h:417
#define CF_BITMAP
Definition: constants.h:397
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
int MessageBoxRes(HWND hWnd, HINSTANCE hInstance, UINT uText, UINT uCaption, UINT uType)
Definition: winutils.c:49
static BOOL ClipboardReadPalette(HANDLE hFile, DWORD dwOffset, DWORD dwLength)
Definition: fileutils.c:116
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CF_DSPBITMAP
Definition: constants.h:415
struct _CLIPFORMATHEADER CLIPFORMATHEADER
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define CF_PALETTE
Definition: constants.h:404
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
#define FILE_BEGIN
Definition: winbase.h:112
static BOOL ClipboardReadBitmap(HANDLE hFile, DWORD dwOffset, DWORD dwLength)
Definition: fileutils.c:234
struct _NTCLIPFORMATHEADER NTCLIPFORMATHEADER
#define MB_OK
Definition: winuser.h:784
#define CreateFileW
Definition: compat.h:400
static const WCHAR szName[]
Definition: msipriv.h:1194
#define CF_PRIVATEFIRST
Definition: constants.h:418
#define CLIP_FMT_BK
Definition: fileutils.h:14
static BOOL ClipboardReadMemory(HANDLE hFile, DWORD dwFormat, DWORD dwOffset, DWORD dwLength, WORD FileIdentifier, PVOID lpFormatName)
Definition: fileutils.c:47
HINSTANCE hInstance
Definition: precomp.h:43
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
static BOOL ClipboardReadMetafile(HANDLE hFile, DWORD dwOffset, DWORD dwLength)
Definition: fileutils.c:156
_In_ LPCSTR lpFileName
Definition: winbase.h:3011
#define CF_PRIVATELAST
Definition: constants.h:419
struct _CLIPFILEHEADER CLIPFILEHEADER

◆ WriteClipboardFile()

void WriteClipboardFile ( LPCWSTR  lpFileName,
WORD  wFileIdentifier 
)

Definition at line 449 of file fileutils.c.

Referenced by SaveClipboardToFile().

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 
465  HANDLE hFile;
466  DWORD dwBytesWritten;
467  int i;
468 
469  /* Create the file for write access */
472  if (hFile == INVALID_HANDLE_VALUE)
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 */
510  SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
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 
581 Cont:
582  i++;
583  dwFormatID = EnumClipboardFormats(dwFormatID);
584  }
585 
586 done:
587  if (hFile != INVALID_HANDLE_VALUE)
588  CloseHandle(hFile);
589 
590  return;
591 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define INVALID_SET_FILE_POINTER
Definition: winbase.h:115
WORD wFileIdentifier
Definition: fileutils.h:42
struct _NTCLIPFILEHEADER NTCLIPFILEHEADER
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define assert(x)
Definition: debug.h:53
#define ZeroMemory
Definition: winbase.h:1635
#define MB_ICONSTOP
Definition: winuser.h:797
#define CLIP_FMT_NT
Definition: fileutils.h:13
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
void ShowLastWin32Error(HWND hwndParent)
Definition: winutils.c:11
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define CLIP_FMT_31
Definition: fileutils.h:12
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define ERROR_INVALID_FILE_FORMAT
Definition: resources.h:47
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
int MessageBoxRes(HWND hWnd, HINSTANCE hInstance, UINT uText, UINT uCaption, UINT uType)
Definition: winutils.c:49
WORD wFileIdentifier
Definition: fileutils.h:24
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
void RetrieveClipboardFormatName(HINSTANCE hInstance, UINT uFormat, BOOL Unicode, PVOID lpszFormat, UINT cch)
Definition: cliputils.c:95
struct _CLIPFORMATHEADER CLIPFORMATHEADER
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
UINT WINAPI EnumClipboardFormats(_In_ UINT)
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
WORD wFormatCount
Definition: fileutils.h:25
_In_ HANDLE hFile
Definition: mswsock.h:90
#define CREATE_ALWAYS
Definition: disk.h:72
#define FILE_BEGIN
Definition: winbase.h:112
struct _NTCLIPFORMATHEADER NTCLIPFORMATHEADER
#define MB_OK
Definition: winuser.h:784
static BOOL ClipboardWriteMemory(HANDLE hFile, DWORD dwFormat, DWORD dwOffset, PDWORD pdwLength)
Definition: fileutils.c:83
#define CreateFileW
Definition: compat.h:400
static const WCHAR szName[]
Definition: msipriv.h:1194
#define CLIP_FMT_BK
Definition: fileutils.h:14
HINSTANCE hInstance
Definition: precomp.h:43
int WINAPI CountClipboardFormats(void)
Definition: ntwrapper.h:184
_In_ LPCSTR lpFileName
Definition: winbase.h:3011
struct _CLIPFILEHEADER CLIPFILEHEADER