Using C# .dll within C++ .dll

  • Thread starter Thread starter slooper
  • Start date Start date
S

slooper

I am trying to instantiate a Windows Form that I have created in C#.
The problem is that I am instantiating it within a C++ .dll. Here's my
example of what works and what doesn't:


WORKS:

///////////////////////////////////// START CODE
///////////////////////////////

#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System::Windows::Forms;

PLUGINCALLBACK CStatus TestForm_Execute( CRef& in_ctxt )
{
Context ctxt( in_ctxt );
CValueArray args = ctxt.GetAttribute(L"Arguments");

System::Windows::Forms::Form f;
f.ShowDialog();
f.Close();

return CStatus::OK;
}

///////////////////////////////////// END CODE
///////////////////////////////

DOES NOT WORK:

///////////////////////////////////// START CODE
///////////////////////////////
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <C:\Working Folder\tmp\TestCOM\TestCOM\bin\Release\TestCOM.dll>

using namespace System::Windows::Forms;
using namespace TestCOM;

PLUGINCALLBACK CStatus TestForm_Execute( CRef& in_ctxt )
{
Context ctxt( in_ctxt );
CValueArray args = ctxt.GetAttribute(L"Arguments");

TestCOM::TestForm f;
f.ShowDialog();
f.Close();

return CStatus::OK;
}

///////////////////////////////////// END CODE
///////////////////////////////


I am guessing that I am not compiling the C# .dll properly or that
there is an interface missing in the TestCOM.dll that exists in the
System.Windows.Forms.dll. Are there any compiler settings that would
prevent my C# library from being used within C++?


Any suggestions are appreciated. I've been banging my a head on this
for a week now.

Sean
 
You need to have both assemblies (C# and C++/CLI )in the same directory
C:\Working Folder\tmp\TestCOM\TestCOM\bin\Release\TestCOM.dll to begin with,
but it would help if you were a bit more explicit, "It doesn't work" is of
little help, really.

Willy.

|I am trying to instantiate a Windows Form that I have created in C#.
| The problem is that I am instantiating it within a C++ .dll. Here's my
| example of what works and what doesn't:
|
|
| WORKS:
|
| ///////////////////////////////////// START CODE
| ///////////////////////////////
|
| #using <mscorlib.dll>
| #using <System.dll>
| #using <System.Drawing.dll>
| #using <System.Windows.Forms.dll>
|
| using namespace System::Windows::Forms;
|
| PLUGINCALLBACK CStatus TestForm_Execute( CRef& in_ctxt )
| {
| Context ctxt( in_ctxt );
| CValueArray args = ctxt.GetAttribute(L"Arguments");
|
| System::Windows::Forms::Form f;
| f.ShowDialog();
| f.Close();
|
| return CStatus::OK;
| }
|
| ///////////////////////////////////// END CODE
| ///////////////////////////////
|
| DOES NOT WORK:
|
| ///////////////////////////////////// START CODE
| ///////////////////////////////
| #using <mscorlib.dll>
| #using <System.dll>
| #using <System.Drawing.dll>
| #using <System.Windows.Forms.dll>
| #using <C:\Working Folder\tmp\TestCOM\TestCOM\bin\Release\TestCOM.dll>
|
| using namespace System::Windows::Forms;
| using namespace TestCOM;
|
| PLUGINCALLBACK CStatus TestForm_Execute( CRef& in_ctxt )
| {
| Context ctxt( in_ctxt );
| CValueArray args = ctxt.GetAttribute(L"Arguments");
|
| TestCOM::TestForm f;
| f.ShowDialog();
| f.Close();
|
| return CStatus::OK;
| }
|
| ///////////////////////////////////// END CODE
| ///////////////////////////////
|
|
| I am guessing that I am not compiling the C# .dll properly or that
| there is an interface missing in the TestCOM.dll that exists in the
| System.Windows.Forms.dll. Are there any compiler settings that would
| prevent my C# library from being used within C++?
|
|
| Any suggestions are appreciated. I've been banging my a head on this
| for a week now.
|
| Sean
|
 
I apologize for the vagueness. What happens when I use
System::Windows::Forms::Form is that when the method PLUGINCALLBACK is
invoked from my host application, a default form appears. Once the
form is closed, the method returns an OK status. When I use
TestCOM::TestForm instead of or in addition to
System::Windows::Forms::Form, the method PLUGINCALLBACK is called, but
nothing appears to happen and the method does not return a status code.


I'm wondering if perhaps an exception is occurring in the
PLUGINCALLBACK method but it is being handled by the host application
and not being reported.

Does that help to narrow it down a bit?

Sean
 
I've tried #using <TestCOM.dll> with the TestCOM.dll file copied into
the project folder, and the same symptoms occur...

Sean
 
Sorry, you'll have to post a complete sample that illustrates the problem,
we don't have an idea what you are doing here, we don't see any host code,
whatever that may be, nor the C# code.

Willy.

| I've tried #using <TestCOM.dll> with the TestCOM.dll file copied into
| the project folder, and the same symptoms occur...
|
| Sean
|
 
I was hoping that there was an obvious compile option and/or technique
that should be used when compiling C# classes for use within managed
C++. Apparantly it's not so obvious. I'll keep hacking away at it...

Thx

Sean
 
|I was hoping that there was an obvious compile option and/or technique
| that should be used when compiling C# classes for use within managed
| C++. Apparantly it's not so obvious. I'll keep hacking away at it...
|
| Thx
|
| Sean
|

You simply have to compile your C# code as a class library (using /t:library
compiler switch) and you are done


Willy.
 
Back
Top