InsertRow uses the va_start macro to assign a pointer (arguments) to the first parameter on the stack. Next, the function uses the va_arg macro to get the values one at a time. The va_arg macro returns a value of the specified type and then increments the pointer (arguments) to point to the next item. When the pointer encounters a NULL terminator, the function uses the va_end macro to assign a value to the pointer that prevents the future use of the pointer. That is until va_start reinitializes the pointer again.
An example follows:
Code:
#include <windows.h>
#include <stdio.h>
void InsertRow(HWND hwnd, char *col1, char *col, ...)
{
LPCTSTR pMsg;
va_list arguments;
printf("%s\n", col1);
printf("%s\n", col);
va_start (arguments, col);
while ((pMsg = va_arg (arguments, LPCTSTR)) != NULL)
printf("%s\n", pMsg);
va_end (arguments);
}
int main(void)
{
InsertRow(NULL,"col1A", "Test1", "Test2", "Test3", NULL);
InsertRow(NULL,"col1B", "Test4", NULL);
InsertRow(NULL,"col1C", "Test5", "Test6", "Test7", "Test8", "Test9", "Test10", NULL);
return 0;
}