Article View: borland.public.cppbuilder.nativeapi
Article #3331Re: dynamically loading wininet.dll
From: Bob Gonder
Date: Sun, 23 Jul 2006 14:01
Date: Sun, 23 Jul 2006 14:01
63 lines
2614 bytes
2614 bytes
Mike Collins wrote:
> 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:
You don't report failure to load the library.
Add failure code to show the szWNetPath.
> // Dynamically Load WinINet.dll...
> AnsiString szWINetPath = "";
> szWINetPath.SetLength(MAX_PATH+1);
> szWINetPath.SetLength(GetSystemDirectory(szWINetPath.c_str(),
>szWINetPath.Length()));
I find that line confusing.
Also not sure if length isn't calculated before GetSystemDirectory
sets it?
Also, since everything in here uses cstrings, why not use cstrings
instead complicating things with AnsiString?
char szWINetPath[MAX_PATH+1];
GetSystemDirectory( szWINetPath, MAX_PATH);
lstrcat( szWINetPath, "\\wininet.dll");
hINetDLL = LoadLibrary(szWINetPath);
But, I'd prefer this:
hINetDLL = LoadLibrary("wininet.dll");
BTW#2: AnsiString isn't an sz. Probably an 'as' or plain 's'.
> szWINetPath = AnsiString(szWINetPath + "\\wininet.dll");
> hINetDLL = LoadLibrary(szWINetPath.c_str());
> // If ineternet connection established, then close it...
> if (hINetHnd)
> InternetCloseHandle(hINetHnd);
>
> if (hINetDLL)
> FreeLibrary(hINetDLL);
Proper use of flow control will eliminated those extra if()s at the
end...
if (hINetDLL)
{
if (hINetHnd)
{
// use the internet
// .....
InternetCloseHandle(hINetHnd);
}else{
// handle hNet failure
};
FreeLibrary(hINetDLL);
}else{
//handle dll failure
};
Technical Details
Message-ID:
<6tu6c2pdoiiif4akdmtsvbmi8u1kvv3c4q@4ax.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news4.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-mailReferences:
<44c3590d$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,1c5f45dab245a9b X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: dynamically loading wininet.dll Date: Sun, 23 Jul 2006 07:01:58 -0700 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <6tu6c2pdoiiif4akdmtsvbmi8u1kvv3c4q@4ax.com> References: <44c3590d$1@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 71.49.221.11 X-Trace: newsgroups.borland.com 1153663317 71.49.221.11 (23 Jul 2006 07:01:57 -0700) Lines: 66 Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news4.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