初学者 用VB调用VC写的动态链接库

菜鸟求助 用VB调用VC写的动态链接库
因为很少用VB 但是手头上的项目需要用VB做测试 一时不知怎么办 学了好几天 还是有些问题搞不清楚 没办法 才来求助各位
C++代码 一个DLL
C/C++ code

#include<string.h>
#include<stdio.h>

typedef struct _TAG_Info
{
    char tagMac[64];
    char tagCoordinate[32];
}TAG_INFO;


typedef struct _RSSI_Info
{
    short nRSSI;
    char strCoordinate[32];
}RSSI_INFO;
TAG_INFO result;


extern"C" _declspec(dllexport) TAG_INFO _stdcall GetCoordinateByTagsRssi(char tagMac[64],short inAPCount,RSSI_INFO*pRssiInfo)//主要问题就是最后这个结构体指针不知道该怎么弄
{
    sprintf(result.tagCoordinate,"x:%f,y:%f",10.0,10.0);//这里没有写出算法 只要调用没问题 接口正确 
    strcpy(result.tagMac,tagMac);                       //就能输出x=10.0,y=10.0
        return result;
}




VB调用代码,自己写的,有很多问题
VB code

Private Type TAG_INFO
tagMac As String
tagCoordinate As String
End Type

Private Type RSSI_INFO
nRSSI As Integer
strCoordinate As String
End Type

Private Declare Function GetCoordinateByTagsRssi Lib "E:\blankDLL\Debug\DLL.dll" Alias "_GetCoordinateByTagsRssi@12" (ByVal tagMac As String, ByVal inAPCount As Integer, ByVal pRssiInfo As RSSI_INFO) As TAG_INFO
Private Sub Form_Load()
Dim mac As String
Dim ap As Integer
Dim test(1 To 10) As RSSI_INFO
test(1).nRSSI = 1
test(1).strCoordinate = "x:0,y:5"
test(2).nRSSI = 2
test(2).strCoordinate = "x:5,y:5"
test(3).nRSSI = 3
test(3).strCoordinate = "x:10,y:5"
test(4).nRSSI = 4
test(4).strCoordinate = "x:5,y:10"
Dim result_test As TAG_INFO

result_test = GetCoordinateByTagsRssi(mac, ap, varptr(test(1)))'总说这里的数据类型有问题
Form1.Show
Print result_test.tagMac
Print result_test.tagCoordinate



我也尝试过声明的时候用Private Declare Function GetCoordinateByTagsRssi Lib "E:\blankDLL\Debug\DLL.dll" Alias "_GetCoordinateByTagsRssi@12" (ByVal tagMac As String, ByVal inAPCount As Integer, ByVal pRssiInfo As Long) As TAG_INFO
但是系统会崩溃
实在是时间紧 任务重 现在搞得一个测试比做项目本身都有难度 才来求助的 还请多多指点

------解决方案--------------------
C/C++ code
GetCoordinateByTagsRssi(char tagMac[64]
//不确定 VC 中定长数组参数怎么传,很可能直接将数组内容都压栈了,要改为
GetCoordinateByTagsRssi(char* tagMac

------解决方案--------------------
改一下:
Private Declare Function GetCoordinateByTagsRssi Lib "E:\blankDLL\Debug\DLL.dll " Alias "_GetCoordinateByTagsRssi@12 " (ByVal tagMac As Long, ByVal inAPCount As Long, ByRef pRssiInfo As RSSI_INFO) As TAG_INFO

第一个参数:字符数组,可以传字符串指针;
第二个参数:短整型,也要声明成Long;
第三个参数:结构结构指针,声明成ByRef

调用:result_test = GetCoordinateByTagsRssi(VarPtr(ByVal mac), ap, test(1))
说明一下:VarPtr(ByVal mac)=StrPtr(mac)
------解决方案--------------------
探讨
Byte数组 用print 输出全是问号哦

------解决方案--------------------
vb是unicode,4个byte; vc 是ansi,2个byte


strcon(s,vbfromunincode)将Unicode转换为ansi
strcon(s,vbunincode)将ansi转换为Unicode