我一直在用C++编写DLL,现在我必须从VB6应用程序调用这个DLL.
这是来自此DLL的代码示例:
#include <vector>
#include <string>
using namespace std;
void __stdcall DLLFunction (vector<Object>*)
{
// performs a few operations on the Objects contained in the vector.
}
struct Object
{
long CoordX;
long CoordY;
long Width;
long Height;
LPSTR Id;
};
Run Code Online (Sandbox Code Playgroud)
我还在VB6中定义了"Object struct"
Private Type Object
CoordX As Integer
CoordY As Integer
Width As Integer
Height As Integer
Id As String
End Type
Run Code Online (Sandbox Code Playgroud)
问题是我不知道什么vb6类型可以代表std :: vector以调用DLL的函数.
注意:
- 我使用DLL的向量来添加对象.
- 我使用指针以尽可能少地使用内存.
- 对不起我的英语,这根本不是我的母语.
- 感谢您阅读并试图帮助我.
编辑:
- 我修复了输入问题(Ids肯定是由NullChar结束的,所以LPSTR应该这样做). - 我读了你的答案,我要感谢你们两位,你们的答案彼此接近,一个重大问题依然存在.我的DLL肯定需要向容器添加元素.因此,我想知道如何才能做到这一点.也许我可以为我的函数添加一个返回类型,然后使该函数能够返回它创建的项目(而不是直接将它放入容器中),以便vb6应用程序获取这些项目并能够处理它们,但是我无法弄清楚如何做到这一点 …