Please help with this error!!

Jun 12, 2012 at 6:44pm
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
Jun 12, 2012 at 6:46pm
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 Jun 12, 2012 at 6:48pm
Jun 12, 2012 at 6:47pm
no sry.. im a beginner
Jun 12, 2012 at 6:47pm
Works perfectly fine for me?
Jun 12, 2012 at 6:49pm
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 Jun 12, 2012 at 6:50pm
Jun 12, 2012 at 6:50pm
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.
Jun 12, 2012 at 6:53pm
thanks for trying to help but my problem is i have no idea what "argument" and "initialized" means in c++..
Last edited on Jun 12, 2012 at 6:54pm
Jun 12, 2012 at 7:00pm
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 Jun 12, 2012 at 7:03pm
Jun 12, 2012 at 7:15pm
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 Jun 12, 2012 at 7:16pm
Jun 12, 2012 at 7:17pm
@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?!
Jun 12, 2012 at 7:17pm
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.