我正在使用 .NET 2.0 编写一个 C# COM 类来实现IActiveScriptParse32接口。使用 RegAsm.exe 生成 TLB 文件时,不会导出包含 EXCEPINFO 结构的接口方法。为什么 RegAsm.exe 不导出 EXCEPINFO 结构?
接口和类声明:
using System.Runtime.InteropServices;
using ComTypes = System.Runtime.InteropServices.ComTypes;
namespace ScriptEngine
{
[Guid("BB1A2AE2-A4F9-11cf-8F20-00805F2CD064")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IActiveScriptParse32
{
void InitNew();
void AddScriptlet([MarshalAs(UnmanagedType.LPWStr)] string defaultName,
[MarshalAs(UnmanagedType.LPWStr)] string code,
[MarshalAs(UnmanagedType.LPWStr)] string itemName,
[MarshalAs(UnmanagedType.LPWStr)] string subItemName,
[MarshalAs(UnmanagedType.LPWStr)] string eventName,
[MarshalAs(UnmanagedType.LPWStr)] string delimiter,
IntPtr sourceContextCookie,
uint startingLineNumber,
ScriptTextFlags flags,
[MarshalAs(UnmanagedType.BStr)] out string name,
out ComTypes.EXCEPINFO exceptionInfo);
void ParseScriptText([MarshalAs(UnmanagedType.LPWStr)] string code,
[MarshalAs(UnmanagedType.LPWStr)] string itemName,
[MarshalAs(UnmanagedType.IUnknown)] object context,
[MarshalAs(UnmanagedType.LPWStr)] string delimiter,
IntPtr sourceContextCookie,
uint startingLineNumber,
ScriptTextFlags flags,
out object result,
out ComTypes.EXCEPINFO exceptionInfo);
}
[ComVisible(true)]
[Guid("70C3474B-CFE3-4CBB-89F3-E9C70386BCB5")]
public class MyScriptParser : IActiveScriptParse32
{
// Other interface methods
public void ParseScriptText(string code, string itemName, object context, string delimiter, IntPtr sourceContextCookie, uint startingLineNumber, ScriptTextFlags flags, out object result, out ComTypes.EXCEPINFO exceptionInfo)
{
//Code
}
}
}
RegAsm.exe 生成此警告:
类型库导出器警告处理 'ScriptEngine.IActiveScriptParse32. ParseScriptText(异常信息),MyScriptParser'。警告:非 COM 可见值类型“System.Runtime.InteropServices.ComTypes.EXCEPINFO”被当前导出的类型或其基类型之一引用。
并使用此声明生成一个 .tlb 文件:
[
odl,
uuid(BB1A2AE2-A4F9-11CF-8F20-00805F2CD064),
version(1.0),
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "ScriptEngine.IActiveScriptParse32")
]
interface IActiveScriptParse32 : IUnknown {
HRESULT _stdcall InitNew();
};