When I try to compile this:
unsigned char MyArray;
I get a program that crashes when I run it. When I look at the dissassembly in OllyDbg, it turns out that what's happening is that in the WriteFile line of code, it's passing the value stored in BytesWritten, rather than its memory address, even though BytesWritten has been declared with LPDWORD, and even though LPDWORD has by defined (via typedef) as a pointer. When a pointer type variable is passed it should be passing the memory address, not the value stored there, but passing the value stored there is EXACTLY what's happening. The ONLY time that the value stored at a pointer should be passed is when you prefface that pointer with an asterisk. If I have a variable declared like this:
Every time I use that pointer, including passing it as a parameter in a function as just MyPtr, it SHOULD be passing the memory address, not the value stored there. The ONLY time that it should it should be using the value stored in a pointer-type variable there is if I am using an astrisk with it, like this:
As you can see from the above code sample, my pointer-type variable is being passed in such a way that it should be passing the ADDRESS to the function, NOT passing the value, yet passing the value is exactly what's happening, as I can tell by running the program in a debugger.