Article View: borland.public.cppbuilder.nativeapi
Article #3327dynamically loading wininet.dll
From: Mike Collins
Date: Sun, 23 Jul 2006 11:10
Date: Sun, 23 Jul 2006 11:10
83 lines
3935 bytes
3935 bytes
Hi all, trying to dynamically load wininet.dll as opposed to using the .lib
file. My code is pretty straightforward (as shown below) but it seems to to
failing on the GetProcAddress. Can anyone see where i'm going wrong:
// Typedefs
typedef HINTERNET WINAPI (* TInternetOpen) (LPCTSTR lpszAgent,
DWORD dwAccessType,
LPCTSTR lpszProxyName,
LPCTSTR lpszProxyBypass,
DWORD dwFlags);
typedef HINTERNET WINAPI (* TInternetConnect) (HINTERNET hInternet,
LPCTSTR lpszServerName,
INTERNET_PORT nServerPort,
LPCTSTR lpszUsername,
LPCTSTR lpszPassword,
DWORD dwService,
DWORD dwFlags,
DWORD_PTR dwContext);
typedef BOOL WINAPI (* TInternetCloseHandle) (HINTERNET hInternet);
// dll handle
HINSTANCE hINetDLL = NULL;
// Internet handle
HINTERNET hINetHnd = NULL;
TInternetOpen InternetOpen;
TInternetConnect InternetConnect;
TInternetCloseHandle InternetCloseHandle;
// Dynamically Load WinINet.dll...
AnsiString szWINetPath = "";
szWINetPath.SetLength(MAX_PATH+1);
szWINetPath.SetLength(GetSystemDirectory(szWINetPath.c_str(),
szWINetPath.Length()));
szWINetPath = AnsiString(szWINetPath + "\\wininet.dll");
hINetDLL = LoadLibrary(szWINetPath.c_str());
if (hINetDLL)
{
InternetOpen = (TInternetOpen)GetProcAddress(hINetDLL,
"InternetOpen");
InternetConnect = (TInternetConnect)GetProcAddress(hINetDLL,
"InternetConnect");
InternetCloseHandle = (TInternetCloseHandle)GetProcAddress(hINetDLL,
"InternetCloseHandle");
// Open Internet Connection
if (InternetOpen)
{
hINetHnd = InternetOpen("KidSafe Live Update", 0, 0, 0, 0);
if (hINetHnd)
{
HINTERNET hHTTPHnd = InternetConnect(hINetHnd,
"www.softwareassociates.nu/";
INTERNET_DEFAULT_HTTP_PORT,
"", "",
INTERNET_SERVICE_HTTP, 0,
0);
if (hHTTPHnd)
{
// Operation complete
}
else
{
// Internet Connect Error...
}
}
else
{
// Internet Open Error...
}
}
}
// If ineternet connection established, then close it...
if (hINetHnd)
InternetCloseHandle(hINetHnd);
if (hINetDLL)
FreeLibrary(hINetDLL);
Many thanks in advance...
Mike C
Technical Details
Message-ID:
<44c3590d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,1c5f45dab245a9b,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Mike Collins" <its@TheBottomOfThePost.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: dynamically loading wininet.dll Date: Sun, 23 Jul 2006 12:10:02 +0100 Lines: 85 Organization: SDA Ltd X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.2663 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2663 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 81.2.92.14 Message-ID: <44c3590d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1153653005 81.2.92.14 (23 Jul 2006 04:10:05 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail