ReactOS 0.4.16-dev-289-g096a551
clip.c File Reference
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <winuser.h>
#include <conutils.h>
#include "resource.h"
Include dependency graph for clip.c:

Go to the source code of this file.

Functions

VOID PrintError (DWORD dwError)
 
static BOOL IsDataUnicode (HGLOBAL hGlobal)
 
int wmain (int argc, wchar_t **argv)
 

Function Documentation

◆ IsDataUnicode()

static BOOL IsDataUnicode ( HGLOBAL  hGlobal)
static

Definition at line 28 of file clip.c.

29{
30 BOOL bReturn;
32
33 lpBuffer = GlobalLock(hGlobal);
34 bReturn = IsTextUnicode(lpBuffer, GlobalSize(hGlobal), NULL);
35 GlobalUnlock(hGlobal);
36
37 return bReturn;
38}
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define NULL
Definition: types.h:112
BOOL WINAPI IsTextUnicode(IN CONST VOID *lpv, IN INT iSize, IN OUT LPINT lpiResult OPTIONAL)
Definition: unicode.c:27
unsigned int BOOL
Definition: ntddk_ex.h:94
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
SIZE_T NTAPI GlobalSize(HGLOBAL hMem)
Definition: heapmem.c:1090

Referenced by wmain().

◆ PrintError()

VOID PrintError ( DWORD  dwError)

Definition at line 19 of file clip.c.

20{
21 if (dwError == ERROR_SUCCESS)
22 return;
23
25 NULL, dwError, LANG_USER_DEFAULT);
26}
#define StdErr
Definition: fc.c:15
#define ERROR_SUCCESS
Definition: deptool.c:10
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:837
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:449

Referenced by wmain().

◆ wmain()

int wmain ( int  argc,
wchar_t **  argv 
)

Definition at line 40 of file clip.c.

41{
42 HANDLE hInput;
43 DWORD dwBytesRead;
44 BOOL bStatus;
45 HGLOBAL hBuffer;
46 HGLOBAL hTemp;
48 SIZE_T dwSize = 0;
49
50 /* Initialize the Console Standard Streams */
53
54 /* Check for usage */
55 if (argc > 1 && wcsncmp(argv[1], L"/?", 2) == 0)
56 {
58 return 0;
59 }
60
61 if (GetFileType(hInput) == FILE_TYPE_CHAR)
62 {
64 return 0;
65 }
66
67 /* Initialize a growable buffer for holding clipboard data */
68 hBuffer = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, 4096);
69 if (!hBuffer)
70 goto Failure;
71
72 /*
73 * Read data from the input stream by chunks of 4096 bytes
74 * and resize the buffer each time when needed.
75 */
76 do
77 {
78 lpBuffer = GlobalLock(hBuffer);
79 if (!lpBuffer)
80 goto Failure;
81
82 bStatus = ReadFile(hInput, lpBuffer + dwSize, 4096, &dwBytesRead, NULL);
83 dwSize += dwBytesRead;
84 GlobalUnlock(hBuffer);
85
86 hTemp = GlobalReAlloc(hBuffer, GlobalSize(hBuffer) + 4096, GMEM_ZEROINIT);
87 if (!hTemp)
88 goto Failure;
89
90 hBuffer = hTemp;
91 }
92 while (bStatus && dwBytesRead > 0);
93
94 /*
95 * Resize the buffer to the total size of data read.
96 * Note that, if the call fails, we still have the old buffer valid.
97 * The old buffer would be larger than the actual size of data it contains,
98 * but this is not a problem for us.
99 */
100 hTemp = GlobalReAlloc(hBuffer, dwSize + sizeof(WCHAR), GMEM_ZEROINIT);
101 if (hTemp)
102 hBuffer = hTemp;
103
104 /* Attempt to open the clipboard */
105 if (!OpenClipboard(NULL))
106 goto Failure;
107
108 /* Empty it, copy our data, then close it */
109
111
112 if (IsDataUnicode(hBuffer))
113 {
115 }
116 else
117 {
118 // TODO: Convert text from current console page to standard ANSI.
119 // Alternatively one can use CF_OEMTEXT as done here.
121 }
122
124 return 0;
125
126Failure:
127 if (hBuffer) GlobalFree(hBuffer);
129 return -1;
130}
static int argc
Definition: ServiceArgs.c:12
#define IDS_HELP
Definition: resource.h:3
#define IDS_USAGE
Definition: resource.h:3
VOID PrintError(DWORD dwError)
Definition: clip.c:19
static BOOL IsDataUnicode(HGLOBAL hGlobal)
Definition: clip.c:28
#define ConInitStdStreams()
Definition: fc.c:13
#define StdOut
Definition: fc.c:14
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define CF_UNICODETEXT
Definition: constants.h:408
#define CF_OEMTEXT
Definition: constants.h:402
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
DWORD WINAPI GetFileType(HANDLE hFile)
Definition: fileinfo.c:269
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
HGLOBAL NTAPI GlobalReAlloc(HGLOBAL hMem, SIZE_T dwBytes, UINT uFlags)
Definition: heapmem.c:825
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define argv
Definition: mplay32.c:18
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
unsigned char * LPBYTE
Definition: typedefs.h:53
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define STD_INPUT_HANDLE
Definition: winbase.h:293
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GMEM_ZEROINIT
Definition: winbase.h:332
#define FILE_TYPE_CHAR
Definition: winbase.h:286
#define GMEM_MOVEABLE
Definition: winbase.h:320
HANDLE WINAPI SetClipboardData(_In_ UINT, _In_opt_ HANDLE)
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
BOOL WINAPI EmptyClipboard(void)
Definition: ntwrapper.h:190
__wchar_t WCHAR
Definition: xmlstorage.h:180