<?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[Speicherproblem&#x2F;TWAIN]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe ein Problem mit Speicherzuweisung, ich benutze den BDS 2006 und habe im folgenden die Klassen zur TWAIN-Ansteuerung von<br />
<a href="http://www.neatcpp.com/" rel="nofollow">http://www.neatcpp.com/</a> und <a href="http://www.allanpetersen.com" rel="nofollow">www.allanpetersen.com</a> modifiziert. Der Datentyp CCapValue ist folgendermaßen definiert:</p>
<pre><code class="language-cpp">union CCapValue
{
	int type;
	struct twain_array
	{
		pTW_ARRAY m_pValue;
		long m_nItemSize;
	}array;

	struct twain_enumeration
	{
		pTW_ENUMERATION m_pValue;
		long m_nItemSize;
	}enumeration;

	struct twain_onevalue
	{
		pTW_ONEVALUE m_pValue;
	}onevalue;

	struct twain_range
	{
		pTW_RANGE m_pValue;
	}range;
};
</code></pre>
<p>wobei pTW_ENUMERATION in twain.h so definiert ist:</p>
<pre><code class="language-cpp">/* TWON_ENUMERATION. Container for a collection of values. */
typedef struct {
   TW_UINT16  ItemType;
   TW_UINT32  NumItems;     /* How many items in ItemList                 */
   TW_UINT32  CurrentIndex; /* Current value is in ItemList[CurrentIndex] */
   TW_UINT32  DefaultIndex; /* Powerup value is in ItemList[DefaultIndex] */
   TW_UINT8   ItemList[1];  /* Array of ItemType values starts here       */
} TW_ENUMERATION, FAR * pTW_ENUMERATION;
</code></pre>
<p>Ich habe nun folgende Funktion</p>
<pre><code class="language-cpp">BOOL CTwain::GetDifferentCapability(TW_CAPABILITY&amp; twCap, CCapValue *CapInfo, TW_UINT16 cap,TW_UINT16 conType)
{
	CapInfo-&gt;type = capNone;
	if(GetCapability(twCap,cap))
	{
		 void * pValue = ::GlobalLock(twCap.hContainer);
		 pTW_ENUMERATION pEnum;
		 pTW_ARRAY pArray;
		 long nItemSize;
		 long nSize;
		 switch (twCap.ConType) {
			 case TWON_ARRAY:
				 ...

			case TWON_ENUMERATION:
				{
					pEnum = static_cast&lt;pTW_ENUMERATION&gt;(pValue);
					//CapInfo-&gt;enumeration.m_pValue = static_cast&lt;pTW_ENUMERATION&gt;(pValue);
					nItemSize = GetTwainTypeSize(pEnum-&gt;ItemType);
					if(nItemSize)
					{
						nSize = sizeof(TW_ENUMERATION) - sizeof(TW_UINT8) + nItemSize * pEnum-&gt;NumItems;
						void * pMem = new BYTE[nSize];
						memset(pMem, 0, nSize);
						int aa = sizeof(TW_ENUMERATION);
						int ab = sizeof(TW_UINT8);
						//CapInfo.enumeration.m_pValue = new TW_ENUMERATION;
						memcpy(pMem, pEnum, nSize);
						byte *test = new byte[nSize];
						memcpy (test, pMem, nSize);
						CapInfo-&gt;enumeration.m_pValue = static_cast&lt;pTW_ENUMERATION&gt;(pMem);  //(1)
						CapInfo-&gt;enumeration.m_nItemSize = nItemSize;
						CapInfo-&gt;type = capEnumeration;                                      //(2)
						int testrr = 0;                                                      //(3)   
					}

					break;
				}
			case TWON_ONEVALUE:
                                    ...  
			case TWON_RANGE:
		                  ...
			default:
				return false;
			}
	}
	::GlobalUnlock(twCap.hContainer);
	::GlobalFree(twCap.hContainer);
	return (CapInfo-&gt;type != capNone);
}
</code></pre>
<p>wobei ich bei ... der Übersichtlichkeit halber den Code entfernt habe, da mein Problem in</p>
<pre><code class="language-cpp">case TWON_ENUMERATION
</code></pre>
<p>auftritt.</p>
<p>Wenn ich mit dem Debugger durch die Funktion gehe, ist in case TWON_ENUMERATION auch alles ok,</p>
<pre><code class="language-cpp">CapInfo-&gt;enumeration.m_pValue
</code></pre>
<p>erhält in (1) eine Adresse und der Inhalt ist auch ok, wenn ich im Debugger von (2) nach (3) springe, so ändert sich die Adresse und der Inhalt ist nicht mehr definiert.</p>
<p>Hat irgendjemand eine Ahnung, woran das liegen könnte?</p>
<p>Gruss<br />
Lodo2609</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/195320/speicherproblem-twain</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 08:37:16 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/195320.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 16 Oct 2007 13:50:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Speicherproblem&#x2F;TWAIN on Tue, 16 Oct 2007 13:50:12 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe ein Problem mit Speicherzuweisung, ich benutze den BDS 2006 und habe im folgenden die Klassen zur TWAIN-Ansteuerung von<br />
<a href="http://www.neatcpp.com/" rel="nofollow">http://www.neatcpp.com/</a> und <a href="http://www.allanpetersen.com" rel="nofollow">www.allanpetersen.com</a> modifiziert. Der Datentyp CCapValue ist folgendermaßen definiert:</p>
<pre><code class="language-cpp">union CCapValue
{
	int type;
	struct twain_array
	{
		pTW_ARRAY m_pValue;
		long m_nItemSize;
	}array;

	struct twain_enumeration
	{
		pTW_ENUMERATION m_pValue;
		long m_nItemSize;
	}enumeration;

	struct twain_onevalue
	{
		pTW_ONEVALUE m_pValue;
	}onevalue;

	struct twain_range
	{
		pTW_RANGE m_pValue;
	}range;
};
</code></pre>
<p>wobei pTW_ENUMERATION in twain.h so definiert ist:</p>
<pre><code class="language-cpp">/* TWON_ENUMERATION. Container for a collection of values. */
typedef struct {
   TW_UINT16  ItemType;
   TW_UINT32  NumItems;     /* How many items in ItemList                 */
   TW_UINT32  CurrentIndex; /* Current value is in ItemList[CurrentIndex] */
   TW_UINT32  DefaultIndex; /* Powerup value is in ItemList[DefaultIndex] */
   TW_UINT8   ItemList[1];  /* Array of ItemType values starts here       */
} TW_ENUMERATION, FAR * pTW_ENUMERATION;
</code></pre>
<p>Ich habe nun folgende Funktion</p>
<pre><code class="language-cpp">BOOL CTwain::GetDifferentCapability(TW_CAPABILITY&amp; twCap, CCapValue *CapInfo, TW_UINT16 cap,TW_UINT16 conType)
{
	CapInfo-&gt;type = capNone;
	if(GetCapability(twCap,cap))
	{
		 void * pValue = ::GlobalLock(twCap.hContainer);
		 pTW_ENUMERATION pEnum;
		 pTW_ARRAY pArray;
		 long nItemSize;
		 long nSize;
		 switch (twCap.ConType) {
			 case TWON_ARRAY:
				 ...

			case TWON_ENUMERATION:
				{
					pEnum = static_cast&lt;pTW_ENUMERATION&gt;(pValue);
					//CapInfo-&gt;enumeration.m_pValue = static_cast&lt;pTW_ENUMERATION&gt;(pValue);
					nItemSize = GetTwainTypeSize(pEnum-&gt;ItemType);
					if(nItemSize)
					{
						nSize = sizeof(TW_ENUMERATION) - sizeof(TW_UINT8) + nItemSize * pEnum-&gt;NumItems;
						void * pMem = new BYTE[nSize];
						memset(pMem, 0, nSize);
						int aa = sizeof(TW_ENUMERATION);
						int ab = sizeof(TW_UINT8);
						//CapInfo.enumeration.m_pValue = new TW_ENUMERATION;
						memcpy(pMem, pEnum, nSize);
						byte *test = new byte[nSize];
						memcpy (test, pMem, nSize);
						CapInfo-&gt;enumeration.m_pValue = static_cast&lt;pTW_ENUMERATION&gt;(pMem);  //(1)
						CapInfo-&gt;enumeration.m_nItemSize = nItemSize;
						CapInfo-&gt;type = capEnumeration;                                      //(2)
						int testrr = 0;                                                      //(3)   
					}

					break;
				}
			case TWON_ONEVALUE:
                                    ...  
			case TWON_RANGE:
		                  ...
			default:
				return false;
			}
	}
	::GlobalUnlock(twCap.hContainer);
	::GlobalFree(twCap.hContainer);
	return (CapInfo-&gt;type != capNone);
}
</code></pre>
<p>wobei ich bei ... der Übersichtlichkeit halber den Code entfernt habe, da mein Problem in</p>
<pre><code class="language-cpp">case TWON_ENUMERATION
</code></pre>
<p>auftritt.</p>
<p>Wenn ich mit dem Debugger durch die Funktion gehe, ist in case TWON_ENUMERATION auch alles ok,</p>
<pre><code class="language-cpp">CapInfo-&gt;enumeration.m_pValue
</code></pre>
<p>erhält in (1) eine Adresse und der Inhalt ist auch ok, wenn ich im Debugger von (2) nach (3) springe, so ändert sich die Adresse und der Inhalt ist nicht mehr definiert.</p>
<p>Hat irgendjemand eine Ahnung, woran das liegen könnte?</p>
<p>Gruss<br />
Lodo2609</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1386423</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1386423</guid><dc:creator><![CDATA[lodo2609]]></dc:creator><pubDate>Tue, 16 Oct 2007 13:50:12 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherproblem&#x2F;TWAIN on Tue, 16 Oct 2007 15:32:04 GMT]]></title><description><![CDATA[<p>Du überschreibst damit ja auch wieder den Wert, da der Datentyp als Verbund (union) deklariert ist, d.h. alle Member innerhalb des Unions belegen denselben Speicherplatz:</p>
<pre><code class="language-cpp">union CCapValue
{
    int type;
    struct twain_array { ... };
    struct twain_enumeration { ... };
    ...
</code></pre>
<p>Also entweder in type oder in twain_enumeration etwas reinschreiben.<br />
Was soll überhaupt 'type' sein, d.h. woher kommt 'capEnumeration'?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1386509</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1386509</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Tue, 16 Oct 2007 15:32:04 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherproblem&#x2F;TWAIN on Tue, 16 Oct 2007 19:13:14 GMT]]></title><description><![CDATA[<p>danke, das wars. Hätte mir vorher durchlesen sollen, was eine union ist...</p>
<p>Gruss Lodo2609</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1386674</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1386674</guid><dc:creator><![CDATA[lodo2609]]></dc:creator><pubDate>Tue, 16 Oct 2007 19:13:14 GMT</pubDate></item></channel></rss>