469,889 Members | 1,247 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

COM Interop - exposing properties

My ActiveX Container requires certain properties to be exposed by
components - properties that appear under the properties section in the
IDL/type library file.

C# properties are exposed as methods and the interfaces that my c# class
implements cannot contain fields in order to expose these as properties.

Can anyone tell me how to expose c# code as COM (IDL) properties.

Thanks

Nov 15 '05 #1
4 6623
Look there:

http://msdn.microsoft.com/library/de...tnetserver.asp
José
"Luke Briner" <lu***********@cheerful.com> a écrit dans le message de
news:bj**********@hercules.btinternet.com...
My ActiveX Container requires certain properties to be exposed by
components - properties that appear under the properties section in the
IDL/type library file.

C# properties are exposed as methods and the interfaces that my c# class
implements cannot contain fields in order to expose these as properties.

Can anyone tell me how to expose c# code as COM (IDL) properties.

Thanks

Nov 15 '05 #2
I was just going working through this issue on a different thread in this
news group... This is what I finally came up with:

using System;
using System.Runtime.InteropServices;

namespace Squarei
{
//DEFINE THE PUBLIC INTERFACE FOR THE COM OBJECT
public interface IComInteropTest
{
void SetHTML(string strHtml);
string GetHTML();
}
//IMPLEMENT THE CLASS BELOW USING THE PUBLIC INTERFACE DEFINED ABOVE
[ClassInterface(ClassInterfaceType.None)]
public class ComInteropTest : IComInteropTest
{

public string strUrl = string.Empty;
public string strHtml = string.Empty;

public void SetHTML(string strHtml)
{
this.strHtml = strHtml;
}

public string GetHTML()
{
return strHtml;
}
}
}

--
Jay Douglas
Fort Collins, CO

"Luke Briner" <lu***********@cheerful.com> wrote in message
news:bj**********@hercules.btinternet.com...
My ActiveX Container requires certain properties to be exposed by
components - properties that appear under the properties section in the
IDL/type library file.

C# properties are exposed as methods and the interfaces that my c# class
implements cannot contain fields in order to expose these as properties.

Can anyone tell me how to expose c# code as COM (IDL) properties.

Thanks

Nov 15 '05 #3
Thanks for the help but the MS website does not have any details and
Jay's example still uses methods. I need to expose "idl properties" from
C#. I don't mind how I write the C# code but my container must see the
properties under the "properties" section in the idl file.

Nov 15 '05 #4
Sorry for providing the incorrect information ....

I'm having issues obtaining the same goals as you. Here's the work around I
came up with (I'm not satisfied with my solution, and it still uses methods)

Say I have a property/field

public string FirstName

I then created the methods

public void setFirstName(string s) {
FirstName = s;
}
public string getFirstName() {
return FirstName;
}

Then I exposed the methods in the interface.

I would love to hear a better way to expose the properties.

--
Jay Douglas
Fort Collins, CO

"Luke Briner" <lu***********@cheerful.com> wrote in message
news:bj**********@titan.btinternet.com...
Thanks for the help but the MS website does not have any details and
Jay's example still uses methods. I need to expose "idl properties" from
C#. I don't mind how I write the C# code but my container must see the
properties under the "properties" section in the idl file.

Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by glenn | last post: by
3 posts views Thread by FredC | last post: by
1 post views Thread by Bart Roozendaal | last post: by
1 post views Thread by Adam Clauss | last post: by
reply views Thread by user2008 | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.