[PATCH] reg.exe: Modernise print functions

Hugh McMaster hugh.mcmaster at outlook.com
Mon Nov 10 06:10:12 CST 2014


On Monday, 10 November 2014, Jonathan Vollebregt wrote:
>> WCHAR msg_buffer[1024];

>No easy way to get the expected size and dynamically allocate the output I take it?

>I looked into it before but besides _vscprintf (In msvcrt, which we're 
>not allowed to use) there doesn't seem to be a way to get the expected 
>output size besides perhaps growing the buffer over and over again until 
>it fits (Which seems inefficient for a simple printing function)

One possible way would be to avoid using vsnprintfW() and pass everything through to output_vprintf().

static void __cdecl reg_printfW(const WCHAR* msg, ...)
{
    __ms_va_list va_args;

    __ms_va_start(va_args, msg);
    output_vprintf(msg, va_args);
    __ms_va_end(va_args);
}

This would have the advantage of using FormatMessage() to allocate memory. But we would have to replace all format specifiers (four or five?) with their FormatMessage() equivalents.

static const WCHAR unhandled[] = {'U','n','h','a','n','d','l','e','d',' ','T','y','p','e',' ','0','x','%','x',' ',' ','d','a','t','a',' ','%','s','\n',0};

becomes

static const WCHAR unhandled[] = {'U','n','h','a','n','d','l','e','d',' ','T','y','p','e',' ','0','x','%','1','!','x','!',' ',' ','d','a','t','a',' ','%','2','\n',0};


 		 	   		  


More information about the wine-devel mailing list