简体   繁体   English

C#COM Object VBA函数或接口标记为受限或该函数使用了不支持的自动化类型

[英]C# COM Object VBA function or interface marked as restricted or the function uses an automation type not supported

I have the following C# COM Object : 我有以下C#COM对象:

[ComVisible(true), GuidAttribute("FD87D0EA-1D00-4189-801A-987D5F8ABD2C")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IRegistration
{
    string RegisterForm(string server, string database, string username, string password, string catalogId, string date, string AxyaContextFile);
    void RegisterFormAcknowledge(string server, string database, string username, string password, long formId, bool isPrinted, string message);
}

When I call the method RegisterFormAcknowledge from Word 200, I get the following compilation exception : function or interface marked as restricted or the function uses an automation type not supported 当我从Word 200调用方法RegisterFormAcknowledge时,出现以下编译异常:函数或接口标记为受限或该函数使用了不支持的自动化类型

Here is the Word macro code 这是Word宏代码

    Set printer = New MyCOMObject.Registration
    printer.RegisterFormAcknowledge "test", "test", "test", "test", 12345, False, "CatalogWordTemplate Not Found"

Does anyone has an idea why ? 有谁知道为什么? Long type are not supported by VB6 ? VB6不支持长型吗? The first method RegisterForm is working well. 第一个方法RegisterForm运行良好。

  [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]

That's a mistake, VB6 and VBA require a dispatch interface. 这是一个错误,VB6和VBA需要一个调度接口。 Boilerplate is to use ComInterfaceType.InterfaceIsAutoDual so that the client code can use both early and late-binding. 样板程序使用ComInterfaceType.InterfaceIsAutoDual,以便客户端代码可以同时使用早期和晚期绑定。 You almost surely need to fix the [ClassInterface] attribute on the class that implements this interface as well, given that you could actually make calls, use ClassInterfaceType.None 鉴于您实际上可以进行调用,几乎肯定需要在实现此接口的类上修复[ClassInterface]属性,请使用ClassInterfaceType.None

Using long as an argument type isn't going to fly, it is not a type supported in VB6. 只要不使用参数类型,VB6就不支持该类型。 VB1 started life as a 16-bit tool so Integer is 16-bits and Long is 32-bits. VB1从16位工具开始,因此Integer是16位,而Long是32位。 No type for 64-bit integrals. 64位积分无类型。 Use int if a VB6 Long was intended. 如果打算使用VB6 Long,则使用int If not then you'll need to consider Double, gets you up to 15 digits, or String. 如果不是,那么您将需要考虑使用Double,最多15个数字或String。

C#'s long is a signed 64-bit integer, which is not automation-compatible . C#的long是带符号的64位整数,不兼容自动化 On the other hand, C#'s int is a signed 32-bit integer, which is automation-compatible. 另一方面,C#的int是带符号的32位整数,与自动化兼容。

You asked about large integers, such as 372036854775807. 您询问了大整数,例如372036854775807。

This one in particular needs 49 bits to represent. 特别是这一位需要49位来表示。 C#'s double is a standard double float , which can represent integers that require up to 53 bits. C#的double是标准的double浮点型 ,可以表示需要最多53位的整数。

There's also C#'s decimal , which maps to eg VBA's Decimal (inside a VARIANT ). 还有C#的decimal ,它映射到VBA的Decimal (在VARIANT )。 If you wish, you can marshal it as eg VBA's Currency , a signed 64-bit integer, with the [MarshalAs(UnmanagedType.Currency)] attribute before the argument definition. 如果需要,可以将其编组为VBA的Currency ,例如带符号的64位整数,并在参数定义之前使用[MarshalAs(UnmanagedType.Currency)]属性。

For larger values, you should probably be better off using a string . 对于较大的值,最好使用string That is, if you can actually deal with them in VBA. 也就是说,如果您可以在VBA中实际处理它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 标记为受限制的函数或接口,或者该函数使用Visual Basic中不支持的自动化类型 - Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic 错误 Function 或接口标记为受限,或者 function 在 VB6 中使用 Visual Basic 中不支持的自动化类型 - Error Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic in VB6 VBScript throw exception when the receiving object is C# COM object and the function has interface as parameter - VBScript throw exception when the receiving object is C# COM object and the function has interface as parameter C#函数返回类型的已实现接口 - C# function to return the implemented interface of a type 接口函数C# - Interface function C# 在C#中加载COM对象抛出异常“无法将类型为'System .__ ComObject'的COM对象转换为接口类型...”,但C ++或VB没有 - Loading COM object in C# throws exception “Unable to cast COM object of type 'System.__ComObject' to interface type …”, but C++ or VB not 具有泛型类型的接口的C#函数返回实例 - C# Function return instance of type Interface with Generic Types 在C#中为Excel Automation创建COM对象时出现COMException - COMException when creating COM object for Excel Automation in C# Excel自动化C#中的“创建列表”功能 - “Create List” function in Excel automation C# C#COM Interop:使用托管对象作为参数公开函数 - C# COM Interop: exposing function with a managed object as parameter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM