我使用TlbImp.exe
. 一个有一个包装器描述为的类
using System;
using System.Runtime.InteropServices;
namespace GNOTDRSIGNATURESERVERLib
{
[CoClass(typeof(GNOTDRSignatureServerClass)),
Guid("20CBF9E0-06BF-11D3-97B5-0080C878CFFA")]
public interface GNOTDRSignatureServer
{
}
}
该对象必须作为参数传递
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace GN8000Lib
{
[TypeLibType(2),
ClassInterface(0),
ComSourceInterfaces("GN8000Lib._I8000Events\0"),
Guid("DCAD84FE-43A8-11D3-B1A2-005004131886")]
public class GN8000Class : I8000
{
[MethodImpl(MethodImplOptions.InternalCall)]
public extern GN8000Class();
[DispId(6)]
[MethodImpl(MethodImplOptions.InternalCall)]
void I8000.Initialize(
[IUnknownConstant] [MarshalAs(UnmanagedType.IUnknown)] [In]
object pSigServer = null);
}
}
然后我这样调用方法:
var gn8000 = new GN8000();
var signatureServer = new GNOTDRSignatureServer();
gn8000.Initialize(signatureServer);
我认为正在传递的对象不是正确的。我觉得TlbImp.exe
可以链接那些 DLL 并使用GNOTDRSignatureServer
而不是UnmanagedType.IUnknown
,或者我可以使用System.Runtime.InteropServices.Marshal.GetComInterfaceForObject
我的代码有什么问题?