Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • Last Modified:

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
0
spaznuski
Asked:
spaznuski
1 Solution
 
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
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now