I'm doing com interop from a native client.
The native client uses a native dll to call managed server dll.
All I want is to display a simple form when it load in my native application.
I really appreciate your help/thoughts on this.
Sincerely
Andla
------------------------------------------------------
This is the server
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Server1
{
[Guid("?????????????????")]
public interface IPelle
{
string ShowPelle();
}
[Guid("?????????????????")]
public class PelleClass : IPelle
{
public string ShowPelle()
{
Form1 test = new Form1();
test.Activate();
System.Threading.Thread.Sleep(5000);
return "Pelle 1 was here";
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
This is the client native dll:
IPellePtr pelleptr;
HRESULT hr2 = pelleptr.CreateInstance(__uuidof(PelleClass));
if (SUCCEEDED(hr2))
{
MessageBox(0,pelleptr->ShowPelle(),"",0);
}
Loading
VulpesPosted May 11, 2011, 6:28 AM
andrlagePosted May 12, 2011, 5:04 PM
I'm aware that I can run managed code in c++ so why have I not done that. The simple reason because it is Microsoft. They like to change things so that if I take a project and convert it then I need to do a lot of extra work. Well for small demo projects with a few files it is ok to convert but for the current over 15 year old unmanaged c++ big ass project I will not involve myself in fixing all the missing stuff for the upgrade. The other reason is because I want clean understandable easy to debug code = C# (and it rocks!)
Back to this stuff. I think it is a natural process to make the client support a sink when the server starts the window manage form I want to deal with certain events so I want to use source functions to connect to the sink on the client side.
I think I'm going to implement sink functionality because I think it isn't that hard after I found an awesome article with source code to exactly what I'm looking for.
Here is the link:
http://codeguru.earthweb.com/csharp/csharp/cs_misc/com/print.php/c15199__2/
I think this link should be saved on c-sharpconer because it is what many are looking for.
Cheers
Sam HobbsPosted May 12, 2011, 1:52 PM
I don't understand what you are using an event sink for. You probably have explained that and if so then I forget. I know that old-style C++ COM is confusing. I hope you figure it out.
There is one point I am not sure you understand. It is possible to use managed code in C++. I am not sure that you are doing that. If not then it might make things easier. And then going the other direction, you can use COM objects much easier in C#. It is not clear to me why you are not doing that; I am sorry that I do not understand if you have explained that.
andrlagePosted May 12, 2011, 9:14 AM
That is what I need to run this?
BTW I'm thinking of skipping eventsink and stuff and instead create my own polling routine.
Is that very amateurish or if you look it another way lot of time saving :)
Don't know. For the information I found it involved much extra work to what? Get some
call back to my functions? Still something tells me I must do things right but I question
the purpose of doing this.
Sam HobbsPosted May 11, 2011, 10:14 PM
andrlagePosted May 11, 2011, 7:01 AM
Thanks again.
andrlagePosted May 11, 2011, 6:16 AM
Vulpes the info you provided was helpful but I'm still stuck. Do I have to use the showdialog in the native c++ in modal mode to make it work?
Not sure how I would do that and how to proceed.
Mahesh Chand
The idea is to move away from C++ / MFC. I want to make a bridge between a native application and c#. If I know how to build the bridge then I don't have to fish around with c++ much any more which is a time waster.
Sam HobbsPosted May 11, 2011, 1:14 AM
Is the managed server a COM object? Is there a type library for it? If there is a type library for it then use a "#import" in your C++ program to reduce the details you need to do.
However I am sorry but I don't see a question.
VulpesPosted May 10, 2011, 3:51 PM
Mahesh ChandPosted May 10, 2011, 3:48 PM