Article View: borland.public.cppbuilder.nativeapi
Article #8182Re: Is it possible to use Wininet functions WITHOUT LINKING the Wininet.lib ??
From: Oren Halvani
Date: Sat, 13 Nov 2004 01:37
Date: Sat, 13 Nov 2004 01:37
98 lines
4468 bytes
4468 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> schrieb im
Newsbeitrag news:41955ff6@newsgroups.borland.com...
>
> If you are dynamically loading the DLL via LoadLibrary(), then yes. You
> will, of course, have to make sure that when you use GetProcAddress() to
> retreive a function pointer, that the pointer is not returned as NULL before
> you try to call the function. Some WinInet functions are not implemented on
> all OS versions.
OK, i check now: if(InternetGetConnectedStatePtr != NULL)
>
> True, although you don't need to make thousands of calls. You should only
> call LoadLibrary() once, and keep the DLL loaded for the entire duration
> that you are going to use it, and then call FreeLibrary() when you are not
> using the DLL anymore. As for GetProcAddress(), you only have to call it
> once for each individual function that you are interested in. Are you
> planning on call a thousand separate WinInet functions? I doubt it.
OK..what do you think of this usage:
/**************************************************/
#include <WININET.h>
HMODULE wininet_hand;
typedef BOOL WINAPI (*FuncPtr)(DWORD* flags, DWORD reserved);
__fastcall TfrmMainUnit::TfrmMainUnit(TComponent* Owner) : TForm(Owner)
{
wininet_hand = LoadLibrary("WININET.DLL");
}
void __fastcall TfrmMainUnit::Button1Click(TObject *Sender)
{
FuncPtr InternetGetConnectedStatePtr;
if(wininet_hand)
{
InternetGetConnectedStatePtr = (FuncPtr) GetProcAddress(wininet_hand,
"InternetGetConnectedState");
if(InternetGetConnectedStatePtr != NULL)
{
DWORD flags;
if(InternetGetConnectedStatePtr(&flags, 0))
{
char s[1024] = "Internet connection ";
if(flags & INTERNET_CONNECTION_LAN) lstrcat(s, "is by local area
network");
else if (flags & INTERNET_CONNECTION_MODEM) lstrcat(s, "is by modem");
else if (flags & INTERNET_CONNECTION_PROXY) lstrcat(s, "is by proxy");
else lstrcpy(s, "Not sure how the internet connection is made");
ShowMessage(s);
}
else ShowMessage("InternetGetConnectedState call failed");
}
else ShowMessage("InternetGetConnectedState function not found");
}
else ShowMessage("Unable to load WinInet.DLL");
}
__fastcall TfrmMainUnit::~TfrmMainUnit()
{
FreeLibrary(wininet_hand);
}
/**************************************************/
is this ok...?
>
> On the other hand, if you do statically link to the lib file, then not only
> does the DLL itself have to exist, but so does every individual function
> that your code calls. If you run your program on a system that does not
> have every single WinInet function that your code calls statically, then
> your program will fail to start at all.
TRUE !! i didn't thought about that, very good catch Remy !!!
>
> Then LoadLibrary() and GetProcAddress() are your only option. Of course,
> had you been using BCB 5 or 6, you could make use of their Delay-Load
> mechanism to statically link to the DLL functions in your code while still
> providing run-time loading of the DLL when needed. A very nice feature to
> use if you have it available.
>
>
> Gambit
still have to fight with BCB 3..this will only be possible for me in the
next project that will be finally developed under BCB 6 :-)
Oren
Technical Details
Message-ID:
<4195658a@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<419508ed$1@newsgroups.borland.com> <419516cd$1@newsgroups.borland.com> <41955b2e$1@newsgroups.borland.com> <41955ff6@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,7fd10020e90983c X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Oren Halvani" <Spam@Me-Please.com> From: "Oren Halvani" <Spam@Me-Please.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <419508ed$1@newsgroups.borland.com> <419516cd$1@newsgroups.borland.com> <41955b2e$1@newsgroups.borland.com> <41955ff6@newsgroups.borland.com> Subject: Re: Is it possible to use Wininet functions WITHOUT LINKING the Wininet.lib ?? Date: Sat, 13 Nov 2004 02:37:30 +0100 Lines: 100 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: 217.86.58.178 Message-ID: <4195658a@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1100309898 217.86.58.178 (12 Nov 2004 17:38:18 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail