[PATCH 2/2] [IcInfo]: no longer use stdio functions, but direct kernel32 ones
Eric Pouech
eric.pouech at orange.fr
Thu Nov 3 15:54:11 CDT 2011
(Also converts to Unicode)
#28188
A+
---
programs/icinfo/Makefile.in | 2 -
programs/icinfo/icinfo.c | 124 +++++++++++++++++++++++++++++++++----------
2 files changed, 97 insertions(+), 29 deletions(-)
diff --git a/programs/icinfo/Makefile.in b/programs/icinfo/Makefile.in
index cbd49f9..e6f6b95 100644
--- a/programs/icinfo/Makefile.in
+++ b/programs/icinfo/Makefile.in
@@ -1,6 +1,6 @@
EXTRADEFS = -DWINE_NO_UNICODE_MACROS
MODULE = icinfo.exe
-APPMODE = -mconsole
+APPMODE = -mconsole -municode
IMPORTS = msvfw32
C_SRCS = icinfo.c
diff --git a/programs/icinfo/icinfo.c b/programs/icinfo/icinfo.c
index 345f813..3f174f4 100644
--- a/programs/icinfo/icinfo.c
+++ b/programs/icinfo/icinfo.c
@@ -18,28 +18,98 @@
#include <stdio.h>
#include <string.h>
+#include <wine/unicode.h>
#include "windows.h"
#include "mmsystem.h"
#include "vfw.h"
+int mywprintf(const WCHAR *format, ...)
+{
+ static WCHAR* output_bufW = NULL;
+ static char* output_bufA = NULL;
+#define MAX_WRITECONSOLE_SIZE 65535
+ va_list parms;
+ DWORD nOut;
+ int len;
+ BOOL res = FALSE;
+ HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
+
+ if (!output_bufW && !(output_bufW = HeapAlloc(GetProcessHeap(), 0,
+ MAX_WRITECONSOLE_SIZE)))
+ return 0;
+
+ va_start(parms, format);
+ len = vsnprintfW(output_bufW, MAX_WRITECONSOLE_SIZE/sizeof(WCHAR), format, parms);
+ va_end(parms);
+ if (len < 0)
+ {
+ /* String too long */
+ return 0;
+ }
+
+ /* Try to write as unicode whenever we think it's a console */
+ if (((DWORD_PTR)hout & 3) == 3)
+ {
+ res = WriteConsoleW(hout, output_bufW, len, &nOut, NULL);
+ }
+ else
+ {
+ BOOL usedDefaultChar = FALSE;
+ DWORD convertedChars;
+
+ if (!output_bufA && !(output_bufA = HeapAlloc(GetProcessHeap(), 0,
+ MAX_WRITECONSOLE_SIZE)))
+ return 0;
+
+ /* Convert to OEM, then output */
+ convertedChars = WideCharToMultiByte(GetConsoleOutputCP(), 0, output_bufW, len,
+ output_bufA, MAX_WRITECONSOLE_SIZE,
+ "?", &usedDefaultChar);
+ res = WriteFile(hout, output_bufA, convertedChars, &nOut, FALSE);
+ }
+
+ return res ? nOut : 0;
+}
-int main(int argc, char* argv[])
+int wmain(int argc, WCHAR* argv[])
{
int i, n=0,doabout=0,doconfigure=0;
- char buf[128],type[5],handler[5];
+
+ static WCHAR header[] = {'C','u','r','r','e','n','t','l','y',' ','i','n','s','t','a','l','l','e','d',' ',
+ 'V','i','d','e','o',' ','C','o','m','p','r','e','s','s','o','r','s',':','\n',0};
+ static WCHAR close_flags[] = {')','\n',0};
+ static WCHAR s_fmt[] = {'%','s',0};
+ static WCHAR sspc_fmt[] = {'%','s',' ',0};
+ static WCHAR fcc_fmt[] = {'%','c','%','c','%','c','%','c','.','%','c','%','c','%','c','%','c',':',' ','%','s','\n',0};
+ static WCHAR desc_fmt[] = {'\t','s','z','D','e','s','c','r','i','p','t','i','o','n',':',' ','%','s','\n',0};
+ static WCHAR flags_fmt[] = {'\t','d','w','F','l','a','g','s',':',' ','0','x','%','0','8','x',' ','(',0};
+ static WCHAR version_fmt[] = {'\t','d','w','V','e','r','s','i','o','n',':',' ','0','x','%','0','8','x','\n',0};
+ static WCHAR versicm_fmt[] = {'\t','d','w','V','e','r','s','i','o','n','I','C','M',':',' ','0','x','%','0','8','x','\n',0};
+ static WCHAR VIDCF_QUALITY_W[] = {'V','I','D','C','F','_','Q','U','A','L','I','T','Y',0};
+ static WCHAR VIDCF_CRUNCH_W[] = {'V','I','D','C','F','_','C','R','U','N','C','H',0};
+ static WCHAR VIDCF_TEMPORAL_W[] = {'V','I','D','C','F','_','T','E','M','P','O','R','A','L',0};
+ static WCHAR VIDCF_COMPRESSFRAMES_W[] = {'V','I','D','C','F','_','C','O','M','P','R','E','S','S','F','R','A','M','E','S',0};
+ static WCHAR VIDCF_DRAW_W[] = {'V','I','D','C','F','_','D','R','A','W',0};
+ static WCHAR VIDCF_FASTTEMPORALC_W[] = {'V','I','D','C','F','_','F','A','S','T','T','E','M','P','O','R','A','L','C',0};
+ static WCHAR VIDCF_FASTTEMPORALD_W[] = {'V','I','D','C','F','_','F','A','S','T','T','E','M','P','O','R','A','L','D',0};
+ static WCHAR VIDCF_QUALITYTIME_W[] = {'V','I','D','C','F','_','Q','U','A','L','I','T','Y','T','I','M','E',0};
for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "-about"))
+ static WCHAR about[] = {'-','a','b','o','u','t','\0'};
+ static WCHAR configure[] = {'-','c','o','n','f','i','g','u','r','e','\0'};
+ static WCHAR unk_opt_fmt[] = {'U','n','k','n','o','w','n',' ','o','p','t','i','o','n',':',' ','%','s','\n',0};
+
+ if (!strcmpW(argv[i], about))
doabout = 1;
- else if (!strcmp(argv[i], "-configure"))
+ else if (!strcmpW(argv[i], configure))
doconfigure = 1;
else {
- printf("Unknown option: %s\n", argv[i]);
+ mywprintf(unk_opt_fmt, argv[i]);
return -1;
}
}
- printf("Currently installed Video Compressors:\n");
+ mywprintf(s_fmt, header);
while (1) {
ICINFO ii;
HIC hic;
@@ -53,28 +123,26 @@ int main(int argc, char* argv[])
ICClose(hic);
continue;
}
-#define w2s(w,s) WideCharToMultiByte(0,0,w,-1,s,128,0,NULL)
-
- w2s(ii.szName,buf);
- memcpy(type,&(ii.fccType),4);type[4]='\0';
- memcpy(handler,&(ii.fccHandler),4);handler[4]='\0';
- printf("%s.%s: %s\n",type,handler,buf);
- printf("\tdwFlags: 0x%08x (",ii.dwFlags);
-#define XX(x) if (ii.dwFlags & x) printf(#x" ");
- XX(VIDCF_QUALITY);
- XX(VIDCF_CRUNCH);
- XX(VIDCF_TEMPORAL);
- XX(VIDCF_COMPRESSFRAMES);
- XX(VIDCF_DRAW);
- XX(VIDCF_FASTTEMPORALC);
- XX(VIDCF_FASTTEMPORALD);
- XX(VIDCF_QUALITYTIME);
-#undef XX
- printf(")\n");
- printf("\tdwVersion: 0x%08x\n",ii.dwVersion);
- printf("\tdwVersionICM: 0x%08x\n",ii.dwVersionICM);
- w2s(ii.szDescription,buf);
- printf("\tszDescription: %s\n",buf);
+
+ mywprintf(fcc_fmt,
+ LOBYTE(ii.fccType),LOBYTE(ii.fccType>>8),LOBYTE(ii.fccType>>16),LOBYTE(ii.fccType>>24),
+ LOBYTE(ii.fccHandler),LOBYTE(ii.fccHandler>>8),LOBYTE(ii.fccHandler>>16),LOBYTE(ii.fccHandler>>24),
+ ii.szName);
+ mywprintf(flags_fmt,ii.dwFlags);
+
+ if (ii.dwFlags & VIDCF_QUALITY) mywprintf(sspc_fmt, VIDCF_QUALITY_W);
+ if (ii.dwFlags & VIDCF_CRUNCH) mywprintf(sspc_fmt, VIDCF_CRUNCH_W);
+ if (ii.dwFlags & VIDCF_TEMPORAL) mywprintf(sspc_fmt, VIDCF_TEMPORAL_W);
+ if (ii.dwFlags & VIDCF_COMPRESSFRAMES) mywprintf(sspc_fmt, VIDCF_COMPRESSFRAMES_W);
+ if (ii.dwFlags & VIDCF_DRAW) mywprintf(sspc_fmt, VIDCF_DRAW_W);
+ if (ii.dwFlags & VIDCF_FASTTEMPORALC) mywprintf(sspc_fmt, VIDCF_FASTTEMPORALC_W);
+ if (ii.dwFlags & VIDCF_FASTTEMPORALD) mywprintf(sspc_fmt, VIDCF_FASTTEMPORALD_W);
+ if (ii.dwFlags & VIDCF_QUALITYTIME) mywprintf(sspc_fmt, VIDCF_QUALITYTIME_W);
+
+ mywprintf(s_fmt, close_flags);
+ mywprintf(version_fmt,ii.dwVersion);
+ mywprintf(versicm_fmt,ii.dwVersionICM);
+ mywprintf(desc_fmt,ii.szDescription);
if (doabout) ICAbout(hic,0);
if (doconfigure && ICQueryConfigure(hic))
ICConfigure(hic,0);
More information about the wine-patches
mailing list