Assuming that I understand what you are asking (i.e. can you create an
interface definition in .Net which can be used in unmanaged code?), then
just define the interface in a .Net assembly (c#) using the regular
"interface" syntax. E.g.
// in C# .Net managed assembly (schmaboogle.dll):
namespace schmaboogle
{
public interface IFoo
{
string bar
{
[return : MarshalAs(UnmanagedType.BStr)]
get;
}
}
}
Then to use it in your unmanaged code, use an "#import" statement to ...
well... import that definition for use:
// in your, let's say C++, unmanaged code:
#import "schmaboogle.tlb" raw_interfaces_only
using namespace schmaboogle;
// use the interface defined above
typedef CComPtr<IFoo> ptrIfoo;
Bob
> Hi all,
>
[quoted text clipped - 46 lines]
>
> }
Egbert Nierop (MVP for IIS) - 27 May 2006 11:42 GMT
> Assuming that I understand what you are asking (i.e. can you create an
> interface definition in .Net which can be used in unmanaged code?), then
> just define the interface in a .Net assembly (c#) using the regular
> "interface" syntax. E.g.
Hi!
I'm missing some attributes...
> // in C# .Net managed assembly (schmaboogle.dll):
> namespace schmaboogle
> {
[GuidAttribute ("9DD12939-DC08-4f6d-9E64-A3EC6CFE0317"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
TypeLibType(TypeLibTypeFlags.FOleAutomation), ComVisible(true)]
> public interface IFoo
> {
[quoted text clipped - 5 lines]
> }
> }
use RegAsm.exe to create a TLB from your interface...
And the [return : MarshalAs(UnmanagedType.BStr)] is optionally since this
is assumed by default.
> Then to use it in your unmanaged code, use an "#import" statement to ...
> well... import that definition for use:
[quoted text clipped - 59 lines]
>>
>> }
Dule - 30 May 2006 18:21 GMT
Hi Bob,
You got my question right. However, this still doesn't want to work for me
the way I want. Actually, my goal is to have interface declared in my COM
object, everything in managed code.
Imagine situation where I have IAccount interface, and then IUserList under
that IAccount interface. Then I have Account class implementing IAccount,
and Users class implementing IUserList. Now I want to have the Account COM
object, which will return the read-only property IUserList, but my goal is
to have HIDDEN Users class in COM, and still able to marshall IUserList as a
variant to the client.
In addition, I'm having all of this as DCOM. DCOM registration works fine,
but I'm not sure what should be registered on the client side. Basically, if
I setup Users class to be visible, it works fine. However, if I hide it from
COM, my DCOM is lost (DCOM client is working with Variants, with late
binding, if it helps).
Thanks a lot in advance,
Dusko
P.S. Below is the code snipet.
namespace Admin.System
{
//=========================================
// Account part
//IAccount interface
[Guid("B9724F5C-4A75-406d-8176-D852A76203E0")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IAccount
{
[DispId(1)]
IUserList Users
{
get;
}
}
//--------------------------------------------------
[ComVisible(true)]
[Guid("53C74A10-6FFE-49c7-99C5-6E6D05B623C9")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Admin.Account")]
public class Account : IAccount
{
private IUserList users = null;
public IUserList Users
{
get
{
if (users == null)
{
users = new Users();
}
return users;
}
}
}
//==========================================
// Users part
[ComVisible(true)]
[Guid("74FA5E41-E12F-4ce7-ABEB-371ED269F4B5")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]//InterfaceIsIUnknown
// I tried both
[TypeLibType(TypeLibTypeFlags.FOleAutomation)]
public interface IUserList : IList
{
[DispId(1)]
int Add(IUser user);
}
//--------------------------------------------------
// [ComVisible(true)] // I don't want to have visible this class
[Guid("CE3B3FD1-ACD7-4f60-B13F-742CA88BCA4B")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[TypeLibType(TypeLibTypeFlags.FControl)]
// [ProgId("Admin.Account.Passengers")]
public sealed class Users : ArrayList, IUserList
{
public int Add(IUser user)
{
return base.Add(user);
}
}
}
//======== END OF POST
----- Original Message -----
From: "Bob Eaton" <pete_dembrowski@hotmail.com>
Newsgroups: microsoft.public.dotnet.framework.interop
Sent: Friday, May 26, 2006 6:43 PM
Subject: Re: How to create registered COM Interface (not a class) ?
> Assuming that I understand what you are asking (i.e. can you create an
> interface definition in .Net which can be used in unmanaged code?), then
[quoted text clipped - 77 lines]
>>
>> }