C# com Objects

  • Thread starter Thread starter Abhishek
  • Start date Start date
A

Abhishek

Hi All,

I am trying to create a C# Com object and call it from unmanaged Cpp. I
have created a call library. I was able to create the interfaces for the
functions and call them from cpp code

//in c#
[Guid("58644AAF-F082-485f-AB33-CC344A5D3522")]
public interface TestDLL_Interface
{

[DispId(1)]
string Testing(string userid);
}

//in cpp

#import "TestDLL.tlb"
using namespace TestDLL;
TestDLL_Interface *t_com_ptr;

//calling the function

CoInitialize(NULL);
TestDLL::TestDLL_InterfacePtr p(_uuidof(TestDLL::Class1));
t_com_ptr = p;
std::string abc = t_com_ptr->Testing("Abhi");

Till this point it is working perfectly and i was able to call the function
without and issue.

Now i need to create an event, and write the event handling code in the cpp
section so that when the event is generated it will fire the code. How do i
do this? Is there any other method of doing this?
Any example would be hugely helpful. Thanks a lot in advance.

Regards
Abhishek
 
Abhishek said:
I am trying to create a C# Com object and call it from unmanaged Cpp. I
have created a call library. I was able to create the interfaces for the
functions and call them from cpp code

(sorry I don't know the answer). But just to check -- is there a
reason not to write a managed cpp file? You can even have a cpp
project that's a hybrid, where most of the cpp files are unmanaged and
just one is managed. This'd make the interop enormously easier.
 
Sorry the code has to be unmanaged. Cause i am trying to call this in an
unmanaged dll.
 
Usually you create the C# assembly as you would normally. Then you use
a program (forget the name at the moment) to generate a wrapper
assembly, which your unmanaged application will call. The wrapper will
handle translating unmanaged calls to managed.

HTH
Andy
 
Thanks Andy,

the Cpp code in the fist post is the wrapper and the c# is the dll. I was
able to get ahead from yesterday's post and now have been able to create the
event in the c# application and just need to create the event handler for
that code in cpp is where i am stuck right now. I was looking at using the
__event to create an event and set it with the c# event so that it is raised
when called.

regards
Abhishek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top