<?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[Registry lesen&#x2F;schreiben ohne .NET]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe nun mittlerweile alles mögliche getestet und natürlich auch die FAQ gelesen. Allerdings komme ich nicht wirklich zu einem Ergebnis.</p>
<p>Problem: Klasse ohne .NET die einen REG_SZ als std::string ausgibt bzw. einen einen std::string als REG_SZ in die Registry schreibt. Bzw. das gleiche mit int/DWORD.</p>
<p>Das lesen eines DWORD hat soweit funktioniert, nur beim string kommt immer nur der erste Buchstabe an?! Im Moment arbeitet die Klasse noch mit char*, statt mit std::string.</p>
<p>Konsolen-Anwendung:<br />
main</p>
<pre><code>int _tmain(int argc, _TCHAR* argv[])
{
	registry *regObj = new registry();

	char *path = regObj-&gt;readString(HKEY_LOCAL_MACHINE,TEXT(&quot;SOFTWARE\\testApp&quot;),TEXT(&quot;path&quot;));

        cout &lt;&lt; path &lt;&lt; &quot;\n&quot;;

	return 0;
}
</code></pre>
<p>Klasse-Registry<br />
header:</p>
<pre><code>#pragma once

class registry
{
public:
	registry(void);
public:
	~registry(void);

	char*	readString(HKEY hKey, TCHAR* hSubKey, TCHAR* hValue);
	DWORD	readInteger(HKEY hKey, TCHAR* hSubKey, TCHAR* hValue);
};
</code></pre>
<p>code:</p>
<pre><code>#include &quot;StdAfx.h&quot;

registry::registry(void) {}

registry::~registry(void) {}

char*  registry::readString(HKEY hKey, TCHAR* hSubKey, TCHAR* hValue) {

	HKEY NEWhKey;
	TCHAR	SubKey[MAX_PATH];
	TCHAR	Data[MAX_PATH];
	lstrcpy(SubKey, hSubKey);
	lstrcpy(Data, hValue);

	DWORD	dwData=0;
	char	*bData;

	RegOpenKey(HKEY_LOCAL_MACHINE,SubKey,&amp;NEWhKey);
	if(RegQueryValueEx(NEWhKey, Data, 0, 0, (PBYTE)NULL, &amp;dwData)==ERROR_SUCCESS &amp;&amp; NEWhKey!=NULL) {
		bData=(char *)malloc(sizeof(char)*dwData);
		RegQueryValueEx(NEWhKey, Data, 0, 0,(PBYTE)(LPTSTR)bData,&amp;dwData); 
	}
	RegCloseKey(NEWhKey);

	return bData;
}

DWORD  registry::readInteger(HKEY hKey, TCHAR* hSubKey, TCHAR* hValue) {

	HKEY NEWhKey;
	TCHAR	SubKey[MAX_PATH];
	TCHAR	Data[MAX_PATH];
	lstrcpy(SubKey, hSubKey);
	lstrcpy(Data, hValue);	

	DWORD dwNumber = 0;
	DWORD dwData = sizeof(DWORD);

	RegOpenKey(HKEY_LOCAL_MACHINE,SubKey,&amp;NEWhKey);
	RegQueryValueEx(NEWhKey, Data, NULL, NULL,(BYTE*)&amp;dwNumber,&amp;dwData);
	RegCloseKey(NEWhKey);

	return dwNumber;
}
</code></pre>
<p>Der Code ist mittlerweile alles andere als sauber, weil ich schon so viel probiert habe. Warum kommt beim auslesen des Pfades von TestApp (path) immer nur der erste Buchstabe?!?</p>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/213227/registry-lesen-schreiben-ohne-net</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 17:04:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/213227.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 15 May 2008 12:28:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Registry lesen&#x2F;schreiben ohne .NET on Thu, 15 May 2008 12:28:53 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe nun mittlerweile alles mögliche getestet und natürlich auch die FAQ gelesen. Allerdings komme ich nicht wirklich zu einem Ergebnis.</p>
<p>Problem: Klasse ohne .NET die einen REG_SZ als std::string ausgibt bzw. einen einen std::string als REG_SZ in die Registry schreibt. Bzw. das gleiche mit int/DWORD.</p>
<p>Das lesen eines DWORD hat soweit funktioniert, nur beim string kommt immer nur der erste Buchstabe an?! Im Moment arbeitet die Klasse noch mit char*, statt mit std::string.</p>
<p>Konsolen-Anwendung:<br />
main</p>
<pre><code>int _tmain(int argc, _TCHAR* argv[])
{
	registry *regObj = new registry();

	char *path = regObj-&gt;readString(HKEY_LOCAL_MACHINE,TEXT(&quot;SOFTWARE\\testApp&quot;),TEXT(&quot;path&quot;));

        cout &lt;&lt; path &lt;&lt; &quot;\n&quot;;

	return 0;
}
</code></pre>
<p>Klasse-Registry<br />
header:</p>
<pre><code>#pragma once

class registry
{
public:
	registry(void);
public:
	~registry(void);

	char*	readString(HKEY hKey, TCHAR* hSubKey, TCHAR* hValue);
	DWORD	readInteger(HKEY hKey, TCHAR* hSubKey, TCHAR* hValue);
};
</code></pre>
<p>code:</p>
<pre><code>#include &quot;StdAfx.h&quot;

registry::registry(void) {}

registry::~registry(void) {}

char*  registry::readString(HKEY hKey, TCHAR* hSubKey, TCHAR* hValue) {

	HKEY NEWhKey;
	TCHAR	SubKey[MAX_PATH];
	TCHAR	Data[MAX_PATH];
	lstrcpy(SubKey, hSubKey);
	lstrcpy(Data, hValue);

	DWORD	dwData=0;
	char	*bData;

	RegOpenKey(HKEY_LOCAL_MACHINE,SubKey,&amp;NEWhKey);
	if(RegQueryValueEx(NEWhKey, Data, 0, 0, (PBYTE)NULL, &amp;dwData)==ERROR_SUCCESS &amp;&amp; NEWhKey!=NULL) {
		bData=(char *)malloc(sizeof(char)*dwData);
		RegQueryValueEx(NEWhKey, Data, 0, 0,(PBYTE)(LPTSTR)bData,&amp;dwData); 
	}
	RegCloseKey(NEWhKey);

	return bData;
}

DWORD  registry::readInteger(HKEY hKey, TCHAR* hSubKey, TCHAR* hValue) {

	HKEY NEWhKey;
	TCHAR	SubKey[MAX_PATH];
	TCHAR	Data[MAX_PATH];
	lstrcpy(SubKey, hSubKey);
	lstrcpy(Data, hValue);	

	DWORD dwNumber = 0;
	DWORD dwData = sizeof(DWORD);

	RegOpenKey(HKEY_LOCAL_MACHINE,SubKey,&amp;NEWhKey);
	RegQueryValueEx(NEWhKey, Data, NULL, NULL,(BYTE*)&amp;dwNumber,&amp;dwData);
	RegCloseKey(NEWhKey);

	return dwNumber;
}
</code></pre>
<p>Der Code ist mittlerweile alles andere als sauber, weil ich schon so viel probiert habe. Warum kommt beim auslesen des Pfades von TestApp (path) immer nur der erste Buchstabe?!?</p>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1509647</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1509647</guid><dc:creator><![CDATA[Ueberflasher]]></dc:creator><pubDate>Thu, 15 May 2008 12:28:53 GMT</pubDate></item><item><title><![CDATA[Reply to Registry lesen&#x2F;schreiben ohne .NET on Thu, 15 May 2008 14:32:50 GMT]]></title><description><![CDATA[<p>EDIT: Blödsinnn <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
Weil du aus der Registry wide-character-strings bekommst, die du erst nach narrow-character konvertieren musst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1509810</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1509810</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 15 May 2008 14:32:50 GMT</pubDate></item><item><title><![CDATA[Reply to Registry lesen&#x2F;schreiben ohne .NET on Thu, 15 May 2008 15:05:51 GMT]]></title><description><![CDATA[<p>Danke für die Antwort. ich hab aber schon ganzen Tag danach gesucht. Wie muss die Methode readString() dann richtig aussehen. Bzw. wie muss &quot;RegQueryValueEx(NEWhKey, Data, 0, 0,(PBYTE)(LPTSTR)bData,&amp;dwData);&quot; aussehen? Und wie konvertiert man zwischen char und wchar?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1509832</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1509832</guid><dc:creator><![CDATA[Ueberflasher]]></dc:creator><pubDate>Thu, 15 May 2008 15:05:51 GMT</pubDate></item><item><title><![CDATA[Reply to Registry lesen&#x2F;schreiben ohne .NET on Thu, 15 May 2008 20:13:07 GMT]]></title><description><![CDATA[<p>Es gibt zwei Wege zum Ziel:</p>
<p>Enweder man schaltet den Compiler von UNICODE auf MULTIBYTE. Dann ist LPTSTR nur ein typedef für char*. Oder, falls, wie bei meinen Programm, UNICODE benötigt wird, nimmt man Weg 2.</p>
<pre><code>#include &lt;stdlib.h&gt;
</code></pre>
<pre><code>char*  registry::readString(HKEY hKey, TCHAR* hSubKey, TCHAR* hValue) {

	HKEY NEWhKey;
	TCHAR	SubKey[MAX_PATH];
	TCHAR	Data[MAX_PATH];
	lstrcpy(SubKey, hSubKey);
	lstrcpy(Data, hValue);

	DWORD	dwData=0;
	LPTSTR	*bData;

	RegOpenKey(HKEY_LOCAL_MACHINE,SubKey,&amp;NEWhKey);
	if(RegQueryValueEx(NEWhKey, Data, 0, 0, (PBYTE)NULL, &amp;dwData)==ERROR_SUCCESS &amp;&amp; NEWhKey!=NULL) {
		bData=(LPTSTR *)malloc(sizeof(LPTSTR)*dwData);
		RegQueryValueEx(NEWhKey, Data, 0, 0,(PBYTE)(LPTSTR)bData,&amp;dwData); 
	}
	RegCloseKey(NEWhKey);

	char *cData=(char *)malloc(sizeof(char)*dwData);

	wcstombs(cData, (wchar_t*)bData,dwData);

	return cData;
}
</code></pre>
<p>Oder zumindest so ähnlich...</p>
<p>wcstombs(cData, (wchar_t*)bData,dwData); konvertiert hier einen &quot;widecharacterstring to multibytestring&quot;.</p>
<p>Weitere Infos hier:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-171319-and-highlight-is-wchart.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-171319-and-highlight-is-wchart.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1510061</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1510061</guid><dc:creator><![CDATA[Ueberflasher]]></dc:creator><pubDate>Thu, 15 May 2008 20:13:07 GMT</pubDate></item></channel></rss>