<?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[DLL -Funktionsaufruf mit Paramterübergabe]]></title><description><![CDATA[<p>Guten Tag liebes Forum,</p>
<p><strong>folgendes Problem:</strong></p>
<p>Ich habe eine DLL vorliegen. Leider fehlt mir jegliche Beschreibung dazu. Einzig ein Code-Sample, mit dem aus VB heraus darauf zugegriffen wird lieg mir vor. Das Sample funktioniert auch soweit in VB. Nun benötige ich das Gleiche jedoch in C++. Leider bereitet mr das Probleme.</p>
<pre><code class="language-cpp">CString GetBeispielfunktionFunktion()
{
	HMODULE handle;
	handle = LoadLibrary(&quot;beispiel.dll&quot;);
	if (handle==NULL)
		return &quot;Fehler&quot;;

	wchar_t *in ;
	wchar_t *out;

	out= new wchar_t[40];
	in= new wchar_t[6];
	in[0]='9';
	in[1]='2';
	in[2]='7';
	in[3]='6';
	in[4]='3';
	in[5]='\0';
	int b=6;

        if (handle != NULL)
		{
		typedef void (*DLLFUNC)(wchar_t*,wchar_t*,int);
		DLLFUNC func = (DLLFUNC)GetProcAddress(*handle, &quot;GetText&quot;);

		if (func)
			func(out,in,b);
		}
return (LPCWSTR) out;
}
</code></pre>
<p>**<br />
Das Code-Sample für den Zugriff in VB:**</p>
<pre><code>Public Class Form1

    Declare Sub GetText Lib &quot;beispiel.dll&quot; ( _
        ByVal OutputString As String, _
        ByVal InputString As String, _
        ByVal InputLength As Byte)

 Dim outbuff As Char(40)

    Public Function GetText(ByVal InputString As String) As String

        GetText (outbuff, InputString, Len(InputString))
        MsgBox outbuff
    End Function
End Class
</code></pre>
<p>Dem Beispiel in VB nach gehe ich mal davon aus, dass ein char [40] als output übergeben, ein char * als Eingabe und ein int als Längenangabe für den Input reichen sollten.</p>
<p>Soweit ich die Aufstellung hier <a href="http://msdn.microsoft.com/de-de/library/4xwz0t37.aspx" rel="nofollow">http://msdn.microsoft.com/de-de/library/4xwz0t37.aspx</a> verstanden habe, verwende ich die richtigen Datentypen.</p>
<p><strong>Meine Fehlermeldung:</strong></p>
<p>Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.</p>
<p>Hat jemand eine Idee, wo das Problem liegen könnte?</p>
<p>gruß<br />
klaus</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/230285/dll-funktionsaufruf-mit-paramterübergabe</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 01:10:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/230285.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 23 Dec 2008 14:12:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to DLL -Funktionsaufruf mit Paramterübergabe on Tue, 23 Dec 2008 14:12:41 GMT]]></title><description><![CDATA[<p>Guten Tag liebes Forum,</p>
<p><strong>folgendes Problem:</strong></p>
<p>Ich habe eine DLL vorliegen. Leider fehlt mir jegliche Beschreibung dazu. Einzig ein Code-Sample, mit dem aus VB heraus darauf zugegriffen wird lieg mir vor. Das Sample funktioniert auch soweit in VB. Nun benötige ich das Gleiche jedoch in C++. Leider bereitet mr das Probleme.</p>
<pre><code class="language-cpp">CString GetBeispielfunktionFunktion()
{
	HMODULE handle;
	handle = LoadLibrary(&quot;beispiel.dll&quot;);
	if (handle==NULL)
		return &quot;Fehler&quot;;

	wchar_t *in ;
	wchar_t *out;

	out= new wchar_t[40];
	in= new wchar_t[6];
	in[0]='9';
	in[1]='2';
	in[2]='7';
	in[3]='6';
	in[4]='3';
	in[5]='\0';
	int b=6;

        if (handle != NULL)
		{
		typedef void (*DLLFUNC)(wchar_t*,wchar_t*,int);
		DLLFUNC func = (DLLFUNC)GetProcAddress(*handle, &quot;GetText&quot;);

		if (func)
			func(out,in,b);
		}
return (LPCWSTR) out;
}
</code></pre>
<p>**<br />
Das Code-Sample für den Zugriff in VB:**</p>
<pre><code>Public Class Form1

    Declare Sub GetText Lib &quot;beispiel.dll&quot; ( _
        ByVal OutputString As String, _
        ByVal InputString As String, _
        ByVal InputLength As Byte)

 Dim outbuff As Char(40)

    Public Function GetText(ByVal InputString As String) As String

        GetText (outbuff, InputString, Len(InputString))
        MsgBox outbuff
    End Function
End Class
</code></pre>
<p>Dem Beispiel in VB nach gehe ich mal davon aus, dass ein char [40] als output übergeben, ein char * als Eingabe und ein int als Längenangabe für den Input reichen sollten.</p>
<p>Soweit ich die Aufstellung hier <a href="http://msdn.microsoft.com/de-de/library/4xwz0t37.aspx" rel="nofollow">http://msdn.microsoft.com/de-de/library/4xwz0t37.aspx</a> verstanden habe, verwende ich die richtigen Datentypen.</p>
<p><strong>Meine Fehlermeldung:</strong></p>
<p>Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.</p>
<p>Hat jemand eine Idee, wo das Problem liegen könnte?</p>
<p>gruß<br />
klaus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1634666</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1634666</guid><dc:creator><![CDATA[Junior]]></dc:creator><pubDate>Tue, 23 Dec 2008 14:12:41 GMT</pubDate></item><item><title><![CDATA[Reply to DLL -Funktionsaufruf mit Paramterübergabe on Tue, 23 Dec 2008 14:23:59 GMT]]></title><description><![CDATA[<p>als erstes würde ich mal</p>
<pre><code>typedef void (*DLLFUNC)(wchar_t*,wchar_t*,int);
</code></pre>
<p>auserhalb einer funktion &amp; der classe deklarieren.</p>
<p>zweitens,<br />
was soll *handle bringen</p>
<pre><code>DLLFUNC func = (DLLFUNC)GetProcAddress(*handle, &quot;GetText&quot;);
</code></pre>
<p>versuch das mal ohne pointer...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1634669</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1634669</guid><dc:creator><![CDATA[*rT*f*Ct]]></dc:creator><pubDate>Tue, 23 Dec 2008 14:23:59 GMT</pubDate></item><item><title><![CDATA[Reply to DLL -Funktionsaufruf mit Paramterübergabe on Tue, 23 Dec 2008 14:30:35 GMT]]></title><description><![CDATA[<p>Da fehtl aber noch ein &quot;__stdcall&quot; bei der Definition von DLLFUNC...<br />
Und am besten wchar_t durch BSTR ersetzen...<br />
Und &quot;int&quot; durch &quot;unsigned char&quot;...</p>
<p>Quasi so:</p>
<pre><code class="language-cpp">typedef void (__stdcall *DLLFUNC)(BSTR*,BSTR*,unsigned char);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1634672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1634672</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Tue, 23 Dec 2008 14:30:35 GMT</pubDate></item><item><title><![CDATA[Reply to DLL -Funktionsaufruf mit Paramterübergabe on Tue, 23 Dec 2008 14:38:25 GMT]]></title><description><![CDATA[<p>Naja, ich lag doch falsch... es muss nicht BSTR und auch nicht wchar_t heissen, sondern LPSTR...</p>
<pre><code class="language-cpp">typedef void (__stdcall *DLLFUNC)(LPSTR,LPSTR,unsigned char);
</code></pre>
<p>Siehe auch:<br />
<a href="http://sandsprite.com/CodeStuff/Writing_A_C_Dll_for_VB.html" rel="nofollow">http://sandsprite.com/CodeStuff/Writing_A_C_Dll_for_VB.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1634681</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1634681</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Tue, 23 Dec 2008 14:38:25 GMT</pubDate></item><item><title><![CDATA[Reply to DLL -Funktionsaufruf mit Paramterübergabe on Tue, 23 Dec 2008 15:05:35 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>vielen Dank für die rasend schnellen Antworten.<br />
Ich habe es euren Beiträgen nach mal umgebaut und bekomme nun keinen Fehler mehr.</p>
<p>Anbei noch der Code, falls jemand das gleiche Problem bekommt.</p>
<p>Danke nochmals für die Hilfe!!!!!!!!!!!!!<br />
und frohes Fest. :xmas1:</p>
<pre><code class="language-cpp">StdAfx.h

typedef void (__stdcall *DLLFUNC)(LPSTR,LPSTR,unsigned char);

...cpp

CString GetBeispielfunktionFunktion()
{
    HMODULE handle;
    handle = LoadLibrary(&quot;beispiel.dll&quot;);
    if (handle==NULL)
        return &quot;Fehler&quot;;

	BSTR in=L&quot;513511351&quot;;
	BSTR out [40];

	unsigned char b;
	b= '6';

        if (handle != NULL)
           {
           DLLFUNC func = (DLLFUNC)GetProcAddress(handle, &quot;GetText&quot;);

           if (func)
               func(LPSTR)out,(LPSTR)in,b);
        }

return (LPSTR) out;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1634694</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1634694</guid><dc:creator><![CDATA[Junior]]></dc:creator><pubDate>Tue, 23 Dec 2008 15:05:35 GMT</pubDate></item><item><title><![CDATA[Reply to DLL -Funktionsaufruf mit Paramterübergabe on Tue, 23 Dec 2008 20:50:01 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>so ganz war es das dann doch nicht.. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Irgendwas geht bei der Übergabe der Parameten noch schief. Ich bekomme eine Speicherzugriffsverletzung. Wenn ich es so mache, wie vorhergehenden post geschrieben, dann bekomme ich ein BSTR - Array mit 40 &lt;Schlechter pointer&gt; zurück. Kann mir jemand sagen, wie ich</p>
<p>1. einen BSTR mit 40 Zeichen zeichen erstelle ( BSTR b[40]; ???)<br />
2. diesen BSTR initialisiere, so dass mir die Zugriffsverletzung erspart bleibt.</p>
<p>ich bin für jede Hilfe dankbar!</p>
<pre><code class="language-cpp">StdAfx.h

#include &lt;comdef.h&gt;

typedef void (__stdcall *DLLFUNC)(LPSTR,LPSTR,unsigned char);

...cpp

CString GetBeispielFunktion(CString sIn)
{
	HMODULE handle;
	handle = LoadLibrary(&quot;beispiel.dll&quot;);
	if (handle==NULL)
		return &quot;Fehler&quot;;

	CString s;
	BSTR in=sIn.AllocSysString();

	// 40 Leerzeichen
	BSTR out=::SysAllocString(L&quot;                                        &quot;);

	sIn.Format(&quot;%d&quot;,sIn.GetLength());
	long nLen = sIn.GetLength() + 1;
	unsigned char* b = new unsigned char [ nLen ];   
	memcpy( b, sIn.GetBuffer(0), nLen ); 

        if (handle != NULL)
                {
                DLLFUNC func = (DLLFUNC)GetProcAddress(handle, &quot;GetText&quot;);

                if (func)
                        func(LPSTR)out,(LPSTR)in,*b);
                }
	s=out;

	// out und in wieder freigeben ?????? 

return (LPSTR) out;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1634861</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1634861</guid><dc:creator><![CDATA[Junior]]></dc:creator><pubDate>Tue, 23 Dec 2008 20:50:01 GMT</pubDate></item></channel></rss>