Results 1 to 6 of 6

Thread: [Resolved] Compiler Directives

  1. #1

    Thread Starter
    Hyperactive Member Quiver318's Avatar
    Join Date
    Sep 2007
    Posts
    260

    [Resolved] Compiler Directives

    I am using VB6 SP6, and I am wondering if anyone knows if there is a way to conditionally declare an API depending on which OS you happen to be running.

    I have seen compiler directives placed in the general declarations area of a form that is platform specific, but they seem to differentiate between 32 bit and 16 bit platforms, and not between an OS like XP versus Vista. I would like to include a delcaration for one OS, but exclude it in another. Any ideas?

    If have been unclear about compiler directives, they look like this in VB6:
    Code:
    #If Win32 Then 
        Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    #End If
    Last edited by Quiver318; Apr 18th, 2009 at 06:42 PM. Reason: Closing Thread

  2. #2
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Compiler Directives

    >Any Ideas

    Nope!

    However, you could code your program to look for which OS version and based upon that execute optional code.

    Good Luck
    Option Explicit should not be an Option!

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Compiler Directives

    The only built-in conditional compilation constants are Win16, Win32, and Vba6.

    You can make up your own though, like WinXP, WinVista. Then you set these in the Project Properties dialog or on the VB6.EXE command line to compile different versions.

  4. #4

    Thread Starter
    Hyperactive Member Quiver318's Avatar
    Join Date
    Sep 2007
    Posts
    260

    Re: Compiler Directives

    Thanks for the feedback, you two. It is apprecited.

  5. #5
    Addicted Member
    Join Date
    Jun 2009
    Location
    C:\Windows\SysWOW64\
    Posts
    227

    Re: [Resolved] Compiler Directives

    You can declare both API functions. Nothing will happen until one (or both) is executed.
    The compiler doesn't do any check on the existence of the function or the dll file.

    I, for example, have declared an API function twice; one for XP and one for Vista. They are almost identical. One argument is different.
    I check the OS version and call the appropriate function.

    This is good, because you can declare anything you want as an API function, even if it doesn't exist.

  6. #6

    Thread Starter
    Hyperactive Member Quiver318's Avatar
    Join Date
    Sep 2007
    Posts
    260

    Re: [Resolved] Compiler Directives

    Thanks, Cube. That is a very interesting tip!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width