COM Interop - exposing properties

L

Luke Briner

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
 
J

Jay Douglas

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;
}
}
}
 
L

Luke Briner

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.
 
J

Jay Douglas

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.
 

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

Top