我有一个很好的老式win32 dll与表单的功能
void Foo1(int* value) void Foo2(char* string) void Foo3(MyType* data) //ect...我需要在QTP(vbscript)中调用它并检索用于QTP应用程序的数据。 这在vbscript中甚至可能吗?
我对DLL有一些控制权。 它是用c ++编写的。 构建COM服务器不是一种选择。 重构代码以包含具有序数返回类型的访问器方法是不可能的(将是维护和scabaility噩梦)。
编辑以澄清示例......
我有...
void Add(int x, int y, int* result)
......我需要做相当于QTP的QTP ......
int myX = 2; int myY = 5; int myResult = -1; Add(myX, myY, &myResult); //myResult should now be 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.
最满意答案
你可以声明像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"))名称出现两次的原因是您可以为脚本重命名它(我不记得要查找的名称是哪个,以及您将使用的名称)。
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)更多推荐
发布评论