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

First-time using Interop

adx
I want to use an interface of a COM object (implemented in C++) using
Interop.

1. Should it be simply just implement an interface on C# side with syntax
like below?

[ComImport]
[Guid("xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
interface ITestInterface
{
[PreserveSig]
int GetTestLevel(out int level);

2. Do all methods in the original interface have to be implemented on C#
side?

3. Should "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx" be the interface GUID or CoClass
ID of the COM object?

4. What do "[ComImport]" and "[PreserveSig]" mean?
Mar 25 '07 #1
1 1353
>1. Should it be simply just implement an interface on C# side with syntax
>like below?

[ComImport]
[Guid("xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
interface ITestInterface
{
[PreserveSig]
int GetTestLevel(out int level);

2. Do all methods in the original interface have to be implemented on C#
side?
You don't have to implement the interface if you're just consuming an
existing class that implements it.

>3. Should "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx" be the interface GUID or CoClass
ID of the COM object?
The IID if you're declaring an interface. The CLSID if you're
declaring a class.

>4. What do "[ComImport]" and "[PreserveSig]" mean?
ComImport means that the type is originally defined in the COM world.
As a result, the type is not exported and registered by Tlbexp/Regasm
for example.

PreserveSig means you're taking responsability to handle the HRESULT
return value from the method. If you remove the attribute (and change
the return type to void) the CLR will do that for you and convert
error HRESULTs to corresponding exceptions.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 25 '07 #2

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

Similar topics

5
by: Mel | last post by:
i want to have a block, like some articles i see, with the first char (very Fancy and huge) and have the rest of the block kind of wrap around this char (to the right of). something like below...
12
by: Alan J. Flavell | last post by:
OK, today's email brought a comment from a reader, pointing out something that I'd long since noticed myself but hadn't done anything about it. On my pages, I've got a first-letter style on...
6
by: Veerle | last post by:
Hi, Somewhere in my html page, I have the following code: <div id="main-body"> <h2>Header text</h2> <p>Some other text ...</p> ..... <h2>Another header text</h2> <p>Some more other text...
5
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test...
43
by: Roger L. Cauvin | last post by:
Say I have some string that begins with an arbitrary sequence of characters and then alternates repeating the letters 'a' and 'b' any number of times, e.g. "xyz123aaabbaabbbbababbbbaaabb" I'm...
5
by: glenn | last post by:
Hi folks, If I want to select the first item in a DropDownList, I need to first select any item other than the first item and then next I select the first item which will then fire an event...
13
by: howa | last post by:
e.g. <div class="main"> <p>ssssss</p> <p>ssssss</p> <p>ssssss</p> <p>ssssss</p>
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
HI I have a stored procedure that returns data with a date field in the form of a DateTime type. I need to place data in variables based on days of the week starting with the first thursday of the...
4
by: Milan Krejci | last post by:
int first=15,latest=15; QString typ=NULL; std::map<int,std::string>::iterator i; for(i = SeznamPracovniDoby.begin(); i != SeznamPracovniDoby.end(); i++) { if (typ==NULL) typ=i->second.c_str(); if...
3
by: dmalhotr2001 | last post by:
Hi, For string extraction function in vb, if I feed in a paragraph, how do I extract the first sentence of that paragraph. Thanks :D
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.