Article View: borland.public.cppbuilder.nativeapi
Article #8326Re: Is it possible to use Wininet functions WITHOUT LINKING the Wininet.lib ??
From: Ed Mulroy [TeamB]
Date: Fri, 12 Nov 2004 18:42
Date: Fri, 12 Nov 2004 18:42
99 lines
3756 bytes
3756 bytes
Wininet.lib is not a static library. It is an import
library for a DLL. Wininet.DLL is a DLL, a DYNAMIC
LINKED library. It cannot be static linked into your
program.
If you do not want to implicitly link with wininet.lib or
wininet.def then you will have to explicitly link to the
DLL by using LoadLibrary, GetProcAddress and FreeLibrary
yourself instead of letting the Windows' program loader
do that for you.
Below is a 'quicky' demo of a Windows GUI program that
explicitly links to WinInet.DLL. It does not use the VCL.
If you want to build it in the IDE then create the
project with File|New|Other (File|New on older compiler
versions), double click the (misnamed) Console Wizard,
and make sure GUI is selected and neither of Console or
VCL are not (which of GUI or Console are shown varies
with compiler version).
If you want to build it from the command line a command
to do that might be:
bcc32 -WR -v filename.cpp
----------
#include <windows.h>
#include <wininet.h>
typedef BOOL WINAPI
(*FuncPtr)(DWORD* flags, DWORD reserved);
void WINAPI MboxMsg(const char *msg)
{
MessageBox(HWND_DESKTOP, msg, "", MB_OK);
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
FuncPtr InternetGetConnectedStatePtr;
HMODULE wininet_hand = LoadLibrary("WININET.DLL");
if (wininet_hand)
{
InternetGetConnectedStatePtr = (FuncPtr)
GetProcAddress(
wininet_hand,
"InternetGetConnectedState");
if (InternetGetConnectedStatePtr)
{
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");
MboxMsg(s);
}
else
MboxMsg("InternetGetConnectedState call failed");
}
else
MboxMsg("InternetGetConnectedState function not found");
FreeLibrary(wininet_hand);
}
else
MboxMsg("Unable to load WinInet.DLL");
return 0;
}
----------
. Ed
>Oren Halvani wrote:
>
>is it possible to use the Wininet functions WITHOUT to
>link the Wininet.lib into the project..?
>
>is it possible to use LoadLibary() for that..? do i need something else
>further..? declaring / define something...?
>
>i need to write a standalone.exe without static
>linking...>any ideas for that..?
Technical Details
Message-ID:
<41951241$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!proxad.net!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<419508ed$1@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 From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> Sender: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> Reply-To: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> Subject: Re: Is it possible to use Wininet functions WITHOUT LINKING the Wininet.lib ?? Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 24.74.175.102 References: <419508ed$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <41951241$1@newsgroups.borland.com> Date: 12 Nov 2004 11:42:57 -0700 X-Trace: newsgroups.borland.com 1100288577 207.105.83.66 (12 Nov 2004 11:42:57 -0700) Lines: 100 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!proxad.net!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail