473,396 Members | 1,933 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,396 software developers and data experts.

C# com Objects

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
Dec 4 '06 #1
5 1632
"Abhishek" <sh***@activelement.comwrote:
>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.

--
Lucian
Dec 4 '06 #2
Sorry the code has to be unmanaged. Cause i am trying to call this in an
unmanaged dll.

"Lucian Wischik" <lu***@wischik.comwrote in message
news:oj********************************@4ax.com...
"Abhishek" <sh***@activelement.comwrote:
>>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.

--
Lucian

Dec 4 '06 #3
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

Abhishek wrote:
Sorry the code has to be unmanaged. Cause i am trying to call this in an
unmanaged dll.

"Lucian Wischik" <lu***@wischik.comwrote in message
news:oj********************************@4ax.com...
"Abhishek" <sh***@activelement.comwrote:
>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.

--
Lucian
Dec 4 '06 #4
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

"Andy" <an***@med-associates.comwrote in message
news:11**********************@16g2000cwy.googlegro ups.com...
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

Abhishek wrote:
>Sorry the code has to be unmanaged. Cause i am trying to call this in an
unmanaged dll.

"Lucian Wischik" <lu***@wischik.comwrote in message
news:oj********************************@4ax.com.. .
"Abhishek" <sh***@activelement.comwrote:
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.

--
Lucian

Dec 5 '06 #5
Hi Abhishek,

There is something called COM Callable Wrpper... which you can genarate
through utilities that are provided by .net framework.
you do not need to code manually for this wrapper. If you want any
tweaks,, you can always do it..

see http://www.c-sharpcorner.com/article...netfromcom.asp

Thanks
-Srinivas.

Abhishek wrote:
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
Dec 5 '06 #6

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

Similar topics

2
by: dasod | last post by:
I would like to know if my method to remove list objects is correct in this small test program. It seems to me that there might be a simplier way, but I'm afraid I don't know enough about list...
9
by: Aguilar, James | last post by:
Hey guys. A new question: I want to use an STL libarary to hold a bunch of objects I create. Actually, it will hold references to the objects, but that's beside the point, for the most part. ...
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
3
by: ytrewq | last post by:
Should dynamic ("expando") properties be restricted to native and user-defined objects? Or should host objects - such as references to the browser or a plug-in or to the document and its elements -...
8
by: Lüpher Cypher | last post by:
Hi, Suppose we have a hierarchical class structure that looks something like this: Object | +-- Main | +-- Object1
161
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.....
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
21
by: George Exarchakos | last post by:
Hi everyone, I'd like your help... Can we have a std::list<BASEwhere BASE be the base class of a class hierarchy? I want to add to this list objects that are inherited from BASE class but not...
27
by: SasQ | last post by:
Hello. I wonder if literal constants are objects, or they're only "naked" values not contained in any object? I have read that literal constants may not to be allocated by the compiler. If the...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.