문제

Background:

My application ships without a CRT as it MUST be portable and small.

Problem:

When I run my application on a Virtual Machine for Windows XP, my CreateProcess() function fails, I need to display the GetLastError() DWORD in a MessageBox() without using any of the CRT,

How can I manually implement sprintf() function in my program to convert the DWORD type to a char buffer to display in the MessageBox() function to get the error type, so I can therefore fix the problem.

I have implemented my own memset() function like so

extern "C" void * __cdecl memset(void *, int, size_t);


#pragma function(memset)
void * __cdecl memset(void *pTarget, int value, size_t cbTarget) {
unsigned char *p = static_cast<unsigned char *>(pTarget);
while (cbTarget-- > 0) {
    *p++ = static_cast<unsigned char>(value);
}
return pTarget;
}

I am unsure of how to implement a custom sprintf() function

Thank you

도움이 되었습니까?

해결책 2

If speed is not what you'd concern, you can use RtlMoveMemory and wsprintf supplied by kernel32.dll for memcpy(memmove) and sprintf (Not actually THAT slow, just cannot do link time optimization).

다른 팁

wsprintf is available in Windows, event without a CRT. Just #include windows.h

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top