Help!

Just starting out? Need help? Post your questions and find answers here.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Help!

Post by Psychophanta »

I have a question.

How can i do that a function is not compiled when my compiled program is executed under Windows NT 4.0?

The matter is that AnimateWindow_() MSWindows API function is not available in Windows NT (and maybe W95 neither), so i must use something like CompilerIf - CompilerEndIf part.

But CompilerIf command doesn't admit a variable, but only a constant:

Code: Select all

CompilerIf OSVersion()<>#PB_OS_Windows_NT_4
or similar doesn't work

And course, i can't do:

Code: Select all

if OSVersion=#PB_OS_Windows_NT_4
#OSV=0
else
#OSV=1
endif
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: Help!

Post by tinman »

Psychophanta wrote:How can i do that a function is not compiled when my compiled program is executed under Windows NT 4.0?
You cannot. Compile-time is when the executable is created, and has no knowledge of what happens when your program is executed.

You need to use a normal If...Else...EndIf structure to stop code being executed if the OS version is not suitable.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Help!

Post by PB »

Just do this for the time being (I know it isn't what you want, but at least
your app can do different things depending on the OS being used):

Code: Select all

If OSVersion()=#PB_OS_Windows_98
  Debug "You are running Windows 98!"
Else
  Debug "You are NOT running Windows 98."
EndIf
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Oh, impossible too, i tried it calling to AW() instead:

Code: Select all

Procedure AW(wi,b,c)
  If OSVersion=#PB_OS_Windows_NT_4
    If c&#AW_HIDE:ShowWindow_(wi,#SW_HIDE):Else:ShowWindow_(wi,#SW_SHOW):EndIf
  Else
    AnimateWindow_(wi,b,c)
  EndIf
EndProcedure
but when executable is runned under WinNT, this say that AnimateWindow() function is not available, and program is sharply terminated at the beginning.
It is because the function was compiled in the final code.

It seem not possible. :cry:
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

A placeholder for the Function will be compiled in the exe, the function
itself is inside a dll of the OS (in this case it is user32.dll)

You can call the function directly in the dll, so this placeholder won't be
compiled, and it should run.

Like this:

Code: Select all

Procedure AW(wi,b,c) 
  If OSVersion=#PB_OS_Windows_NT_4 
    If c&#AW_HIDE:ShowWindow_(wi,#SW_HIDE):Else:ShowWindow_(wi,#SW_SHOW):EndIf 
  Else
    If OpenLibrary(0, "user32.dll") And IsFunction(0,  "AnimateWindow")
      CallFunction(0, "AnimateWindow", wi, b, c)
      CloseLibrary(0)
    Else ; In case something went wrong...
      If c&#AW_HIDE:ShowWindow_(wi,#SW_HIDE):Else:ShowWindow_(wi,#SW_SHOW):EndIf 
    EndIf 
  EndIf 
EndProcedure 
Timo
quidquid Latine dictum sit altum videtur
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

So, i change the question:

It is possible to detect if a certain function is available in any lib in the system before call it?
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

That's what the IsFunction() in my example allready does.

Timo
quidquid Latine dictum sit altum videtur
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Thank you, thank you, Timo. Great!

Moreover, you have answered my question.

I don't know how i didn't think about OpenLibrary(), because i have used a lot before. Brrrr :x


Now i got the good solution. :wink:
Post Reply