<?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[[Erledigt] LoadString dynamisch?]]></title><description><![CDATA[<p>Hi Leute!<br />
Ihr kennt doch sicher alle LoadString.<br />
Wie kann ich einen String dynamisch laden?<br />
Also vorher die Länge von diesem String bestimmen.</p>
<p>Ich hoffe damit kennt sich einer von euch aus.<br />
Danke im Voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/222094/erledigt-loadstring-dynamisch</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 21:32:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/222094.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 07 Sep 2008 18:35:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Erledigt] LoadString dynamisch? on Mon, 08 Sep 2008 12:12:43 GMT]]></title><description><![CDATA[<p>Hi Leute!<br />
Ihr kennt doch sicher alle LoadString.<br />
Wie kann ich einen String dynamisch laden?<br />
Also vorher die Länge von diesem String bestimmen.</p>
<p>Ich hoffe damit kennt sich einer von euch aus.<br />
Danke im Voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1578208</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1578208</guid><dc:creator><![CDATA[Blaze]]></dc:creator><pubDate>Mon, 08 Sep 2008 12:12:43 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] LoadString dynamisch? on Sun, 07 Sep 2008 18:59:27 GMT]]></title><description><![CDATA[<p>Stichwort <strong>FindResource</strong> und <strong>SizeofResource</strong></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1578219</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1578219</guid><dc:creator><![CDATA[desperate progman]]></dc:creator><pubDate>Sun, 07 Sep 2008 18:59:27 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] LoadString dynamisch? on Sun, 07 Sep 2008 20:04:47 GMT]]></title><description><![CDATA[<p>Ist stupide ne Funktoion aus meinem Programm kopiert, aber so müsste es funktionieren. Musst es dir nur noch für dich umschreiben <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<pre><code class="language-cpp">void Settings::FindStringW (int iID, std::wstring &amp;strWide)
{
	wchar_t		*pwchMem	= NULL;
	wchar_t		*pwchCur	= NULL;
	HMODULE		hModule		= NULL;
	int			strIndex	= iID % 16;

	// Current module
	hModule = LS.hModule;

	HRSRC hRes = FindResourceW (hModule, MAKEINTRESOURCEW((iID / 16) +1), MAKEINTRESOURCEW(6));
	if (hRes != NULL)
	{
		pwchMem = reinterpret_cast&lt;wchar_t*&gt; (LoadResource (hModule, hRes));
		if (pwchMem != NULL)
		{
			pwchCur = pwchMem;
			for (int i = 0; i &lt; 16; i++)
			{
				if (*pwchCur != NULL)
				{
					int cchString = *pwchCur;	// String length in characters
					pwchCur++;

					if (i == strIndex)
					{
						// String was found in string table
						strWide.~basic_string();
						strWide.insert (0, pwchCur, cchString);

						FreeResource (pwchMem);
						return;
					}
					pwchCur += cchString;
				}
				else
					pwchCur++;
			}
		}
	}
	else
	{
		err.NewError (EXCEPTION, L&quot;FindResource failed, Settings::FindStringW&quot;, L&quot;%x (hModule), %i (iID), RT_STRING&quot;, 
						hModule, iID);
	}
	return;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1578257</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1578257</guid><dc:creator><![CDATA[_yogle]]></dc:creator><pubDate>Sun, 07 Sep 2008 20:04:47 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] LoadString dynamisch? on Mon, 08 Sep 2008 08:41:01 GMT]]></title><description><![CDATA[<blockquote>
<p>Musst es dir nur noch für dich umschreiben</p>
</blockquote>
<p>Das habe ich hier bereits in fix und fertig:</p>
<pre><code class="language-cpp">UINT GetStringLength(HINSTANCE hInst, UINT uID)
{
    HGLOBAL hGlobal;
    LPWSTR  pwstr;
    HRSRC   hrsrc;
    UINT    uLen = 0, x;

    if(NULL == (hrsrc = FindResource(hInst, MAKEINTRESOURCE((uID / 16) + 1), RT_STRING)))
        return(0);

    if(NULL == (hGlobal = LoadResource(hInst, hrsrc)))
        return(0);

    if(NULL != (pwstr = (LPWSTR)LockResource(hGlobal)))
    {
        for(x = (uID % 16) + 1; x; --x)
        {
            uLen = *pwstr;
            pwstr += (uLen + 1);
        }
        UnlockResource(hGlobal);
    }

    FreeResource(hGlobal);
    return(uLen);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1578441</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1578441</guid><dc:creator><![CDATA[Gästchen]]></dc:creator><pubDate>Mon, 08 Sep 2008 08:41:01 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] LoadString dynamisch? on Mon, 08 Sep 2008 12:12:25 GMT]]></title><description><![CDATA[<p>Danke euch Allen!<br />
Habe erst mit FindResource und SizeofResource die Größe bestimmt, ein WCHAR-Array angelegt, und dann mit LoadString gefüllt.</p>
<p>Ich bin vorher an FindResource gescheitert, habe nicht durch 16 dividiert und dann um 1 addiert, sondern einfach die ID 1 zu 1 übernommen.<br />
Ach ja: ich habe die Division durch 16 um ein Bitshift ersetzt, ist performanter.</p>
<p>Sieht jetzt so aus:</p>
<pre><code class="language-cpp">String GTCORE_API LoadStringFromStringTable(HINSTANCE hModule,
											UINT uID)
{
	//Länge herausfinden	
	DWORD dwLength= SizeofResource(hModule, FindResource(hModule,MAKEINTRESOURCEW( (uID &gt;&gt; 4) + 1 ),RT_STRING) );
	if(!dwLength)
		throw(std::runtime_error(&quot;DWORD dwLength= SizeofResource(hModule, FindResource(hModule,MAKEINTRESOURCEW( (uID &gt;&gt; 4) + 1 ),RT_STRING) );&quot;));
	WCHAR *pwcBuffer=new WCHAR[dwLength];

	//String laden
	::LoadStringW(hModule,uID,pwcBuffer,dwLength);
	String Str(pwcBuffer);
	delete[](pwcBuffer);

	return(Str);
}
</code></pre>
<p><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="🙂"
    /> Und funktioniert!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1578580</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1578580</guid><dc:creator><![CDATA[Blaze]]></dc:creator><pubDate>Mon, 08 Sep 2008 12:12:25 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] LoadString dynamisch? on Mon, 08 Sep 2008 12:41:54 GMT]]></title><description><![CDATA[<blockquote>
<p>ich habe die Division durch 16 um ein Bitshift ersetzt, ist performanter.</p>
</blockquote>
<p>Gemessen oder geraten? Das optimiert der Compiler doch automatisch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1578606</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1578606</guid><dc:creator><![CDATA[oO]]></dc:creator><pubDate>Mon, 08 Sep 2008 12:41:54 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] LoadString dynamisch? on Mon, 08 Sep 2008 17:36:42 GMT]]></title><description><![CDATA[<p>Blaze schrieb:</p>
<blockquote>
<p><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="🙂"
    /> Und funktioniert!</p>
</blockquote>
<p>Schau Dir dwLength bitte einmal genauer an. Das ist never ever die Länge des Strings!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1578789</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1578789</guid><dc:creator><![CDATA[Gästchen]]></dc:creator><pubDate>Mon, 08 Sep 2008 17:36:42 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] LoadString dynamisch? on Mon, 08 Sep 2008 23:20:13 GMT]]></title><description><![CDATA[<p>Ich hab das noch nie benutzt ...<br />
Was bitte hat das mit der Division der ResourceID durch 16 und anschließenden Addition von 1 für eine Bewandnis?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1578906</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1578906</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Mon, 08 Sep 2008 23:20:13 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] LoadString dynamisch? on Tue, 09 Sep 2008 08:57:15 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Belli schrieb:</p>
<blockquote>
<p>Ich hab das noch nie benutzt ...<br />
Was bitte hat das mit der Division der ResourceID durch 16 und anschließenden Addition von 1 für eine Bewandnis?</p>
</blockquote>
<p>Diese Formel ergibt sich aus der Tatsache, dass die Zeichenketten in Resource-Dateien in 16er-Blöcken verwaltet werden, durch die Bitverschiebung wird ein Block angewählt, und weil die eigentlichen IDs pro Block mit 1 starten, muss das noch addiert werden.</p>
<p>Siehe dazu auch die Ausführungen hier:</p>
<p><a href="http://blogs.msdn.com/oldnewthing/archive/2004/01/30/65013.aspx" rel="nofollow">http://blogs.msdn.com/oldnewthing/archive/2004/01/30/65013.aspx</a></p>
<p>MfG,</p>
<p>Probe-Nutzer</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1579037</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1579037</guid><dc:creator><![CDATA[Probe-Nutzer]]></dc:creator><pubDate>Tue, 09 Sep 2008 08:57:15 GMT</pubDate></item></channel></rss>