Thread: [Dev-C++] conversion from void *
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Carlos d. M. <cg...@wo...> - 2002-07-05 19:14:32
|
Hi: I am learning windows programing, and in great proportion of the examples I try to compile I get the error "ANSI C++ forbids implicit conversion from `void *' in argument passing", many times due to the 0 value passed in functions like CreateWindowEx, in the last parameter, what can I do for Mingw accept it? Some times I change 0 by NULL, but it does not work always, in such cases, what can I do? Thank you |
|
From: Hongli L. <h....@ch...> - 2002-07-05 20:16:55
|
On Fri, 2002-07-05 at 21:11, Carlos Garc=EDa del Monte wrote: > Hi: > I am learning windows programing, and in great proportion of the > examples I try to compile I get the error "ANSI C++ forbids implicit > conversion from `void *' in argument passing", many times due to the 0 > value passed in functions like CreateWindowEx, in the last parameter, > what can I do for Mingw accept it? Some times I change 0 by NULL, but it > does not work always, in such cases, what can I do? >=20 > Thank you >=20 That parameter expects a pointer. 0 is an integer. Since C++ is strict, you'll have to tell explicitly that 0 must be treated as a memory location (pointer). Something like this: CreateWindowEx (foo, bar, (void *) 0); |
|
From: Carlos d. M. <cg...@wo...> - 2002-07-06 11:01:50
|
Thanks, it works in some sites, but now I have found a place where it is a 0
in LoadImage, and it still says that, the parameter expected is an UINT, I do
everything but no way!
Here is the line:
_class.hIcon = reinterpret_cast<HICON> (
::LoadImage (_class.hInstance,
MAKEINTRESOURCE (resId),
IMAGE_ICON,
::GetSystemMetrics (SM_CXICON),
::GetSystemMetrics (SM_CYICON),
0));
I changed the first with _class.hIcon = ::LoadIcon(_class.hInstance,
MAKEINTRESOURCE(resId)); and it says the same error. The same if I put 1-1
instead of 0, or if I declare a UINT var = 0; and write var. I use the
LR_DEFAULTSIZE flag and still says that.
Here is the code of the full function where the two lines still have error
are:
void WinClass::SetResIcons (int resId)
{
UINT zero = 0;
_class.hIcon = reinterpret_cast<HICON> (
::LoadImage (
_class.hInstance,
MAKEINTRESOURCE (resId),
IMAGE_ICON,
::GetSystemMetrics (SM_CXICON),
::GetSystemMetrics (SM_CYICON),
0));
// Small icon can be loaded from the same resource
_class.hIconSm = reinterpret_cast<HICON> (
::LoadImage (
_class.hInstance,
MAKEINTRESOURCE (resId),
IMAGE_ICON,
::GetSystemMetrics (SM_CXSMICON),
::GetSystemMetrics (SM_CYSMICON),
0));
}
Borland 5.5 compiles fine, but I prefer Dev, it's more comfortable IDE than
those I found for Borland, with difference.
P.S.: Some times the error has lines where the error is unreadable characters.
|
|
From: Napoleon A. <nah...@so...> - 2002-07-06 16:40:28
|
Hi there, There solution to your problem can be found at http://www.relisoft.com/forum check Windows API Programming in C++. Below is an excerpt of the discussions that went on. ..... The hInstance member of _class is a HANDLE (that is, _class is a WNDCLASSEX, and WNDCLASSEX's 'hInstance' member is a HANDLE, not, as one might guess from it's name, an HINSTANCE). mingw does define HANDLE as a pointer to void. But LoadImage is looking for an honest-to-god HINSTANCE. There is also a solution on the forumwhich works fine on Dev-C++. Napoleon. ----- Original Message ----- From: "Carlos García del Monte" <cg...@wo...> To: "dev-cpp-users-list" <dev...@li...> Sent: Saturday, July 06, 2002 11:58 AM Subject: Re: [Dev-C++] conversion from void *(and is neither void nor pointer) > Thanks, it works in some sites, but now I have found a place where it is a 0 > in LoadImage, and it still says that, the parameter expected is an UINT, I do > everything but no way! > > Here is the line: > _class.hIcon = reinterpret_cast<HICON> ( > ::LoadImage (_class.hInstance, > MAKEINTRESOURCE (resId), > IMAGE_ICON, > ::GetSystemMetrics (SM_CXICON), > ::GetSystemMetrics (SM_CYICON), > 0)); > > I changed the first with _class.hIcon = ::LoadIcon(_class.hInstance, > MAKEINTRESOURCE(resId)); and it says the same error. The same if I put 1-1 > instead of 0, or if I declare a UINT var = 0; and write var. I use the > LR_DEFAULTSIZE flag and still says that. > Here is the code of the full function where the two lines still have error > are: > > void WinClass::SetResIcons (int resId) > { > UINT zero = 0; > _class.hIcon = reinterpret_cast<HICON> ( > ::LoadImage ( > _class.hInstance, > MAKEINTRESOURCE (resId), > IMAGE_ICON, > ::GetSystemMetrics (SM_CXICON), > ::GetSystemMetrics (SM_CYICON), > 0)); > // Small icon can be loaded from the same resource > _class.hIconSm = reinterpret_cast<HICON> ( > ::LoadImage ( > _class.hInstance, > MAKEINTRESOURCE (resId), > IMAGE_ICON, > ::GetSystemMetrics (SM_CXSMICON), > ::GetSystemMetrics (SM_CYSMICON), > 0)); > } > > Borland 5.5 compiles fine, but I prefer Dev, it's more comfortable IDE than > those I found for Borland, with difference. > > P.S.: Some times the error has lines where the error is unreadable characters. > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Got root? We do. > http://thinkgeek.com/sf > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.372 / Virus Database: 207 - Release Date: 20/06/02 |
|
From: Carlos d. M. <cg...@wo...> - 2002-07-11 18:30:32
|
Yes, it worked, thanks, and thanks too for your comment about this tutori= al, as a comment for those who can be interesting in beginning learning windows,= I feel it is a good way for preparing oneself to that kind of things, although I= thing it is not explanative enough, it's too superficial. I would recommend eye= the winprog tutorial (forger's) which explains the functions a bit more and t= hen see the reliable, while they (reliable) don't explain them a little more, tho= ugh reliable's tutorial can be enough for a starting. Naturally, for true learning, buy a book, online tutorials are only for g= et started. I agree you in that of know or not C before C++, you don't need c before = c++, but many people has a bad logical thought: they don't notice that after C= is easier learn C++ than learn C++ directly simply because the half is the s= ame, if you learn first C and then C++, when you're studying C++ you know yet the= half or more of what you're reading, but if you want only C++ and not need C, = why have to learn one and a half programming language? Learn just one, the on= e you need. At the same way we could say, if you want learn C, learn first C++, it's = the same case, when you study C after C++ you know yet more than a half of it= , it's more, C++ has more of C than C of C++, so it is faster the inverse way: Demonstration: Time for learning C alone: say four months. Time for learning C++ alone: Say five months (admit a little of confusion= is due to this difference in time of learning directly). Proportion of C++ inside C: 50% Proportion of C inside C++: 75% What to do from C to C++: change and add names and add capabilities. What to do from C++ to C++: change names and don't use some capabilities. First C and second C++: 4 moths learnig C + 5 * 0.50 (100 - 50%/100) =3D 4 + 2.5 =3D 6.5 months, = add 0.5 months for "take the feeling to object oriented programming" ^|= This is what remains unknown. Total: 7 months. First C++ and second C: 5 months learning C++ + 4 * 0.25 (100 - 75%/100) =3D 5 + 1 =3D 6 months. = You don't need add anything because the object oriented things are not needed, you = simply don't use them. Result: C++ -> C is one month faster than C -> C++. And the calculus has = been made to favour C->C++. Of course, and that is another thing, know both is better than only one, = so you have at your disposal some functions that perhaps in some moments could m= ake some things easier, but I think those would be rare, and there is nothing= you can't do with c++ but can with c, however there are things you can do wit= h C++ you cannot with C (object orienting), but you can simulate object orienti= ng with structs (I am not speaking about the effectivity of this), but how can yo= u simulate objects if you don't know them?. Napoleon Ahiable escribi=F3: > Hi there, > > There solution to your problem can be found at http://www.relisoft.com/= forum > check Windows API Programming in C++. Below is an excerpt of the discus= sions > that went on. > > ..... The hInstance member of _class is a HANDLE (that is, _class is a > WNDCLASSEX, and WNDCLASSEX's 'hInstance' member is a HANDLE, not, as on= e > might guess from it's name, an HINSTANCE). mingw does define HANDLE as= a > pointer to void. But LoadImage is looking for an honest-to-god HINSTAN= CE. > > There is also a solution on the forumwhich works fine on Dev-C++. > > Napoleon. > ----- Original Message ----- > From: "Carlos Garc=EDa del Monte" <cg...@wo...> > To: "dev-cpp-users-list" <dev...@li...> > Sent: Saturday, July 06, 2002 11:58 AM > Subject: Re: [Dev-C++] conversion from void *(and is neither void nor > pointer) > > > Thanks, it works in some sites, but now I have found a place where it= is a > 0 > > in LoadImage, and it still says that, the parameter expected is an UI= NT, I > do > > everything but no way! > > > > Here is the line: > > _class.hIcon =3D reinterpret_cast<HICON> ( > > ::LoadImage (_class.hInstance, > > MAKEINTRESOURCE (resId), > > IMAGE_ICON, > > ::GetSystemMetrics (SM_CXICON), > > ::GetSystemMetrics (SM_CYICON), > > 0)); > > > > I changed the first with _class.hIcon =3D ::LoadIcon(_class.hInstanc= e, > > MAKEINTRESOURCE(resId)); and it says the same error. The same if I pu= t 1-1 > > instead of 0, or if I declare a UINT var =3D 0; and write var. I use = the > > LR_DEFAULTSIZE flag and still says that. > > Here is the code of the full function where the two lines still have = error > > are: > > > > void WinClass::SetResIcons (int resId) > > { > > UINT zero =3D 0; > > _class.hIcon =3D reinterpret_cast<HICON> ( > > ::LoadImage ( > > _class.hInstance, > > MAKEINTRESOURCE (resId), > > IMAGE_ICON, > > ::GetSystemMetrics (SM_CXICON), > > ::GetSystemMetrics (SM_CYICON), > > 0)); > > // Small icon can be loaded from the same resource > > _class.hIconSm =3D reinterpret_cast<HICON> ( > > ::LoadImage ( > > _class.hInstance, > > MAKEINTRESOURCE (resId), > > IMAGE_ICON, > > ::GetSystemMetrics (SM_CXSMICON), > > ::GetSystemMetrics (SM_CYSMICON), > > 0)); > > } > > > > Borland 5.5 compiles fine, but I prefer Dev, it's more comfortable ID= E > than > > those I found for Borland, with difference. > > > > P.S.: Some times the error has lines where the error is unreadable > characters. > > > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by:ThinkGeek > > Got root? We do. > > http://thinkgeek.com/sf > > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.372 / Virus Database: 207 - Release Date: 20/06/02 |