我在VB中嵌入了一个OCX控件,该控件用VC编写,对于控件里面的函数直接调用即可,但是对于控件里面的事件,该如何使用呢?控件里面有一个MYOCX_NotifyEvent(ByVal tAgentNotify As 0, ByVal tAgentSummary As 0)事件(MYOCX是控件名称),tAgentNotify 和tAgentSummary 是返回的两个结构,我在该事件下面该怎样得到这两个结构下面各个成员的值呢????????
调试欢乐多
{
LPCTSTR strMonitorDesk;
LPCTSTR strJoinDesk;
union
{
WORD wErrorCode;
BOOL bSilent;
DWORD dwNoUse;
} u;
} AgentNotify_T;
我在VB里面应该怎么写实现同样功能的结构呢?
是的,你必须在VB中建立对应结构这是一点,还有一点,你必须查看从VC里传出的结构中有没有char*的成员,如果有,那么,你还必须修改vc里的那个数据结构改为:
char*temp---->BSTR temp
否则vb无法接受数据然后使用vb的varptr方法,以下是我写的一个这个是vb调用vc的例子,反过来也是:
Public Function Read(ByVal strFileName As String) As Boolean
Dim ptr As Long
On Error Resume Next
ptrDicom = VarPtr(DataStruct)
VCReadFile "E:\Projection\c++6\AAA\" & strFileName, ptr
Read = True
If Err.Number <> 0 Then
Read = False
End If
End Function注意ptr的类型,DataStruct是你在vb的结构,然后将其传入VCReadFile,就可watch出有数据传入
string
string
long就可以了,你比刚才那个家伙好,他要模板类型数组,就有点困难,对了,大部分人和我一样上班不能用msn,呵呵:)记得再用我上面写的那个方法即可,记住varptr是long,另外对于它是个保留函数,升级到.net可能费点事最后记得给分~!! ^_____^!
Private Type AgentNotify_T
strMonitorDesk As String
strJoinDesk As String
wErrorCode As Integer
bSilent As Boolean
dwNoUse As Integer
End Type'API declare
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Dim an As AgentNotify_TCopyMemory an , Byval tAgentNotify , Len(AgentNotify_T)'Msgbox an.strMonitorDesk
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)Private Type union
wErrorCode As Integer
bSilent As Integer
dwNoUse As Long
End TypePrivate Type AgentNotify_T
pstrMonitorDesk As Long
pstrJoinDesk As Long
pu As Long
End Type'你的问题里写的是 AS 0,小弟就假设是 long
Private Sub MYOCX_NotifyEvent(ByVal ptAgentNotify As Long, ByVal ptAgentSummary As Long)
Dim tAgentNotify As AgentNotify_T
Dim tU As union
CopyMemory tAgentNotify, ByVal ptAgentNotify, LenB(tAgentNotify)
CopyMemory tU, ByVal tAgentNotify.pu, LenB(union)
MsgBox GetStr(tAgentNotify.pstrJoinDesk) '根据地址获取字符串里面值
MsgBox GetStr(tAgentNotify.pstrMonitorDesk) '根据地址获取字符串里面值
End SubPrivate Function GetStr(pStr As Long)
Dim strRet As String
CopyMemory ByVal VarPtr(strRet), ByVal pStr, 4
GetStr = strRet
End Function
是由于这两个参数的结构不确定,所以放在vb里面的时候默认为0。
这个两个参数在OCX控件里面是返回一个结构的地址,而这个结构很复杂(结构中又包含结构,变量和共用体)所以问题该如何解决呢????
1.要得到
Private Type union
wErrorCode As Integer
bSilent As Integer
dwNoUse As Long
End Type 里面的变量值
怎么引用呢???是
GetStr(tAgentNotify.pu.wErrorCode)这样写不对吧?pu还没指向union,而且要实现共用体的功能?
2.另外,在vbscript中是否也可以嵌入你上面写的这些语句,因为我做的这些是写在网页里面的?3.typedef struct
{
char strNowCallState[10];
char strAgentState[10];
AgentStatusInfo_T *ptAgentStatusInfo;
} AgentSummaryInfo_T;
请问在这里char 类型和指向一个结构的指针类型在VB里面如何实现?其中AgentStatusInfo_T是一个结构体baoaya大哥可有MSN或者OICQ,我再弄不出来就交不了差了,谢谢
确实不行,只有改控件的接口了,我那个是要在网页中调用控件的,而且照原来那样提供的接口也就失去了OCX控件的意义,越弄越复杂