从 vbscript (qtp) 传递 win32 dll 中的指针

发布于 2024-11-18 01:18:05 字数 793 浏览 7 评论 0原文

我有一个很好的老式 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 技术交流群。

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

发布评论

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

评论(2

凉宸 2024-11-25 01:18:05

您可以声明像 Win32 API 这样的外部函数,但有一些限制,我相信该函数应该具有 extern "C" 链接,并且并非所有类型都受支持。下面是如何使用 QTP 中的 Win32 GetParent 函数的示例,您也许能够推断出如何匹配您自己的函数。

' Declare
Extern.Declare micHwnd, "GetParent", "user32.dll", "GetParent", micHwnd
' explanation:  retVal     name        sourceDll     name        parameter

' Usage
hwnd = Extern.GetParent(Browser(“xxx”).GetROProperty("hwnd"))

该名称出现两次的原因是您可以为脚本重命名它(我不记得要查找的名称以及您将使用的名称)。

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 Win32 GetParent function from QTP, you may be able to extrapolate how to match your own function.

' Declare
Extern.Declare micHwnd, "GetParent", "user32.dll", "GetParent", micHwnd
' explanation:  retVal     name        sourceDll     name        parameter

' Usage
hwnd = Extern.GetParent(Browser(“xxx”).GetROProperty("hwnd"))

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).

毁梦 2024-11-25 01:18:05

答案是通过引用传递。

在.h文件中声明函数:

extern "C" __declspec(dllexport) int HelloWorld(int &);

在.cpp文件中定义函数:

int HelloWorld(int& i)
{
    i = 10;
    return 55 + i;
}

QTP代码:

Extern.Declare micInteger, "HelloWorld", "C:\test.dll", "HelloWorld", micInteger+micByRef 
myNumber = 5
Extern.HelloWorld(myNumber)
MsgBox(myNumber)

The answer is to pass by reference.

In the .h file declare the function:

extern "C" __declspec(dllexport) int HelloWorld(int &);

In the .cpp file define the function:

int HelloWorld(int& i)
{
    i = 10;
    return 55 + i;
}

QTP code:

Extern.Declare micInteger, "HelloWorld", "C:\test.dll", "HelloWorld", micInteger+micByRef 
myNumber = 5
Extern.HelloWorld(myNumber)
MsgBox(myNumber)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文