<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problem mit CloseHandle]]></title><description><![CDATA[<p>Hi ich habe folgendes Problem mit der Funktion CloseHandle</p>
<p>Der Code ist jedenfalls:</p>
<pre><code class="language-cpp">#include&lt;afxwin.h&gt;
#include&lt;wininet.h&gt;
#pragma comment(lib,&quot;wininet.lib&quot;)
#include&lt;cstring&gt;
#include&lt;iostream&gt;
using namespace std;

int MyMain();

int ReadURL(char *pcURL,char *pData)
{
	HINTERNET hInternet=InternetOpen(&quot;Microsoft Internet Explorer&quot;,INTERNET_OPEN_TYPE_PRECONFIG,0,0,0);
	if(!hInternet)
		return(-1);

	HINTERNET hURL=InternetOpenUrl(hInternet,pcURL,0,0,INTERNET_FLAG_RELOAD,0);

	if(!hURL)
	{
		CloseHandle(hInternet);
		return(-1);
	}

	DWORD dwNumBytesRead;
	BYTE *pCursor=(BYTE*)(pData);
	do
	{
		InternetReadFile(hURL,pCursor,50,&amp;dwNumBytesRead);
		pCursor+=dwNumBytesRead;
	}while(dwNumBytesRead);

	CloseHandle(hInternet);
	CloseHandle(hURL);
	return(0);
}

class CMyApp :public CWinApp
{
public:
	virtual BOOL InitInstance();
};

BOOL CMyApp::InitInstance()
{
    MyMain();
	return(FALSE);
}

CMyApp MyApplikation;

int MyMain()
{
	char acGelesen[4096];
	for(int ii=0;ii&lt;4096;ii++)
		acGelesen[ii]='\0';
	int i=ReadURL(&quot;http://www.frauenstein-net.de/kevin/php/php010012.php?product=Metzgerei-Simulator&quot;,acGelesen);
	if(i==-1)
	{
		MessageBox(NULL,&quot;Konnte keine Verbindung zur URL herstellen&quot;,&quot;&quot;,MB_OK|MB_ICONSTOP);
		return(0);
	}
	LPCSTR Ausgabe=(reinterpret_cast&lt;LPCSTR&gt;(acGelesen));
	MessageBox(NULL,Ausgabe,&quot;Gelesene Ausgabe der URL&quot;,MB_OK);

	return(0);
}
</code></pre>
<p>Das ganze mit den statischen Bibliotheken der MFC gelinkt.</p>
<p>Jetzt meckert der Debugger dass ein ungültiges HANDLE angegeben wurde<br />
Wenn ich aber CloseHandle einfach rauslasse meckert der Debugger nicht mehr. Jetzt weiß ich aber nicht genau ob das Speicherlecks hinterlässt, etc.<br />
Oder mach ich sonst irgendetwas falsch (außer das mit MyMain)?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/194854/problem-mit-closehandle</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 01:03:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/194854.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Oct 2007 14:49:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit CloseHandle on Thu, 11 Oct 2007 14:49:36 GMT]]></title><description><![CDATA[<p>Hi ich habe folgendes Problem mit der Funktion CloseHandle</p>
<p>Der Code ist jedenfalls:</p>
<pre><code class="language-cpp">#include&lt;afxwin.h&gt;
#include&lt;wininet.h&gt;
#pragma comment(lib,&quot;wininet.lib&quot;)
#include&lt;cstring&gt;
#include&lt;iostream&gt;
using namespace std;

int MyMain();

int ReadURL(char *pcURL,char *pData)
{
	HINTERNET hInternet=InternetOpen(&quot;Microsoft Internet Explorer&quot;,INTERNET_OPEN_TYPE_PRECONFIG,0,0,0);
	if(!hInternet)
		return(-1);

	HINTERNET hURL=InternetOpenUrl(hInternet,pcURL,0,0,INTERNET_FLAG_RELOAD,0);

	if(!hURL)
	{
		CloseHandle(hInternet);
		return(-1);
	}

	DWORD dwNumBytesRead;
	BYTE *pCursor=(BYTE*)(pData);
	do
	{
		InternetReadFile(hURL,pCursor,50,&amp;dwNumBytesRead);
		pCursor+=dwNumBytesRead;
	}while(dwNumBytesRead);

	CloseHandle(hInternet);
	CloseHandle(hURL);
	return(0);
}

class CMyApp :public CWinApp
{
public:
	virtual BOOL InitInstance();
};

BOOL CMyApp::InitInstance()
{
    MyMain();
	return(FALSE);
}

CMyApp MyApplikation;

int MyMain()
{
	char acGelesen[4096];
	for(int ii=0;ii&lt;4096;ii++)
		acGelesen[ii]='\0';
	int i=ReadURL(&quot;http://www.frauenstein-net.de/kevin/php/php010012.php?product=Metzgerei-Simulator&quot;,acGelesen);
	if(i==-1)
	{
		MessageBox(NULL,&quot;Konnte keine Verbindung zur URL herstellen&quot;,&quot;&quot;,MB_OK|MB_ICONSTOP);
		return(0);
	}
	LPCSTR Ausgabe=(reinterpret_cast&lt;LPCSTR&gt;(acGelesen));
	MessageBox(NULL,Ausgabe,&quot;Gelesene Ausgabe der URL&quot;,MB_OK);

	return(0);
}
</code></pre>
<p>Das ganze mit den statischen Bibliotheken der MFC gelinkt.</p>
<p>Jetzt meckert der Debugger dass ein ungültiges HANDLE angegeben wurde<br />
Wenn ich aber CloseHandle einfach rauslasse meckert der Debugger nicht mehr. Jetzt weiß ich aber nicht genau ob das Speicherlecks hinterlässt, etc.<br />
Oder mach ich sonst irgendetwas falsch (außer das mit MyMain)?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1382926</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1382926</guid><dc:creator><![CDATA[Vox 3D]]></dc:creator><pubDate>Thu, 11 Oct 2007 14:49:36 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit CloseHandle on Thu, 11 Oct 2007 14:54:24 GMT]]></title><description><![CDATA[<p>InternetCloseHandle <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1382936</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1382936</guid><dc:creator><![CDATA[reudiger]]></dc:creator><pubDate>Thu, 11 Oct 2007 14:54:24 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit CloseHandle on Thu, 11 Oct 2007 15:07:55 GMT]]></title><description><![CDATA[<p>Aha! Danke! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /><br />
Da hat sich wahrscheinlich jemand verschrieben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1382951</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1382951</guid><dc:creator><![CDATA[Vox 3D]]></dc:creator><pubDate>Thu, 11 Oct 2007 15:07:55 GMT</pubDate></item></channel></rss>