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

x
?
Solved

Declare a Function for NT only

Posted on 2003-03-15
5
Medium Priority
?
227 Views
Last Modified: 2010-04-04
OK I have two functions that use NetApi32.dll but the code i have will only work on NT, How can i write it so that if the exe is running on a 9x machine the functions wont get called.
The Functions 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';
0
Comment
Question by:spaznuski
5 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 50 total points
ID: 8143433
Hi,

Try this:

function IsNT: boolean;
var osv: TOSVERSIONINFO;
begin
  result := false;
  FillChar(osv,SizeOf(osv),0);
  osv.dwOSVersionInfoSize := SizeOf(osv);
  if GetVersionEx(osv) then
    if osv.dwMajorVersion = 4 then result := true;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if IsNT then ...
  else ...;
end;

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 8143446
If you want IsNT function to return true for 2000/XP then:
...
  if osv.dwMajorVersion >= 4 then result := true;
...

Regards, Geo
0
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 8143648
MajorVersion 4 is also used for Win95/98/ME and NT4.
The line should be :
if (OsInfoEx.dwPlatformId = VER_PLATFORM_WIN32_NT) and (Osv.dwMajorVersion = 4) then
  result:=true;

For Win2000 and XP you should use VerifyVersionInfo
.
Peter
0
 

Author Comment

by:spaznuski
ID: 8144943
OK, Thanx for the help; I  actually have code like that already and am using it in such a manner for other problems, but after a long break from the code and looking at what is being said, i figured out what i needed to do.
Thanx
0
 

Expert Comment

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline
Suggested Courses

564 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