Note that there are some explanatory texts on larger screens.

plurals
  1. POcall C# class from C++CLR
    primarykey
    data
    text
    <p>I want to call <code>C#</code> class from <code>C++CLR</code>. I have also created the wrapper for the same. Suppose In <code>C#</code> class library:</p> <pre><code>namespace MyImage { public class DicomHandler { public void TestImage(DicomImage dicomImage,int height,int width) { } } public class DicomImage { } } </code></pre> <p>Then in the <code>Wrapper</code>, I have created the object of <code>DicomHandler</code> and I need to call the <code>TestImage(DicomImage dicomImage,int height,int width)</code>.</p> <p>Wrapper class library includes,</p> <p>In IWrapper.h</p> <pre><code>#pragma once #include&lt;windows.h&gt; #include &lt;string&gt; using namespace MyImage; #ifdef MANAGEDWRAPPER_EXPORTS #define DLLAPI __declspec(dllexport) #else #define DLLAPI __declspec(dllimport) #pragma comment(lib,"F:\\8May\\firebreath-FireBreath-firebreath-1.7.0-0- gdf8659e\\firebreath\\Wrapper\\Debug\\Wrapper.lib") #endif class IWrapper { public: static IWrapper *CreateInstance(); static void Destroy(IWrapper *instance); virtual DLLAPI void Sethandle(HWND handle)=0; virtual DLLAPI void TestDicomImage(DicomImage^ _dicomImage,int width,int height)=0; }; In Wrapper.h, #pragma once #include &lt;windows.h&gt; #include &lt;vcclr.h&gt; #include "IWrapper.h" #include "stdio.h" #include "string.h" using namespace System; using namespace System::Reflection; using namespace System::IO; using namespace MyImage; using namespace std; using namespace System::Runtime::InteropServices; class Wrapper:public IWrapper { private: gcroot&lt;DicomHandler^&gt; _dicomHandler; //gcroot&lt;DicomImageHandler^&gt; _dicomImageHandler; public: Wrapper(){} virtual DLLAPI void SetHandle(HWND handle); virtual DLLAPI void TestDicomImage(DicomImage^ _dicomImage,int winwidth,int winheight); }; </code></pre> <p>In Wrapper.cpp,</p> <pre><code>#include "stdafx.h" #include "Wrapper.h" #include "IWrapper.h" #include &lt;windows.h&gt; #include&lt;iostream&gt; #include &lt;winuser.h&gt; #include &lt;tchar.h&gt; #include&lt;vcclr.h&gt; #include &lt;msclr\marshal_cppstd.h&gt; #include &lt;string&gt; using namespace System::Reflection; using namespace System::Runtime::InteropServices; using namespace System; using namespace System::IO; using namespace std; using namespace DicomImage; void Wrapper::SetHandle(HWND handle) { _dicomHandler=gcnew DicomHandler; //_dicomImageHandler=gcnew DicomImageHandler; _dicomHandler-&gt;SetHandle((System::IntPtr)handle); } IWrapper *IWrapper::CreateInstance() { IWrapper *instance =(IWrapper*)new Wrapper(); return (instance); } void IWrapper::Destroy(IWrapper *instance) { delete instance; } void Wrapper::TestDicomImage(DicomImage^ _dicomImage,int width,int height) { _dicomHandler-&gt;TestImage(_dicomImage,width,height); } </code></pre> <p>then It raises three Errors like</p> <p>1)error C3395: 'Wrapper::TestDicomImage' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention</p> <p>2)error C3395: 'IWrapper::TestDicomImage' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention </p> <p>3)error C2259: 'Wrapper' : cannot instantiate abstract class </p> <p>How to fix these errors?Please provide me the solution for it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload