Article View: borland.public.cppbuilder.nativeapi
Article #15628Re: GetIfTable?
From: Remy Lebeau (TeamB)
Date: Mon, 23 Jun 2003 22:22
Date: Mon, 23 Jun 2003 22:22
42 lines
2749 bytes
2749 bytes
"vERUs" <verus@privat.utfors.se> wrote in message
news:3ee8e4e3@newsgroups.borland.com...
> Hmm, I thougt I'd already tried that but it worked so obviously I didn't.
> What's the differens between LoadLibrary() and GetModuleHandle() really?
Dynamic libraries have a reference count to them. If the library is already
loaded by the calling process, then LoadLibrary() simply increments that
reference count. Otherwide, if the library is not loaded yet, then
LodLibrary() loads it fresh. In both cases, FreeLibrary() then decrements
the reference count and the library is finally freed when the reference
count falls to 0. GetModuleHandle(), on the other hand, does not load the
library if it is not already loaded, and it never increments the reference
count either way. LoadLibrary() is good to use for external libraries when
you don't know whether they are already loaded or not, such as third-party
DLLs and such. GetModuleHandle() is good to use for libraries which you
know are already loaded, such as system libraries like KERNEL32 and USER32.
> What am I doing wrong?
You should be dynamically allocating the memory for the table. Chances are,
you are using a structure that is too small and thus the function overwrites
memory it shouldn't be. Try this instead:
PMIB_IFTABLE pIFTable = NULL;
ULONG Sz = 0;
DWORD Result = GetIfTable(NULL, &Sz, true);
if( Result == ERROR_INSUFFICIENT_BUFFER )
{
pIFTable = (PMIB_IFTABLE) GlobalAlloc(GPTR, Sz);
if( pIFTable )
{
Result = GetIfTable(pIFTable, &Sz, true);
//...
GlobalFree(pIFTable);
}
}
Gambit
Technical Details
Message-ID:
<3ef77c95$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3ee62442@newsgroups.borland.com> <3ee62f95$1@newsgroups.borland.com> <3ee89b89@newsgroups.borland.com> <3ee8a91c$1@newsgroups.borland.com> <3ee8e4e3@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,70d2eff840e44f86 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-06-23 15:27:36 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3ee62442@newsgroups.borland.com> <3ee62f95$1@newsgroups.borland.com> <3ee89b89@newsgroups.borland.com> <3ee8a91c$1@newsgroups.borland.com> <3ee8e4e3@newsgroups.borland.com> Subject: Re: GetIfTable? Date: Mon, 23 Jun 2003 15:22:04 -0700 Lines: 44 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 207.175.226.26 Message-ID: <3ef77c95$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1056406677 207.175.226.26 (23 Jun 2003 15:17:57 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail