HWND and HDC problem...

Started by
11 comments, last by Metal Typhoon 21 years, 9 months ago
about he print funciton nehe did... he didn;t explain what an argument is and he said he was... i never use stdarg.h... va_list as variable type ?? .... please can u make it clear ?
Metal Typhoon
Advertisement
What you want to do is call your Print function with any number of arguments, like so:

Print("This %s is %d", str, 10);

Now can you retrieve all arguments and combine them with the format string? vsprintf does just that. It takes three parameters: destination string, format string, and the va_list pointer. That pointer points to the first argument that your Print function received. As vsprintf goes throught the format string, it reads the current argument and advances va_list pointer to the next one. To put it differently, va_list is sort of a pointer into an array of function arguments. The exact workings of va_list are pretty complicated, and you don''t have to know them if you don''t want to. Just remember that vsprintf takes a va_list that points to your arguments and converts them to string.

How can you point a variable of type va_list to the arguments? You use va_start macro. It takes two arguments: the va_list variable to initialize and the last known parameter to your function. All parameters are placed in the stack one after another, and knowing the last parameter you can advance to the memory where the first variable parameter is stored.

Once you initialized a va_list variable with a call to va_start, you can pass it to vsprintf and you''ll have a formatted string.

va_end is supposed to clean up va_list, but I haven''t seen an implementation in which va_end does something useful. Just call it after you''re done with the va_list variables.

va_list is a variable type, more exactly, it''s a disguised pointer.
---visit #directxdev on afternet <- not just for directx, despite the name
There''s a load of info about variable arguments in MSDN. Just pop the word va_list into the index and enjoy. It also has info on all Win32 API functions like CreateFont.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

This topic is closed to new replies.

Advertisement