BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pointer to a Unicode string - returned by API call

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General)
View previous topic :: View next topic  
Author Message
Lester
Guest





PostPosted: Fri May 27, 2005 3:07 am    Post subject: Pointer to a Unicode string - returned by API call Reply with quote



I'm using GetIfTable API call to get information on network interfaces
([url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/getiftable.asp)[/url].

It fills a table (MIB_IFTABLE) with MIB_IFROW structures. (One
MIB_IFROW for each interface.)
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mib/mib/mib_ifrow.asp)

Now MIB_IFROW has a member wszName [MAX_INTERFACE_NAME_LEN] which is a
"Pointer to a Unicode string that contains the name of the interface".
How do I read this out from the memory, and put in (eg.) a TStrings?

=====================================

Here is some code I tried to make (see comments):

Procedure GetIFInfo(ListInterfaces:TStrings);
var
MibRow : TMibIfRow;
IntfTable: PMibIfTable;
Size : ULONG;
I : Integer;
begin
Size := 0;
//just get the size first...
if GetIfTable(nil, Size, True) <> ERROR_INSUFFICIENT_BUFFER then
Exit;

//have size, make the real call...
IntfTable := AllocMem(Size);
try
if GetIfTable(IntfTable, Size, True) = NO_ERROR then
begin
ListInterfaces.Clear;
for I := 0 to IntfTable^.dwNumEntries - 1 do
begin
//row-by-row
MibRow := IntfTable.Table[I];

//this shows perfectly...
ListInterfaces.Add('speed: ' + IntToStr(MibRow.dwSpeed));

//this shows perfectly...
ListInterfaces.Add('output octets: ' +
IntToStr(MibRow.dwOutOctets));

//PROBLEM HERE: MibRow.wszName is EMPTY!!!???
ListInterfaces.Add('name: ' + MibRow.wszName); // <-- HOW TO
READ IT???
end;
end;

finally
FreeMem(IntfTable);
end;
End;


===============

Here is the definition in IpRtrMib.pas (I'm using IPHelper from
JEDI-project):

const
MAXLEN_IFDESCR = 256;
{$EXTERNALSYM MAXLEN_IFDESCR}
MAXLEN_PHYSADDR = 8;
{$EXTERNALSYM MAXLEN_PHYSADDR}

type
PMIB_IFROW = ^MIB_IFROW;
{$EXTERNALSYM PMIB_IFROW}
_MIB_IFROW = record
wszName: array [0..MAX_INTERFACE_NAME_LEN - 1] of WCHAR;
dwIndex: DWORD;
dwType: DWORD;
dwMtu: DWORD;
dwSpeed: DWORD;
dwPhysAddrLen: DWORD;
bPhysAddr: array [0..MAXLEN_PHYSADDR - 1] of BYTE;
dwAdminStatus: DWORD;
dwOperStatus: DWORD;
dwLastChange: DWORD;
dwInOctets: DWORD;
dwInUcastPkts: DWORD;
dwInNUcastPkts: DWORD;
dwInDiscards: DWORD;
dwInErrors: DWORD;
dwInUnknownProtos: DWORD;
dwOutOctets: DWORD;
dwOutUcastPkts: DWORD;
dwOutNUcastPkts: DWORD;
dwOutDiscards: DWORD;
dwOutErrors: DWORD;
dwOutQLen: DWORD;
dwDescrLen: DWORD;
bDescr: array[0..MAXLEN_IFDESCR - 1] of BYTE;
end;
{$EXTERNALSYM _MIB_IFROW}
MIB_IFROW = _MIB_IFROW;
{$EXTERNALSYM MIB_IFROW}
TMibIfRow = MIB_IFROW;
PMibIfRow = PMIB_IFROW;

PMIB_IFTABLE = ^MIB_IFTABLE;
{$EXTERNALSYM PMIB_IFTABLE}
_MIB_IFTABLE = record
dwNumEntries: DWORD;
table: array [0..ANY_SIZE - 1] of MIB_IFROW;
end;
{$EXTERNALSYM _MIB_IFTABLE}
MIB_IFTABLE = _MIB_IFTABLE;
{$EXTERNALSYM MIB_IFTABLE}
TMibIftable = MIB_IFTABLE;
PMibIftable = PMIB_IFTABLE;


MANY thanks in advance!
L.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.