Initialzing structs from Windows API.

Hello all,

I am having a bit of a problem working with very simple c++ rules regarding the Windows API functions.

I understand why a struct must be initialized but am having problems doing so using the Windows API's.

Now if you look where I am using the ZeroMemory() function, I was just trying to make things work.

I know that normally the syntax is something along these lines for initializing your structs size:

PROCESS_INFORMATION pi = sizeof(PROCESS_INFORMATION);

or

PROCESS_INFORMATION pi = sizeof(STRUCTURE HERE); // Pseudo'ish


So can anyone provide me the clarification on correctly initializing any structs size so I can continue reading my book and working through the examples? It seems every example I run into the compiler keeps telling me I am doing things wrong. When I search on the MSDN, I rarely find the answer I am looking for. Thanks to all in advance for the clarification.

Oh by the way, this code is giving me an error 87, which is ERROR_INVALID_PARAMETER "The parameter is incorrect."

Here is my code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <Windows.h>
#include <iostream>
#include "Utilities.h"

using namespace std;

void main()
{
	Util::Utilities ut;
	PROCESS_INFORMATION pi;

	ZeroMemory(&pi, sizeof(&pi));

	CreateProcess((LPCWSTR)"f:\program files\ventrilo.exe",
				  NULL,
				  NULL,
				  NULL,
				  TRUE,
				  CREATE_NO_WINDOW,
				  NULL,
				  NULL,
				  NULL,
				  &pi);
				  
	cout << GetLastError() << endl;

	ut.wait();
}



Last edited on
The backslash in C and C++ string literals are escape characters. If you want a single backslash, you must write two backslashes. Then the cast you do is awful. The Windows SDK provides the TEXT() macro. Use it.

And I see no problem in your use of ZeroMemory().

EDIT: I see a BIG problem in your use of ZeroMemory(). :P hehe. Sorry.

ZeroMemory(&pi, sizeof(pi));

See the difference?
Last edited on
Yes I see the difference and thank you very much.

I also knew about the escape characters as well and can't believe I made such a rookie mistake. It's probably because I was reading a book and the MSDN and I lost my train of thought. The MSDN is great at doing that to me as I branch off to 50 other links.
Topic archived. No new replies allowed.