<?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[C_Wrapper]]></title><description><![CDATA[<p>Hallo Zusammen,</p>
<p>ich habe einen Dummy Projekt (C++) &quot;um DLL zu erstellen&quot; erstellt und<br />
dafür einen C_Wrapper geschrieben:<br />
Myclass.h</p>
<pre><code>#pragma once
//#include &lt;QString&gt;
class MyClass
{
public:
  MyClass(double, double);
  ~MyClass();
  double Add(double,double );
  double Subst(double, double);
  double Mult(double, double);
  double Divid(double, double);
  bool Vergleich(double,double);
  long Avg_num(float *, long, float *);
  unsigned int NumInteger(char * inputString);
  //QString GibEinString(double, double);
private:
  double m_a, m_b;
};
</code></pre>
<p>MyClass.cpp</p>
<pre><code>#include &quot;stdafx.h&quot;
#include &quot;MyClass.h&quot;

MyClass::MyClass(double a,double b)
{
  this-&gt;m_a = a;
  this-&gt;m_b = b;
}

MyClass::~MyClass(){ }

double MyClass::Add(double a, double b)
{
  return a+=b;
}
double MyClass::Mult(double a, double b)
{
  return a*=b;
}
double MyClass::Subst(double a, double b)
{
  return b-=a;
}
double MyClass::Divid(double a, double b)
{
  return (b / a);
}
bool MyClass::Vergleich(double a,double b)
{
  if(a&gt;=b) return true;
  else return false;
}

long MyClass::Avg_num(float *a, long size, float *avg)
{
  //avg_num ermittelt den einfachen Durchschnitt eines Arrays numerischer Werte
  float sum = 0;
  if(a != NULL)
    {
        for(int i=0;i &lt; size; i++)
        sum = sum + a[i];
    }
    else
        return (1);
    *avg = sum / size;
    return (0);
}
unsigned int MyClass::NumInteger(char * inputString)
{
  int lastDigit = 0;
    int numberOfNumbers = 0;
    int stringSize;

    stringSize = strlen(inputString);
    for(int i = 0; i &lt; stringSize; i++)
    {
        if (!lastDigit &amp;&amp; isdigit(inputString[i]))
            numberOfNumbers++;
        lastDigit = isdigit(inputString[i]);
    }
  //numIntegers bestimmt die Anzahl der Integer-Werte in einem String
    return numberOfNumbers;

}
</code></pre>
<p>C_Wrapper Header</p>
<pre><code>#pragma once
#define DLLIMPORT __declspec (dllexport)
#ifdef __cplusplus
extern &quot;C&quot; { 
#endif

typedef struct Wrapper
  {
    void *MYClass;
  }Wrapper;

  DLLIMPORT Wrapper createWrapper(double a, double b);
  DLLIMPORT void destoryWrapper(Wrapper LV_ref);

  DLLIMPORT double Add(Wrapper LV_ref, double a, double b);
  DLLIMPORT double Subst(Wrapper LV_ref ,double a, double b);
  DLLIMPORT double Mult(Wrapper LV_ref, double a, double b);
  DLLIMPORT double Divid(Wrapper LV_ref, double a, double b);
  DLLIMPORT bool Vergleich(Wrapper LV_ref, double a, double b);
  DLLIMPORT long Avg_num(Wrapper LV_ref,float *a, long size, float * avg);
  DLLIMPORT unsigned int NumInteger(Wrapper LV_ref, char * inputString);

#ifdef __cplusplus
}
#endif
</code></pre>
<p>c_Wrapper.cpp</p>
<pre><code>// DLL_Test_Labview.cpp : Defines the exported functions for the DLL application.
//

#include &quot;stdafx.h&quot;
#include &quot;MyClass.h&quot;
#include &quot;C_DllWrapper.h&quot;

DLLIMPORT Wrapper createWrapper(double a, double b)
{
  Wrapper wrapper = {static_cast&lt;void*&gt;(new MyClass(a,b))};
  return wrapper;
}

DLLIMPORT void destoryWrapper(Wrapper LV_ref)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  delete myClass;
}
DLLIMPORT double Add(Wrapper LV_ref, double a, double b)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;Add(a, b);
}

