Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

API Declaration Question

Status
Not open for further replies.

t0ny

Programmer
Nov 26, 2004
1
GB
Hi there:

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

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 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

 
Hi,

check os on program startup,
then you can load the dll on runtime with LoadLibrary and then you can find the function with GetProcAddress.

the code below is meant generally and is untested...

Code:
type TMyfunction =  function(mystring : String): boolean; StdCall;

...

procedure testlib;

var LibHandle : THandle;
    MyFunction : TMyFunction;

begin
 LibHandle:=LoadLibrary('MyLib.dll');
 try
  @MyFunction:=GetProcAddress(LibHandle,'myfunction');
  if @myfunction = nil then RaiseLastWin32Error;
  if MyFunction('test') then ShowMessage('Hey it works!');
 finally
  FreeLibrary(LibHandle);
 end;
end;

--------------------------------------
What You See Is What You Get
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top