<?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[String in die Registry schreiben]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich möchte einen String in die Registry schreiben. Leider klappt das nicht.<br />
Ich vermute das liegt daran das ich ein char Array an die Funktion RegSetValueEx übergebe, diese aber einen Unicode string schreibt.</p>
<p>Wie muss ich das Array übergeben?</p>
<p>Es soll &quot;hallo&quot; in die Registry geschrieben werden. Es steht aber nach ausführen des Programms nur &quot;??o&quot; drin.</p>
<p>hier ist der Code</p>
<pre><code class="language-cpp">int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    lpCmdLine,
					int       nCmdShow)
{
 	// TODO: Place code here.

HKEY hkMyKey;
DWORD dwDisposition;
unsigned char string[]=&quot;hallo&quot;;

	if (ERROR_SUCCESS!=RegCreateKeyEx(	HKEY_USERS,
										TEXT(&quot;TEST&quot;),
										0,
										NULL,
										REG_OPTION_NON_VOLATILE,
										0,
										NULL,
										&amp;hkMyKey,
										&amp;dwDisposition
										))
		printf(&quot;Fehler beim Erzeugen des KEYS&quot;);

	if (ERROR_SUCCESS!=RegSetValueEx(	hkMyKey,
										TEXT(&quot;String&quot;),
										0,
										REG_SZ,
										string,
										(sizeof(string))
										))

		printf(&quot;Fehler beim schreiben&quot;);

	if (ERROR_SUCCESS!=RegCloseKey(	hkMyKey))
	printf(&quot;Fehler beim schließen&quot;);

	return 0;
}
</code></pre>
<p>Gruß<br />
spacehelix</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/160617/string-in-die-registry-schreiben</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 18:03:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/160617.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 27 Sep 2006 14:55:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to String in die Registry schreiben on Wed, 27 Sep 2006 14:55:54 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich möchte einen String in die Registry schreiben. Leider klappt das nicht.<br />
Ich vermute das liegt daran das ich ein char Array an die Funktion RegSetValueEx übergebe, diese aber einen Unicode string schreibt.</p>
<p>Wie muss ich das Array übergeben?</p>
<p>Es soll &quot;hallo&quot; in die Registry geschrieben werden. Es steht aber nach ausführen des Programms nur &quot;??o&quot; drin.</p>
<p>hier ist der Code</p>
<pre><code class="language-cpp">int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    lpCmdLine,
					int       nCmdShow)
{
 	// TODO: Place code here.

HKEY hkMyKey;
DWORD dwDisposition;
unsigned char string[]=&quot;hallo&quot;;

	if (ERROR_SUCCESS!=RegCreateKeyEx(	HKEY_USERS,
										TEXT(&quot;TEST&quot;),
										0,
										NULL,
										REG_OPTION_NON_VOLATILE,
										0,
										NULL,
										&amp;hkMyKey,
										&amp;dwDisposition
										))
		printf(&quot;Fehler beim Erzeugen des KEYS&quot;);

	if (ERROR_SUCCESS!=RegSetValueEx(	hkMyKey,
										TEXT(&quot;String&quot;),
										0,
										REG_SZ,
										string,
										(sizeof(string))
										))

		printf(&quot;Fehler beim schreiben&quot;);

	if (ERROR_SUCCESS!=RegCloseKey(	hkMyKey))
	printf(&quot;Fehler beim schließen&quot;);

	return 0;
}
</code></pre>
<p>Gruß<br />
spacehelix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1145483</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1145483</guid><dc:creator><![CDATA[spacehelix]]></dc:creator><pubDate>Wed, 27 Sep 2006 14:55:54 GMT</pubDate></item><item><title><![CDATA[Reply to String in die Registry schreiben on Wed, 27 Sep 2006 16:02:37 GMT]]></title><description><![CDATA[<p>RegSetValueEx erwartet einen (const) byte pointer, daher musst du den char pointer casten:</p>
<pre><code class="language-cpp">reinterpret_cast&lt;byte*&gt;(string)
</code></pre>
<p>// edit<br />
Sehe grade, dass du schon ein byte array hast, daher dürfte es eigentlich keine Probleme bereiten, wenn du kein Unicode aktiviert hast.<br />
Andernfalls hilft folgender code:</p>
<pre><code class="language-cpp">TCHAR string[]=TEXT(&quot;hallo&quot;); // &lt;-- TCHAR anstatt unsigned char

	if (ERROR_SUCCESS!=RegCreateKeyEx(    HKEY_CURRENT_USER,
		TEXT(&quot;TEST&quot;),
		0,
		NULL,
		REG_OPTION_NON_VOLATILE,
		KEY_ALL_ACCESS,
		NULL,
		&amp;hkMyKey,
		&amp;dwDisposition
		))
		printf(&quot;Fehler beim Erzeugen des KEYS&quot;);

	if (ERROR_SUCCESS!=RegSetValueEx(    hkMyKey,
		TEXT(&quot;String&quot;),
		0,
		REG_SZ,
		reinterpret_cast&lt;byte*&gt;(string), // &lt;-- cast
		(sizeof(string))
		))
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1145530</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1145530</guid><dc:creator><![CDATA[qasdfgh]]></dc:creator><pubDate>Wed, 27 Sep 2006 16:02:37 GMT</pubDate></item><item><title><![CDATA[Reply to String in die Registry schreiben on Wed, 27 Sep 2006 17:37:40 GMT]]></title><description><![CDATA[<p>qasdfgh schrieb:</p>
<blockquote>
<p>RegSetValueEx erwartet einen (const) byte pointer, daher musst du den char pointer casten:</p>
<pre><code class="language-cpp">reinterpret_cast&lt;byte*&gt;(string)
</code></pre>
</blockquote>
<p>Das ist nicht korrekt. Das hat mit const nichts zu tun.</p>
<p>In jedem Fall muss der char * erst einmal in enen UNICODE String umgewandelt werden, oder man verwendet direkt RegSetValueExA!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1145598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1145598</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Wed, 27 Sep 2006 17:37:40 GMT</pubDate></item><item><title><![CDATA[Reply to String in die Registry schreiben on Thu, 28 Sep 2006 15:27:39 GMT]]></title><description><![CDATA[<p>danke für eure hilfe,</p>
<p>ich habs damit geschafft.</p>
<p>Gruß<br />
spacehelix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1146042</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1146042</guid><dc:creator><![CDATA[spacehelix]]></dc:creator><pubDate>Thu, 28 Sep 2006 15:27:39 GMT</pubDate></item></channel></rss>