DLLIMPORT double Mult(Wrapper LV_ref, double a, double b)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;Mult(a, b);
}

DLLIMPORT double Subst(Wrapper LV_ref, double a, double b)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;Subst(a, b);
}

DLLIMPORT double Divid(Wrapper LV_ref, double a, double b)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;Divid(a, b);
}
DLLIMPORT bool Vergleich(Wrapper LV_ref, double a, double b)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;Vergleich(a,b);
}
DLLIMPORT long Avg_num(Wrapper LV_ref,float *a, long size, float * avg)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;Avg_num(a,size,avg);

}
DLLIMPORT unsigned int NumInteger(Wrapper LV_ref, char * inputString)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;NumInteger(inputString);
}
</code></pre>
<p>--&gt; Um dieses DLL zu testen habe ich TestProgramm geschrieben und es<br />
funktinoiert einwandfrei.<br />
Ich habe auch das DLL in Labview importiert und es funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/334255/c_wrapper</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Apr 2026 21:50:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/334255.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 01 Sep 2015 11:45:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C_Wrapper on Tue, 01 Sep 2015 11:45:50 GMT]]></title><description><![CDATA[<p>Hallo Zusammen,</p>
<p>ich habe einen Dummy Projekt (C++) &quot;um DLL zu erstellen&quot; erstellt und<br />
dafür einen C_Wrapper geschrieben:<br />
Myclass.h</p>
<pre><code>#pragma once
//#include &lt;QString&gt;
class MyClass
{
public:
  MyClass(double, double);
  ~MyClass();
  double Add(double,double );
  double Subst(double, double);
  double Mult(double, double);
  double Divid(double, double);
  bool Vergleich(double,double);
  long Avg_num(float *, long, float *);
  unsigned int NumInteger(char * inputString);
  //QString GibEinString(double, double);
private:
  double m_a, m_b;
};
</code></pre>
<p>MyClass.cpp</p>
<pre><code>#include &quot;stdafx.h&quot;
#include &quot;MyClass.h&quot;

MyClass::MyClass(double a,double b)
{
  this-&gt;m_a = a;
  this-&gt;m_b = b;
}

MyClass::~MyClass(){ }

double MyClass::Add(double a, double b)
{
  return a+=b;
}
double MyClass::Mult(double a, double b)
{
  return a*=b;
}
double MyClass::Subst(double a, double b)
{
  return b-=a;
}
double MyClass::Divid(double a, double b)
{
  return (b / a);
}
bool MyClass::Vergleich(double a,double b)
{
  if(a&gt;=b) return true;
  else return false;
}

long MyClass::Avg_num(float *a, long size, float *avg)
{
  //avg_num ermittelt den einfachen Durchschnitt eines Arrays numerischer Werte
  float sum = 0;
  if(a != NULL)
    {
        for(int i=0;i &lt; size; i++)
        sum = sum + a[i];
    }
    else
        return (1);
    *avg = sum / size;
    return (0);
}
unsigned int MyClass::NumInteger(char * inputString)
{
  int lastDigit = 0;
    int numberOfNumbers = 0;
    int stringSize;

    stringSize = strlen(inputString);
    for(int i = 0; i &lt; stringSize; i++)
    {
        if (!lastDigit &amp;&amp; isdigit(inputString[i]))
            numberOfNumbers++;
        lastDigit = isdigit(inputString[i]);
    }
  //numIntegers bestimmt die Anzahl der Integer-Werte in einem String
    return numberOfNumbers;

}
</code></pre>
<p>C_Wrapper Header</p>
<pre><code>#pragma once
#define DLLIMPORT __declspec (dllexport)
#ifdef __cplusplus
extern &quot;C&quot; { 
#endif

typedef struct Wrapper
  {
    void *MYClass;
  }Wrapper;

  DLLIMPORT Wrapper createWrapper(double a, double b);
  DLLIMPORT void destoryWrapper(Wrapper LV_ref);

  DLLIMPORT double Add(Wrapper LV_ref, double a, double b);
  DLLIMPORT double Subst(Wrapper LV_ref ,double a, double b);
  DLLIMPORT double Mult(Wrapper LV_ref, double a, double b);
  DLLIMPORT double Divid(Wrapper LV_ref, double a, double b);
  DLLIMPORT bool Vergleich(Wrapper LV_ref, double a, double b);
  DLLIMPORT long Avg_num(Wrapper LV_ref,float *a, long size, float * avg);
  DLLIMPORT unsigned int NumInteger(Wrapper LV_ref, char * inputString);

#ifdef __cplusplus
}
#endif
</code></pre>
<p>c_Wrapper.cpp</p>
<pre><code>// DLL_Test_Labview.cpp : Defines the exported functions for the DLL application.
//

#include &quot;stdafx.h&quot;
#include &quot;MyClass.h&quot;
#include &quot;C_DllWrapper.h&quot;

DLLIMPORT Wrapper createWrapper(double a, double b)
{
  Wrapper wrapper = {static_cast&lt;void*&gt;(new MyClass(a,b))};
  return wrapper;
}

DLLIMPORT void destoryWrapper(Wrapper LV_ref)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  delete myClass;
}
DLLIMPORT double Add(Wrapper LV_ref, double a, double b)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;Add(a, b);
}

