?
Solved

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

Posted on 2003-03-17
3
Medium Priority
?
297 Views
Last Modified: 2010-04-04
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
Comment
Question by:spaznuski
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Expert Comment

by:DaFox
ID: 8157481
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
 
LVL 17

Accepted Solution

by:
geobul earned 165 total points
ID: 8158448
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
 

Expert Comment

by:CleanupPing
ID: 9316739
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question