RtlStringCbPrintA with PCHAR

Hello all,

I have a problem using RtlStringCbPrintfA when using dynamic allocation. Here is my example :

PCHAR buffer;
NTSTATUS ntStatus;

buffer = (PCHAR)ExAllocatePoolWithtag(NonPagedPool, 100, ‘0uel’);
ntStatus = RtlStringCbPrintfA(buffer, 100, “hello there %s”, string);
if (NT_SUCCESS(ntStatus))
{
ntStatus = ZwWriteFile(hFile, NULL, NULL, NULL, &ioStatusBlock, buffer, 100, NULL, NULL);
}

It seems to not work when using dynamic allocation. But when I declare the buffer staticaly as buffer[512] for example, it works. I think it’s the problem when passing from CHAR to PCHAR in the example.

What do you think ?

Thank you in advance.

Found the problem.
It was in the length of the pool allocated as it wasn’t actually what I gave above. That’s why It never gets to the ZwWriteFile function.
But the example giving above is working x)