从 C# 回调 VBScript

发布于 2024-07-26 06:11:15 字数 593 浏览 5 评论 0原文

我想知道是否可以从 C# 调用 VBScript 中的函数。 让我试着澄清一下。 我正在使用一个应用程序(Quick Test Professional 或“QTP”)来自动化另一个应用程序,主要使用 VBScript。 通过加载模型,可以通过将加载项写入作为 .NET 程序集的测试应用程序 (QTP) 来扩展测试功能。 基本工作流程是 VBScript 测试自动化测试应用程序,并且可以调用程序集中的可扩展性添加中的类上的方法来执行更复杂的操作。 这部分工作正常。

我想知道的是我的 C# 代码(在扩展性添加程序集中)是否可以回调 VBScript 中的函数。 我不认为测试应用程序框架(QTP)明确支持这一点,所以我想知道是否有任何方法可以使用标准互操作技术来做到这一点。 我正在考虑使用 GetRef() 来获取对感兴趣的 VBScript 函数的引用,将其作为参数传递给我在可扩展性插件中调用的方法(我怀疑即使在这一点上我也会遇到编组问题?)然后在我的可扩展性添加的 C# 代码中,以某种方式调用该对象的方法; 这是我完全迷失的地方(因为如果没有反射中通常使用的必要类型信息,我不知道如何做到这一点)。

我认为这可能是不可能的,但如果是这样的话,希望得到确认。

谢谢你!

I'd liked to know whether it is possible to call a function in VBScript from C#. Let me try to clarify. I'm using an application (Quick Test Professional or "QTP") that automates another application, mostly using VBScript. There is the ability, via an add in model, to extend the test functionality by writing add-ins to the testing application (QTP) that are .NET assemblies. The basic workflow is that the VBScript tests automate the test application, and can call methods on a class in the extensibility add in assembly to do more complicated things. This part works fine.

What I'd like to know is whether it is possible for my C# code (in the extensibility add in assembly) to call back to a function in the VBScript. I don't think the test application framework (QTP) explicitly supports this, so I'm wondering if there is any way to do this using standard interop techniques. I was half way thinking of using GetRef() to get a reference to the VBScript function of interest, passing this as a parameter to a method I call in the extensibility addin (I suspect I would run into marshaling issues even at this point?) and then within the C# code of my extensibility add in, somehow call a method on this object; this is where I'm completely lost (since I don't know how to do this without the necessary type information normally used in reflection).

I'm thinking this may not be possible, but would like confirmation if that's the case.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ま柒月 2024-08-02 06:11:15

最后并不难,但发现更难
在 vbscript 中设置 a=getref
在 C# 中将 ref 声明为对象
https://community.saas.hpe.com/t5/Unified-Functional-Testing/C-compile-on-the-fly-thru-dotnetfactory/mp/1611299#M22811

private object _UFTCallBackFunction = null;

 public int callMeBack2()
 {
 string[] retParts = {"Yep this is value 1"};
 _UFTCallBackFunction.GetType().InvokeMember("", 
  System.Reflection.BindingFlags.InvokeMethod, null, 
_UFTCallBackFunction, retParts);
 return 0;
 }

 public void InitUFTCallBack(object UFTCallBackFunction)
 {
 _UFTCallBackFunction = UFTCallBackFunction;
 }

然后在vbs中

Set oCallMe = GetRef("CallMeBackWithAParameter")
oTestCom.InitUFTCallBack(oCallMe)
oTestCom.callMeBack2()
Function callMeBackWithAParameter(P1)
 print "I wass called back from C# having value " & P1
End Function

In the end not so hard but finding it out was harder
In vbscript set a=getref
In c# declare the ref as an object
https://community.saas.hpe.com/t5/Unified-Functional-Testing/C-compile-on-the-fly-thru-dotnetfactory/m-p/1611299#M22811

private object _UFTCallBackFunction = null;

 public int callMeBack2()
 {
 string[] retParts = {"Yep this is value 1"};
 _UFTCallBackFunction.GetType().InvokeMember("", 
  System.Reflection.BindingFlags.InvokeMethod, null, 
_UFTCallBackFunction, retParts);
 return 0;
 }

 public void InitUFTCallBack(object UFTCallBackFunction)
 {
 _UFTCallBackFunction = UFTCallBackFunction;
 }

And then in vbs

Set oCallMe = GetRef("CallMeBackWithAParameter")
oTestCom.InitUFTCallBack(oCallMe)
oTestCom.callMeBack2()
Function callMeBackWithAParameter(P1)
 print "I wass called back from C# having value " & P1
End Function
做个少女永远怀春 2024-08-02 06:11:15

VBScript如何调用C#代码? 我怀疑它真的是调用QTP,而QTP调用的是C#代码。 在这种情况下,只有 QTP 才可能回调 VBScript。

你的C#代码在什么情况下会回调? 我怀疑VBScript是否可以异步回调。

How does the VBScript call the C# code? I suspect that it is really calling on QTP, and QTP is calling the C# code. In that case, only QTP could possibly call the VBScript back.

Under what circumstances would your C# code call back? I doubt that VBScript can be called back asynchronously.

坠似风落 2024-08-02 06:11:15

那是个硬汉。

您可能想要尝试在 VBScript 端为 .NET 组件编写一个事件处理程序,并在您希望调用该函数时在 .NET 端引发一个事件。

请注意,它甚至可能不起作用,因为它实际上取决于 QTP 的脚本引擎。 即使应该这样做,如果它变成了一种挫败感的练习,也不要感到惊讶。

请参阅有关 WSH 和事件处理的示例 http://msdn.microsoft.com/en -us/library/ms974564.aspx 同样,这可能不适用于 QTP,但它可以让您了解解决问题的潜在方法。

编辑:附加链接可能有帮助,也可能没有帮助!

http://www.west-wind.com/presentations/dotnetfromVfp/DotNetFromVfp_EventHandling。 ASP

That's a toughie.

You MAY want to try writing an event handler in the VBScript side for the .NET component and raising an event on the .NET side when you want the function to be called.

Just be warned it may not even work, as it really depends on QTP's scripting engine. And even if it should, don't be surprised if it becomes an exercise in frustration.

See examples on WSH and event handling http://msdn.microsoft.com/en-us/library/ms974564.aspx Again, this probably won't apply to QTP, but it's to give you an idea of potential approach to the problem.

Edit: Additional link which may or may not help!

http://www.west-wind.com/presentations/dotnetfromVfp/DotNetFromVfp_EventHandling.asp

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文