I'm writing a low-level logger function that appends text string to the end of a text (log) file. The requirement is that this function should not invoke any WinAPIs from DLLs that may not be yet available for the process -- such as when it's called from a DllMain handler. In other words, it can't use any libraries other than the ones that are guaranteed to be loaded into any user-mode process, i.e. kernel32.dll
or ntdll.dll
.
I was able to get by quite nicely with just CreateFile
, WriteFile
, CloseHandle
, HeapAlloc
, HeapFree
, etc. that are all from kernel32.dll
.
The issue is formatting the output string. For instance, I need to add some additional (automatically generated) details, such as current time, process ID, session ID, etc. I would normally use wsprintf
type function for that, or StringCchPrintf
to be exact, as such:
StringCchPrintf(buffer, buffer_size, L"%04u-%02u-%02u %02u:%02u:%02u pid=0x%x, sessID=%d, %s\r\n", /* parameters */ );
but those APIs violate the rule I noted above.
Does anyone know if there's a low level printf
type formatting API available?