473,387 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using C# .dll within C++ .dll

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

Feb 28 '06 #1
6 8863
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.

"slooper" <se*********@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
|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
|
Feb 28 '06 #2
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

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

Sean

Mar 1 '06 #4
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.

"slooper" <se*********@gmail.com> wrote in message
news:11**********************@t39g2000cwt.googlegr oups.com...
| I've tried #using <TestCOM.dll> with the TestCOM.dll file copied into
| the project folder, and the same symptoms occur...
|
| Sean
|
Mar 1 '06 #5
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

Mar 1 '06 #6

"slooper" <se*********@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
|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.
Mar 1 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kathryn | last post by:
I hope you can help as this is driving me crazy! I have an asp which has 3 frames on it as follows: <FRAMESET rows="50%,*,10%"> <FRAME src="rundetailstop.asp" name="rundetailstop"...
1
by: Jay Sartoris | last post by:
Hi, I'm adding a node to my XML document using DOM. When I serialize it, I lose my comments that are above my root node. I've created an OutputFormat obect and set the setOmitComments(false)...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
11
by: Mark Schneider | last post by:
I'm trying to avoid using <table> for formatting purposes where other, reasonable means exist. I'm stuck trying to find a way to find an equivalent for the code below. <table align="center">...
3
by: Pranav Shah | last post by:
What is the differrence between using the "using" caluse outside of the namespace definition and inside the namespace. Example Outside: using System; namespace Example.Outside { }
2
by: josh | last post by:
Hi, I am trying to validate cXML documents against cXML.dtd using the XmlValidatingReader. If I set the XMLValidatingReader's ValidatingType to ValidationType.DTD, I get the following...
1
by: mailsatk | last post by:
Hello people! I am trying to do something that I don't know if anyone else might have tried before...I am writing a Macro in Excel that will give a user the list of all the folders present within...
7
by: Jim in Arizona | last post by:
I'm brand new at ajax. In fact, about 20 minutes ago was the first time I got it to work. The problem I'm having on another page did not work, however. I'm running into the following error: ...
2
by: Taras_96 | last post by:
Hi everyone, I'm trying to run a number of commands stored within a sql file from within php using mysqli::query. The syntax I'm using is: source C:\data\projects\forum...
15
by: r0g | last post by:
Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.