deriving COM class compiles in C#, doesnt in VB.net

J

Jozsef Bekes

Hi All,

I need to derive a class in VB.Net from a COM interface declared in an idl
file in a VC++ project. Here is the interface declaration:
-----------------------------------------------------
[
uuid(FC567B40-956B-11e1-9996-008765B53180),
helpstring(""),
version(1.0),
nonextensible,
dual,
oleautomation,
pointer_default(unique)
]
interface IParameter : IDispatch {

[propget, helpstring("")]
HRESULT _stdcall ID([out, retval] long* );

[id(0), propget, helpstring("") ]
HRESULT _stdcall Value([out, retval] VARIANT*);

[id(0), propput]
HRESULT _stdcall Value([in] VARIANT NewValue);

[id(0), propputref]
HRESULT _stdcall Value([in] VARIANT* NewValue);

};
---------------------------------------------------------
I implemented this in vb.net:

Imports System
Imports CBOM

Namespace shit_in_vb

Public Class wrapper
Implements CBOM.IParameter

Public Sub New()
End Sub

Sub let_Value(ByVal __MIDL_0224 As Object) Implements
IParameter.let_Value
End Sub

Public ReadOnly Property ID() As Integer Implements IParameter.ID
Get
Return 0
End Get
End Property

Public Property Value() As Object Implements IParameter.Value
Get
Return Nothing
End Get

Set(ByVal Value As Object)
End Set
End Property

End Class

End Namespace
---------------------------------------------------------
And it gives the following compile errors:
C:\Projects\MSB-xxx\source\Core\CBOMLib\CBOMLib.NET\Parameter.vb(5) : error
BC30154: 'CBOMLib.Parameter' must implement 'Overridable Overloads Property
Value() As Object' for interface 'CBOM.IParameter'. Implementing property
must have matching 'ReadOnly'/'WriteOnly' specifiers.
C:\Projects\MSB-xxx\source\Core\CBOMLib\CBOMLib.NET\Parameter.vb(105) :
error BC30401: 'IParameter_Value' cannot implement 'Value' because there is
no matching property on interface 'IParameter'.

But I was able to derive from this interface in C# (following code compiles
wo warnings):

---------------------------------------------------------
using System;
using CBOM;
namespace shit_in_see_sharp
{
/// <summary>
/// Summary description for wrapper.
/// </summary>
public class wrapper : CBOM.IParameter
{
public wrapper()
{
//
// TODO: Add constructor logic here
//
}
void IParameter.set_Value(ref object obj)
{
}
void IParameter.let_Value(object obj)
{
}
public int ID
{
get
{
return 0;
}
}
public object Value
{
get
{
return null;
}
set
{
}
}
}
}
---------------------------------------------------------

Can anyone suggest what I am doing wrong in the VB.Net code?

Thank you,
Jozsi
 
H

Herfried K. Wagner [MVP]

Jozsef Bekes said:
I need to derive a class in VB.Net from a COM interface declared in an idl
file in a VC++ project. Here is the interface declaration:

For the case that you don't get an answer here, consider posting your
question to the Interop group (microsoft.public.dotnet.framework.interop).
 

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