4

我在 idl 文件中定义了一个接口,并尝试将 vb6 项目转换为 vb.net。

转换从此 idl 的 tlb 创建了互操作,并且在 vs2010 中它抱怨该属性未实现(如下所示)。有谁知道为什么?我什至删除了实现并让 vs2010 重新生成存根,但仍然出错。

idl中的示例界面..

[   uuid(...),
    version(2.0),
    dual,
    nonextensible,
    oleautomation
]
interface IExampleInterface : IDispatch
{
 ...
    [id(3), propget]
    HRESULT CloseDate ([out, retval] DATE* RetVal);
    [id(3), propput]
    HRESULT CloseDate ([in] DATE* InVal);
}

VB.Net 类...

<System.Runtime.InteropServices.ProgId("Project1_NET.ClassExample")>
Public Class ClassExample
    Implements LibName.IExampleInterface

    Public Property CloseDate As Date Implements LibName.IExampleInterface.CloseDate
        Get
            Return mDate
        End Get
        Set(value As Date)
            mDate = value
        End Set
    End Property
4

1 回答 1

2

DATE 参数类型是问题所在。它不是DateTime 或 Date,它是Double。声明在 WTypes.h SDK 头文件中给出,第 1025 行(对于 v7.1):

 typedef double DATE;

因此,通过将其声明为 Double 并根据需要来回转换来修复您的属性:

Public Property CloseDate As Double Implements LibName.IExampleInterface.CloseDate
    Get
        Return mDate.ToOADate
    End Get
    Set(value As Date)
        mDate = DateTime.FromOADate(value)
    End Set
End Property
于 2012-11-20T10:13:18.850 回答