DLLIMPORT double Mult(Wrapper LV_ref, double a, double b)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;Mult(a, b);
}

DLLIMPORT double Subst(Wrapper LV_ref, double a, double b)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;Subst(a, b);
}

DLLIMPORT double Divid(Wrapper LV_ref, double a, double b)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;Divid(a, b);
}
DLLIMPORT bool Vergleich(Wrapper LV_ref, double a, double b)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;Vergleich(a,b);
}
DLLIMPORT long Avg_num(Wrapper LV_ref,float *a, long size, float * avg)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;Avg_num(a,size,avg);

}
DLLIMPORT unsigned int NumInteger(Wrapper LV_ref, char * inputString)
{
  MyClass *myClass = static_cast&lt;MyClass*&gt;(LV_ref.MYClass);
  return myClass-&gt;NumInteger(inputString);
}
</code></pre>
<p>--&gt; Um dieses DLL zu testen habe ich TestProgramm geschrieben und es<br />
funktinoiert einwandfrei.<br />
Ich habe auch das DLL in Labview importiert und es funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2466450</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2466450</guid><dc:creator><![CDATA[MarcoGast]]></dc:creator><pubDate>Tue, 01 Sep 2015 11:45:50 GMT</pubDate></item><item><title><![CDATA[Reply to C_Wrapper on Tue, 01 Sep 2015 11:51:36 GMT]]></title><description><![CDATA[<p>Nun wollte ich das fast das gleiche testen aber dieses Mal mit dem echten projekt.</p>
<p>Meine echten Objeckt sieht wie folgende aus:<br />
Original Class:</p>
<pre><code>class MyClass : public QObject
{
  Q_OBJECT

public:
  MYCLASS_EXPORT MyClass(bool boSimulate_p, QString &amp;strFileSettings_p=QString(&quot;settingsFile.ini&quot;)); // settingsFile ist eine ini File und bestimmte Einstellung zu speichern und wieder aufzurufen
  MYCLASS_EXPORT ~MyClass();
  ....
}
</code></pre>
<p>C_Wrapper (für MyClass):</p>
<p>Header File</p>
<pre><code>#ifndef _C_DLL_EFILIBWRAPPER_H_
#define _C_DLL_EFILIBWRAPPER_H_

/* building a DLL */

#define DLLIMPORT __declspec (dllexport)

#ifdef __cplusplus
   extern &quot;C&quot; { /* using a C++ compiler */
#endif

      typedef struct MYCLASSWrapper
    {
      void *C; 
    }MYCLASSWrapper;

    DLLIMPORT MYCLASSWrapper create_MyClass(bool boSimulate_p);
    DLLIMPORT MYCLASSWrapper create_MyClassWithSettingsFile(bool boSimulate_p, const char *strFileSettings_p);

    DLLIMPORT void destory_MYCLASSWrapper(MYCLASSWrapper LV_ref_MyClass);
    .....
      #ifdef __cplusplus
    }
#endif
#endif
</code></pre>
<p>// Cpp File (C_Wrapper (für MyClass)):</p>
<pre><code>DLLIMPORT MYCLASSWrapper create_MyClass(bool boSimulate_p)
{
  const char *strFileSettings_p = &quot;settings.ini&quot;;
  return create_MyClassWithSettingsFile(boSimulate_p,strFileSettings_p);
}

DLLIMPORT MYCLASSWrapper create_MyClassWithSettingsFile(bool boSimulate_p, const char *strFileSettings_p)
{

  MYCLASSWrapper MyClassWrapper = {static_cast&lt;void*&gt;(new MyClass(boSimulate_p,QString::QString(strFileSettings_p)))};

  return MyClassWrapper; 
}
</code></pre>
<p>Nun habe ich festgestellt, dass meinen Struct (in echten Projekt) gleich<br />
0 ist, was nicht richtig ist.</p>
<p>Was mache ich denn falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2466451</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2466451</guid><dc:creator><![CDATA[MarcoGast]]></dc:creator><pubDate>Tue, 01 Sep 2015 11:51:36 GMT</pubDate></item><item><title><![CDATA[Reply to C_Wrapper on Tue, 01 Sep 2015 13:46:42 GMT]]></title><description><![CDATA[<p>MarcoGast schrieb:</p>
<blockquote>
<p>Nun habe ich festgestellt, dass meinen Struct (in echten Projekt) gleich<br />
0 ist, was nicht richtig ist.</p>
<p>Was mache ich denn falsch?</p>
</blockquote>
<p>Du irgendwie irgendwo irgendwas festgestellt, aber keinen Code geliefert, der den Fehler reproduziert. Da wird dir wohl niemand helfen können.</p>
<p>Benutze einen Debugger, überprüfe, wann es nach create_MyClassWithSettingsFile schief geht.<br />
Wird vielleicht eine Exception geworfen und ignoriert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2466465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2466465</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Tue, 01 Sep 2015 13:46:42 GMT</pubDate></item><item><title><![CDATA[Reply to C_Wrapper on Wed, 02 Sep 2015 14:28:10 GMT]]></title><description><![CDATA[<p>Hi alle zusammen,</p>
<p>Ich bin mittlerweile weiter gekommen.<br />
Nun hakt in eine Sache und zwar:</p>
<p>Eine Methode von meinem C_Wrapper hat als Rückgabeparameter eine Klasse &quot;Bclass&quot;.</p>
<p>nehmen wir einen Beispiel:</p>
<p>Die Methode sieht so aus:</p>
<pre><code>Bclass Measure(MYCLASSWrapper LV_ref_MyClass);
</code></pre>
<p>Bclass ist wie folgende definiert :</p>
<pre><code>class Bclass 
{
	public:
	Bclass();
	Bclass(Sclass * pSclass);
	Bclass(const Bclass *e) ;    // CopyConstructor
	{
		s1 = e.s1;
		s2 =e.s2;
		.....
	}
	virtual ~Bclass(){}
	.....

};
</code></pre>
<p>Sclass ist wie folgende definiert:</p>
<pre><code>class Sclass: public Aclass, public Eclass, public Dclass
{

};
</code></pre>
<p>Meine Frage ist :wie soll ich meine Wrapper für dieses Funktion &quot;Bclass Measure(MYCLASSWrapper LV_ref_MyClass)&quot; schreiben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2466581</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2466581</guid><dc:creator><![CDATA[MarcoGast]]></dc:creator><pubDate>Wed, 02 Sep 2015 14:28:10 GMT</pubDate></item><item><title><![CDATA[Reply to C_Wrapper on Wed, 02 Sep 2015 18:01:36 GMT]]></title><description><![CDATA[<p>Wenn du C-Wrapper benötigst, dann mußt du für alle deine Klassen Wrapper erstellen, also auch eine Bclass_Wrapper:</p>
<pre><code class="language-cpp">Bclass_Wrapper Measure(MYCLASSWrapper LV_ref_MyClass);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2466626</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2466626</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Wed, 02 Sep 2015 18:01:36 GMT</pubDate></item></channel></rss>