Please help with this error!!

Ok so im trying to create an console program that opens a website, but i get an error saying:
"Run-Time Check Failure #3 - The variable 'Handle' is being used without being initialized."

And heres the code of the program:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include "stdafx.h"
#include <iostream>
#include <windows.h>

int main()
{
HWND Handle;
ShellExecute(Handle,
"open",
"http://www.youtube.com/",
NULL,NULL,SW_SHOWDEFAULT);
return 0;
}


Thanks if someone can help me! :D
What is the problem? You can not understand the phrase "The variable 'Handle' is being used without being initialized."?! If so you shall not do programming.

Last edited on
no sry.. im a beginner
Works perfectly fine for me?
Well when i debug it. I need to click ignore to run it. But when i open the .exe file from my debug folder. I cant run it cos of the error.
Last edited on
You use variable Handle as an argument in the function call

ShellExecute(Handle,
"open",
"http://www.youtube.com/",
NULL,NULL,SW_SHOWDEFAULT);

but the variable has undefined value because it was not initialized.
thanks for trying to help but my problem is i have no idea what "argument" and "initialized" means in c++..
Last edited on
Maybe you need to learn the basics of C++ before trying to use the Windows API?

Edit: And argument is a command passed to a function, in your case, the function would be ShellExecute() and Handle, "open", "http://www.youtube.com/", NULL, NULL, SW_SHOWDEFAULT" are all arguments

Initializing a variable is assigning a value to that variable. You "declared" HWND Handle but never gave it a value.
Last edited on
Oh, now i get it wheres the problem :)

{
HWND Handle;
Handle = NULL;
ShellExecute(Handle,
"open",
"http://www.youtube.com/",
NULL,NULL,SW_SHOWDEFAULT);
return 0;
}

Thanks for the help guys! :)
Last edited on
@yge3d
thanks for trying to help but my problem is i have no idea what "argument" and "initialized" means in c++..


If you have no idea what argument and initialization mean then why do you deal with this code?!
HWND is a data type that holds a "handle" to a window.

This value is usually given when you call a create window function.
Topic archived. No new replies allowed.