<?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[Beim Compilieren keine Fehler. Excel stürzt aber ab.]]></title><description><![CDATA[<p>Hi,<br />
Ich habe versucht eine Funktion für Excel zu schreiben (Als Prototyp habe ich den <a href="http://www.codeproject.com/macro/InterpolationAddin.asp" rel="nofollow">Interpolation-Addin</a> genommen.).<br />
Der Versuch ist halbwegs gelungen, die Zahlen werden zurückgegeben, Excel stürzt aber gleich ab.</p>
<p>Vermutlich habe was mit der Speicherfreigabe falsch gemacht.</p>
<pre><code class="language-cpp">__declspec(dllexport) LPXLOPER MatCovar( LPXLOPER xArray )
{
   static XLOPER	resultBuffer[dimResult];	// Return Data Array

   LPXLOPER	xPtr;	// pointers to arrays of x table data

   static XLOPER	xMulti;	// xArray coerced to xltypeMulti

   short		hasXMulti = 0,  // flags to indicate memory has been allocated
		        error = -1;   // -1 if no error; error code otherwise

   ULONG		i, j, k,          // temporary index values
                xSizeC, xSizeR,	// number of columns and rows	
    		    xCount = 0;

   LPXLOPER	retArrayPtr,	// pointer to the return results array
		       tempPtr;		// temporary pointer
   static XLOPER	retMulti;		// return data structure

   // Initialize some variables
   tempTypeMulti.xltype = xltypeInt;
   tempTypeMulti.val.w = xltypeMulti;

   // ======= Get the xArray Data ==============
   // and verify the type
   if (	xArray-&gt;xltype != xltypeRef		&amp;&amp;
	xArray-&gt;xltype != xltypeSRef	&amp;&amp;
	xArray-&gt;xltype != xltypeMulti )
   {
	error = xlerrValue;
	goto done;
   }

   // Coerce the data into the &quot;Multi&quot; type since that's what we expect.
   // If coerce fails due to an uncalced cell, return immediately and Excel will
   // call us again in a moment after that cell has been calced.
   if ( xlretUncalced ==
	Excel4( xlCoerce, (LPXLOPER) &amp;xMulti, 2, (LPXLOPER) xArray,
	(LPXLOPER) &amp;tempTypeMulti ) )
   {
	return 0;
   }

   hasXMulti = 1;		// indicate that Excel has allocated memory for the xMulti

   // determine the size of the x table
    xSizeC = xMulti.val.array.columns; 
    xSizeR = xMulti.val.array.rows;
    xCount = xSizeC*xSizeR;

   // save some temporary pointers to the actual x table data
   // with lparray[]’s array index running from 0 to (val.array.rows * val.array.columns - 1) inclusive.
   xPtr = xMulti.val.array.lparray; 

   // set up the return array data structure
   // type is &quot;multi&quot;
   retMulti.xltype = xltypeMulti;

   retMulti.val.array.columns = xMulti.val.array.columns;
   retMulti.val.array.rows = xMulti.val.array.columns;

   // For efficiency, we have a static buffer that holds up to &quot;dimResult&quot; values
   // If it's large enough, use it.  Otherwise, allocate memory and tell excel to
   // call us back to free it ( via xlAutoFree ).
   if ( xCount &gt; dimResult )
   {
	retArrayPtr = (LPXLOPER) GlobalLock( hArray =
		GlobalAlloc( GMEM_ZEROINIT, xCount * sizeof(XLOPER)) );
	retMulti.xltype |= xlbitDLLFree;
   }
   else
   {
	hArray = 0;
	retArrayPtr = resultBuffer;
   }

   retMulti.val.array.lparray = retArrayPtr;

    // transforming one-dimensional array 'xMulti' into two-dimensional 'ORIG'
    double** ORIG = NULL;  // 
    double *Xm = NULL;     // for column averages

    ORIG = (double**) malloc(xSizeR*sizeof(double*)); //malloc(sizeof(double[])*xSizeR);
    for(i=0; i&lt;xSizeR; i++) // initializing arrays
    {
         ORIG[i]= (double*) malloc(sizeof(double)*xSizeC); 
    }
    Xm = (double*) malloc(sizeof(double)*xSizeC); 

    // populating the array
    for ( k=0; k &lt; xCount; k++ )
    {
        i = Round(k / xSizeC, 0);
        j = k  - i * xSizeC;
        ORIG[i][j] = xPtr[k].val.num;
    }

    //compute the mean for each column
    for(j = 0; j&lt;xSizeR; j++)
    { 
        s = 0;
        for(i = 0; i&lt;xSizeC; i++)
        {
            s = s + ORIG[i][j];
        }
        Xm[j] = s / xSizeR;
    }

    //compute the cross covariance matrix 
   for(i = 0; i&lt;xSizeC; i++)
   { 
      for(j = 0; j&lt;xSizeC; j++)
      { 
      // tempPtr points to the current element of the return data &quot;multi&quot; structure
      tempPtr = &amp;retArrayPtr[i*xSizeC+j];
      // the data type will be ordinary numeric (floating point) data
      tempPtr-&gt;xltype = xltypeNum;

      if(j &lt; i) 
      {
          //tempPtr-&gt;val.num = (&amp;retArrayPtr[j*xSizeC+i])-&gt;val.num; // ?????
          tempPtr-&gt;val.num = 77; // test
      }
      else 
      { 
          s = 0;
          for(k = 0; k&lt;xSizeR; k++) 
          {
              s = s + (ORIG[k][i] - Xm[i]) * (ORIG[k][j] - Xm[j]);
          }
          tempPtr-&gt;val.num = s / xSizeR;
        } 
      } 
    }    

    // freeing memory
    free((void *)Xm);
    for (i = 0; i &lt; xSizeR; i++) free((void *)ORIG[i]); 
    free((void *)ORIG); 

done:
   // free the memory allocated by Excel on our behalf
   if ( hasXMulti )
   Excel4( xlFree, 0, 1, (LPXLOPER) &amp;xMulti );

   // if the &quot;error&quot; variable was set above, something significant failed
   // and we should return an error for all x targets
   if ( error != -1 )
   {
	resultBuffer-&gt;xltype = xltypeErr;
	resultBuffer-&gt;val.err = error;

	return (LPXLOPER) resultBuffer;
   }

   if ( xCount &gt; 1 )
	return (LPXLOPER) &amp;retMulti;
   else
	return (LPXLOPER) resultBuffer;
}

// This function is called by Excel if the xlbitDLLFree bit has been set in the
// return array of the MatCovar function.  It allows us to free up allocated memory.
__declspec(dllexport) void xlAutoFree( LPXLOPER pxFree )
{
   if ( hArray )
   {
	GlobalUnlock( hArray );
	GlobalFree( hArray );
	hArray = 0;
   }
   return;
}
</code></pre>
<p>Compiler: Dev-c++<br />
Code: _http://rapidshare.de/files/14492264/MatCovar.rar.html<br />
Kenntnissstand: Anfänger</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/138907/beim-compilieren-keine-fehler-excel-stürzt-aber-ab</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 09:57:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/138907.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 Mar 2006 10:44:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Beim Compilieren keine Fehler. Excel stürzt aber ab. on Thu, 02 Mar 2006 12:15:52 GMT]]></title><description><![CDATA[<p>Hi,<br />
Ich habe versucht eine Funktion für Excel zu schreiben (Als Prototyp habe ich den <a href="http://www.codeproject.com/macro/InterpolationAddin.asp" rel="nofollow">Interpolation-Addin</a> genommen.).<br />
Der Versuch ist halbwegs gelungen, die Zahlen werden zurückgegeben, Excel stürzt aber gleich ab.</p>
<p>Vermutlich habe was mit der Speicherfreigabe falsch gemacht.</p>
<pre><code class="language-cpp">__declspec(dllexport) LPXLOPER MatCovar( LPXLOPER xArray )
{
   static XLOPER	resultBuffer[dimResult];	// Return Data Array

   LPXLOPER	xPtr;	// pointers to arrays of x table data

   static XLOPER	xMulti;	// xArray coerced to xltypeMulti

   short		hasXMulti = 0,  // flags to indicate memory has been allocated
		        error = -1;   // -1 if no error; error code otherwise

   ULONG		i, j, k,          // temporary index values
                xSizeC, xSizeR,	// number of columns and rows	
    		    xCount = 0;

   LPXLOPER	retArrayPtr,	// pointer to the return results array
		       tempPtr;		// temporary pointer
   static XLOPER	retMulti;		// return data structure

   // Initialize some variables
   tempTypeMulti.xltype = xltypeInt;
   tempTypeMulti.val.w = xltypeMulti;

   // ======= Get the xArray Data ==============
   // and verify the type
   if (	xArray-&gt;xltype != xltypeRef		&amp;&amp;
	xArray-&gt;xltype != xltypeSRef	&amp;&amp;
	xArray-&gt;xltype != xltypeMulti )
   {
	error = xlerrValue;
	goto done;
   }

   // Coerce the data into the &quot;Multi&quot; type since that's what we expect.
   // If coerce fails due to an uncalced cell, return immediately and Excel will
   // call us again in a moment after that cell has been calced.
   if ( xlretUncalced ==
	Excel4( xlCoerce, (LPXLOPER) &amp;xMulti, 2, (LPXLOPER) xArray,
	(LPXLOPER) &amp;tempTypeMulti ) )
   {
	return 0;
   }

   hasXMulti = 1;		// indicate that Excel has allocated memory for the xMulti

   // determine the size of the x table
    xSizeC = xMulti.val.array.columns; 
    xSizeR = xMulti.val.array.rows;
    xCount = xSizeC*xSizeR;

   // save some temporary pointers to the actual x table data
   // with lparray[]’s array index running from 0 to (val.array.rows * val.array.columns - 1) inclusive.
   xPtr = xMulti.val.array.lparray; 

   // set up the return array data structure
   // type is &quot;multi&quot;
   retMulti.xltype = xltypeMulti;

   retMulti.val.array.columns = xMulti.val.array.columns;
   retMulti.val.array.rows = xMulti.val.array.columns;

   // For efficiency, we have a static buffer that holds up to &quot;dimResult&quot; values
   // If it's large enough, use it.  Otherwise, allocate memory and tell excel to
   // call us back to free it ( via xlAutoFree ).
   if ( xCount &gt; dimResult )
   {
	retArrayPtr = (LPXLOPER) GlobalLock( hArray =
		GlobalAlloc( GMEM_ZEROINIT, xCount * sizeof(XLOPER)) );
	retMulti.xltype |= xlbitDLLFree;
   }
   else
   {
	hArray = 0;
	retArrayPtr = resultBuffer;
   }

   retMulti.val.array.lparray = retArrayPtr;

    // transforming one-dimensional array 'xMulti' into two-dimensional 'ORIG'
    double** ORIG = NULL;  // 
    double *Xm = NULL;     // for column averages

    ORIG = (double**) malloc(xSizeR*sizeof(double*)); //malloc(sizeof(double[])*xSizeR);
    for(i=0; i&lt;xSizeR; i++) // initializing arrays
    {
         ORIG[i]= (double*) malloc(sizeof(double)*xSizeC); 
    }
    Xm = (double*) malloc(sizeof(double)*xSizeC); 

    // populating the array
    for ( k=0; k &lt; xCount; k++ )
    {
        i = Round(k / xSizeC, 0);
        j = k  - i * xSizeC;
        ORIG[i][j] = xPtr[k].val.num;
    }

    //compute the mean for each column
    for(j = 0; j&lt;xSizeR; j++)
    { 
        s = 0;
        for(i = 0; i&lt;xSizeC; i++)
        {
            s = s + ORIG[i][j];
        }
        Xm[j] = s / xSizeR;
    }

    //compute the cross covariance matrix 
   for(i = 0; i&lt;xSizeC; i++)
   { 
      for(j = 0; j&lt;xSizeC; j++)
      { 
      // tempPtr points to the current element of the return data &quot;multi&quot; structure
      tempPtr = &amp;retArrayPtr[i*xSizeC+j];
      // the data type will be ordinary numeric (floating point) data
      tempPtr-&gt;xltype = xltypeNum;

      if(j &lt; i) 
      {
          //tempPtr-&gt;val.num = (&amp;retArrayPtr[j*xSizeC+i])-&gt;val.num; // ?????
          tempPtr-&gt;val.num = 77; // test
      }
      else 
      { 
          s = 0;
          for(k = 0; k&lt;xSizeR; k++) 
          {
              s = s + (ORIG[k][i] - Xm[i]) * (ORIG[k][j] - Xm[j]);
          }
          tempPtr-&gt;val.num = s / xSizeR;
        } 
      } 
    }    

    // freeing memory
    free((void *)Xm);
    for (i = 0; i &lt; xSizeR; i++) free((void *)ORIG[i]); 
    free((void *)ORIG); 

done:
   // free the memory allocated by Excel on our behalf
   if ( hasXMulti )
   Excel4( xlFree, 0, 1, (LPXLOPER) &amp;xMulti );

   // if the &quot;error&quot; variable was set above, something significant failed
   // and we should return an error for all x targets
   if ( error != -1 )
   {
	resultBuffer-&gt;xltype = xltypeErr;
	resultBuffer-&gt;val.err = error;

	return (LPXLOPER) resultBuffer;
   }

   if ( xCount &gt; 1 )
	return (LPXLOPER) &amp;retMulti;
   else
	return (LPXLOPER) resultBuffer;
}

// This function is called by Excel if the xlbitDLLFree bit has been set in the
// return array of the MatCovar function.  It allows us to free up allocated memory.
__declspec(dllexport) void xlAutoFree( LPXLOPER pxFree )
{
   if ( hArray )
   {
	GlobalUnlock( hArray );
	GlobalFree( hArray );
	hArray = 0;
   }
   return;
}
</code></pre>
<p>Compiler: Dev-c++<br />
Code: _http://rapidshare.de/files/14492264/MatCovar.rar.html<br />
Kenntnissstand: Anfänger</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006586</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006586</guid><dc:creator><![CDATA[eLiNK]]></dc:creator><pubDate>Thu, 02 Mar 2006 12:15:52 GMT</pubDate></item><item><title><![CDATA[Reply to Beim Compilieren keine Fehler. Excel stürzt aber ab. on Thu, 02 Mar 2006 11:29:34 GMT]]></title><description><![CDATA[<p>sowas gehört ins WinAPI forum...</p>
<p>mfg blan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006635</guid><dc:creator><![CDATA[blan]]></dc:creator><pubDate>Thu, 02 Mar 2006 11:29:34 GMT</pubDate></item><item><title><![CDATA[Reply to Beim Compilieren keine Fehler. Excel stürzt aber ab. on Thu, 02 Mar 2006 16:07:18 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile.php?mode=viewprofile&amp;u=13512" rel="nofollow">c.rackwitz</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=10" rel="nofollow">ANSI C</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=4" rel="nofollow">WinAPI</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006973</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Thu, 02 Mar 2006 16:07:18 GMT</pubDate></item><item><title><![CDATA[Reply to Beim Compilieren keine Fehler. Excel stürzt aber ab. on Thu, 02 Mar 2006 16:35:35 GMT]]></title><description><![CDATA[<p>Warum debuggst Du nicht? Einfach Excel als Startup-Project angeben...<br />
PS: Warum verwendest Du nicht MS VC++ Express 2005!?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006997</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006997</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Thu, 02 Mar 2006 16:35:35 GMT</pubDate></item><item><title><![CDATA[Reply to Beim Compilieren keine Fehler. Excel stürzt aber ab. on Fri, 03 Mar 2006 09:38:29 GMT]]></title><description><![CDATA[<p><strong>Jochen Kalmbach</strong><br />
Vielen Dank für den Tipp.<br />
Hat geholfen. <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="🙂"
    /></p>
<p>Ich programmiere mehr aus Spaß und bisher ausschließlich in VBA unter Excel.<br />
Habe aber vor kurzem festgestellt, daß ich mit VBA bei einigen Aufgaben nicht weiterkomme und habe den Einstieg in C++ gewagt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1007391</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1007391</guid><dc:creator><![CDATA[eLiNK]]></dc:creator><pubDate>Fri, 03 Mar 2006 09:38:29 GMT</pubDate></item><item><title><![CDATA[Reply to Beim Compilieren keine Fehler. Excel stürzt aber ab. on Fri, 03 Mar 2006 09:38:20 GMT]]></title><description><![CDATA[<p>Gern geschehen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1007407</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1007407</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Fri, 03 Mar 2006 09:38:20 GMT</pubDate></item></channel></rss>