NO

Author Topic: warning #2235 ??  (Read 3609 times)

Vbxler

  • Guest
warning #2235 ??
« on: August 11, 2009, 05:38:47 PM »
Hi,

I use this function:

Code: [Select]
HINSTANCE hinstLib;

//------------------------------------------------------
// Laden der DLL
//------------------------------------------------------
int Load_DLL(char *szDLL)
{
//laden der DLL
hinstLib = LoadLibrary(szDLL);

//wenn laden erfolgreich, dann True
if (hinstLib != NULL) return 1;
}
I can compile, but get the message: warning #2235: Not all control paths return a value.
How can I prevent that?

Thank you very much.

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: warning #2235 ??
« Reply #1 on: August 11, 2009, 05:54:40 PM »
Adding a return value for the case that hinstLib == NULL...

You only return a value when loading of the DLL was successful, if, not, the return value is undefined...

Ralf

Vbxler

  • Guest
Re: warning #2235 ??
« Reply #2 on: August 13, 2009, 03:39:06 PM »
Thank you very much!

It's not so easy when you come from VB.  :)

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: warning #2235 ??
« Reply #3 on: August 18, 2009, 07:25:39 AM »
Thank you very much!
Kein Problem, gern geschehen!  ;)
Quote
It's not so easy when you come from VB.  :)
If VB is compiling this without an error, it is even worse of a compiler as commonly  assumed.

It's a very general, logical programming error, leaving the function result undefined if the DLL load wasn't successful. This should generate at least a warning in all compilers...

And then C has a bad reputation for promoting bad programming practices...  :P

Ralf