running an executable that links Netapi32.dll; but ignores the funtion on win98

OK I asked this question already but my intentions were not clear hence the help i got was not what I wanted. Here is my question, I have two stdcalls to netapi32.dll and because of those two calls the app wont load on a 9x machine (I Know the reasons why) what I want to know is if there is a way for me to ignore the calls to the dll on a 9x machine or am I just out of luck. The Functions in question are

function NetShareEnum(servername: PWideChar; level: DWORD; bufptr: PBYTE;
  prefmaxlen: DWORD;  entriesread: PDWORD;  totalentries: PDWORD;
  resume_handle: PDWORD): DWORD;   stdcall;  external 'netapi32.dll' Name 'NetShareEnum';

function NetApiBufferFree(Buffer: Pointer): DWORD;
stdcall; external 'netapi32.dll' Name 'NetApiBufferFree';

SO Once again I want a way to ignore the above if the exe is running on a 9x machine
Please Help
Thanx
spaznuskiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DaFoxCommented:
Hi.

Use dynamic linking instead of doing it statically. Then you're able to check the OS before you try to import the functions.

Example:

var
  function NetShareEnum(servername: PWideChar; level: DWORD; bufptr: PBYTE; prefmaxlen: DWORD;  entriesread: PDWORD;  totalentries: PDWORD; resume_handle: PDWORD): DWORD; stdcall;

...


function IsNTPlatform: Boolean;
var
  osv : TOSVERSIONINFO;
begin
  Result := false;
  osv.dwOSVersionInfoSize := SizeOf(TOSVERSIONINFO);
  GetVersionEx(osv);
  if (osv.dwPlatformId = VER_PLATFORM_WIN32_NT) then result:= true;
end;

...

if isNTPlatform then
begin
  Lib := LoadLibrary('netapi32.dll');
  @hNetShareEnum := GetProcAddress(Lib, 'NetShareEnum');
end;


Markus
0
geobulCommented:
Hi,

I think that you don't need to check the OS version if the library (or the function) doesn't exist in the current OS. Just try to load the library ( as DaFox already showed) and then check if the handle is valid (the same applies for the function itself):

var Lib: THandle;
begin
  Lib := LoadLibrary('netapi32.dll'); // load library
  if Lib <> 0 then begin // if loaded
    try
      @NetShareEnum := GetProcAddress(Lib, 'NetShareEnum'); // get the function address
      if (@NetShareEnum <> nil) then begin // if the function is valid
        res := NetShareEnum(....) // call the function
      end;
    finally
      FreeLibrary(Lib); // close the dll
    end;
  end;
...
end;

Regards, Geo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CleanupPingCommented:
spaznuski:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.