how do I printf a long? Shouldn't this work? %li

You didn't even provide which number you wanted to print, but I guess you've stumbled over the difference between signed and unsigned printing.

Use "%lu" for unsigned long numbers, and "%ld" or "%li" for signed long numbers.

The MSDN has good documentation on printf specifiers. For 64-bit values (like long long, for example), you should use the macros in "inttypes.h".


You are trying to print an HRESULT, the error code for "access denied". That is best formatted in hex, at least to be easily recognizable to a programmer and the Google query box.

printf("0x%08lx", hr);

Now you'll instantly recognize the facility code 7 (Windows API) and the error code 5 (access denied).

Tags:

C

Printf