从 vbscript (qtp) 传递 win32 dll 中的指针
我有一个很好的老式 win32 dll,其函数形式为
void Foo1(int* value)
void Foo2(char* string)
void Foo3(MyType* data)
//ect...
我需要在 QTP (vbscript) 中调用它并检索数据以在 QTP 应用程序中使用。这在 vbscript 中可能吗?
我对 DLL 有一定的控制权。它是用c++编写的。构建 COM 服务器不是一个选项。重构代码以包含具有序数返回类型的访问器方法是完全不可能的(这将是维护和可扩展性的噩梦)。
编辑以澄清示例...
我有...
void Add(int x, int y, int* result)
...我需要执行与此等效的 QTP...
int myX = 2;
int myY = 5;
int myResult = -1;
添加(myX, myY, &myResult);
//myResult 现在应该是 7
...但是在 QTP 中。
在 QTP 中调用 int Bar(int x, int y)
非常简单。
我需要知道是否可以调用 void Foo(int* result)
以这种方式 Foo(&myResult)
并传入对结果的引用。
I have a good old fashioned win32 dll with functions of the form
void Foo1(int* value)
void Foo2(char* string)
void Foo3(MyType* data)
//ect...
I need to call this in QTP (vbscript) and retreive the data for use in the QTP application. Is this even possible in vbscript?
I have some controll over the DLL. It is written in c++. Building a COM server is not an option. Refactoring the code to include accessor methods with ordinal return types is flat out of the question (would be a maintainance and scabaility nightmare).
Editing to clarify the example...
I have...
void Add(int x, int y, int* result)
...I need to do the QTP equivalent of this...
int myX = 2;
int myY = 5;
int myResult = -1;
Add(myX, myY, &myResult);
//myResult should now be 7
...but in QTP.
Calling int Bar(int x, int y)
in QTP is easy.
I need to know if its possible to call into void Foo(int* result)
in this way Foo(&myResult)
and pass in a reference to result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以声明像 Win32 API 这样的外部函数,但有一些限制,我相信该函数应该具有
extern "C"
链接,并且并非所有类型都受支持。下面是如何使用 QTP 中的 Win32GetParent
函数的示例,您也许能够推断出如何匹配您自己的函数。该名称出现两次的原因是您可以为脚本重命名它(我不记得要查找的名称以及您将使用的名称)。
You can declare external functions like Win32 API but there are some limitations, I believe the function should have
extern "C"
linkage and not all types are supported. Here's an example of how to use the Win32GetParent
function from QTP, you may be able to extrapolate how to match your own function.The reason the name appears twice is so you can rename it for your script (I don't remember which is the name to look for and which is the name that you will use).
答案是通过引用传递。
在.h文件中声明函数:
在.cpp文件中定义函数:
QTP代码:
The answer is to pass by reference.
In the .h file declare the function:
In the .cpp file define the function:
QTP code: