“参数不正确”通过 COM 组件调用 .NET 程序集时出错
我有一个位于 GAC 中的 .NET 程序集。它已正确注册,以便可以由 COM 组件调用。此 .NET 程序集包含一个方法和该方法的重载:
public void Foo(string sValString, out string sOutString, string sOverloadString)
{
if( sOverloadString == string.Empty )
// do something
else
// do something else
}
public void Foo(string sValString, out string sOutString)
{
Foo(sValString, out sOutString, string.Empty);
}
现在,我可以使用 FoxPro 调用此程序集:
o = CREATEOBJECT("FooNamespace.FooClass")
sValString = "blah"
sOutString = "blahblah"
o.Foo(sValString, @sOutString, "") *OK!
o.Foo(sValString, @sOutString) *Generates error
调用三参数版本工作正常,但当由 COM 组件调用时,两参数版本会出现以下错误:
< code>OLE 错误代码 0x80070057:参数不正确。
有什么想法吗?谢谢你!
I have a .NET assembly that lives in the GAC. It is registered correctly so that it can be invoked by COM components. This .NET assembly contains a method and an overload to the method:
public void Foo(string sValString, out string sOutString, string sOverloadString)
{
if( sOverloadString == string.Empty )
// do something
else
// do something else
}
public void Foo(string sValString, out string sOutString)
{
Foo(sValString, out sOutString, string.Empty);
}
Now, I can use FoxPro to invoke this assembly:
o = CREATEOBJECT("FooNamespace.FooClass")
sValString = "blah"
sOutString = "blahblah"
o.Foo(sValString, @sOutString, "") *OK!
o.Foo(sValString, @sOutString) *Generates error
Invoking the three parameter version works ok, but the two parameter version gives the following error when invoked by the COM component:
OLE error code 0x80070057: The parameter is incorrect.
Any ideas?? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
COM 根本不支持方法重载。当 Regasm.exe 生成类型库时,您的第二个 Foo() 函数将被重命名。如果 Foxpro 无法告诉您使用的名称,您可以使用 Oleview.exe 工具来查看。
最好的办法是完全避免这个问题,只需给重载另一个名称,这样您就不必猜测它。
COM has no support at all for method overloads. Your second Foo() function will be renamed when Regasm.exe generates the type library. You can use the Oleview.exe tool to take a look at it if Foxpro can't tell you what name was used.
Best thing to do is to completely avoid the problem and simply give the overload another name so you don't have to guess at it.
为什么戒得这么快。
这不是 C# 4.0 的功能。
Why quit so fast.
And this is not a C# 4.0 feature.