#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    1
    Rep Power
    0

    Conditional API Declaration


    Hi there:

    I have an application that is getting run on a few thousand machines (.

    The problem i have is they are 9x/NT/2000 and XP.

    When I encounter an XP box i am calling the CreateProcessWithLogonW API function that is found in advapi32g.dll, which works great, however the app will not run on NT or 9x, coz NT does not contain the function in the dll and 9x does not even have the dll.

    I dont want to reference the function on NT or 9x, but i have to declare the function in the APP as XP uses it? is there a way to only declare this API function on 2000+ machines or get NT/9x to ignore the error of it not being found?

    (I have to have 1 exe)..

    Thanks for any help...

    Tony
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Athens, Greece
    Posts
    92
    Rep Power
    17
    I suppose you can find the version of windows and if the version is WinXP or higher you can call the dll, otherwise ignore it.

    There are a few ways to find the Windows version.
    Here is a borland's article on that issue: http://community.borland.com/article/0,1410,15974,00.html
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    I dont want to reference the function on NT or 9x, but i have to declare the function in the APP as XP uses it?
    I guess you are declaring the function like this?
    function CreateProcessWithLogonW(.... params ...) stdcall external 'advapi32g.dll';

    You should use a different way to load the dll:
    Code:
    var 
      CreateProcessWithLogonW:function (.... params ...) ; stdcall;
    begin
      DllHandle:=LoadLibrary('advapi32g.dll');
      if DllHandle>0 then begin
        @CreateProcessWithLogonW=GetProcAddr(DllHandle, 'CreateProcessWithLogonW');
        if @CreateProcessWithLogonW<>nil then begin
          // Everything ok. You can use the function now.
        end else begin
          // DLL found but function not.
        end;
      end else begin
        // DLL not found
      end;
    end;
    hth,
    M.
    Last edited by M.Hirsch; November 26th, 2004 at 02:21 PM. Reason: corrected the order of parameters

IMN logo majestic logo threadwatch logo seochat tools logo