1

我使用他们提供的 API 类型库为我们在工作中使用的程序编写插件。它是一个名为 SCAPI 的 COM 对象。COM 对象是为 VB6 编写的,因此当我为 .NET 添加它的引用时,会创建它的互操作版本。

当我使用以下代码时,它应该根据文档返回一个 SAFEARRAY(Long),我收到一条错误消息,说我有一个 SafeArrayTypeMismatchException。

 Dim oBag As SCAPI.PropertyBag = tempModel.PropertyBag
 Dim x = oBag.Value("Created")

该错误是从 SCAPI.PropertyBagClass.get_Value(Object Property) 函数引发的,该函数是 COM 对象的一部分,而不是我写的东西。经过我所做的所有研究,我似乎无法弄清楚我需要做什么才能使其正常工作。我使用 tlbimp.exe 来获取方法信息,但它似乎不包含任何 [out] 标签,即使我使用了相同的函数 oBag.Value("Name"),它返回一个字符串值并且不会抛出错误:

 .method public hidebysig newslot specialname abstract virtual 
         instance object 
         marshal( struct) 
         get_Value([in] object  marshal( struct) Property) runtime managed internalcall
 {
 .custom instance void [mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = ( 01 00 01 00 02 60 00 00 )                         // .....`..
 } // end of method ISCPropertyBag::get_Value
4

0 回答 0