我在VB中嵌入了一个OCX控件,该控件用VC编写,对于控件里面的函数直接调用即可,但是对于控件里面的事件,该如何使用呢?控件里面有一个MYOCX_NotifyEvent(ByVal tAgentNotify As 0, ByVal tAgentSummary As 0)事件(MYOCX是控件名称),tAgentNotify 和tAgentSummary 是返回的两个结构,我在该事件下面该怎样得到这两个结构下面各个成员的值呢????????

解决方案 »

  1.   

    MYOCX_NotifyEvent(ByVal tAgentNotify As 0, ByVal tAgentSummary As 0)中是AS 0,你肯定返回的是一个结构?如果是这样,通常可以在已加载OCX控件工程的对象浏览器中找到结构的定义。有了结构的定义一切不都好办了吗?
      

  2.   

    返回的是结构的地址,可以认为是返回了一个结构,我知道该结构的定义,在vc中是用typedef struct定义的,在VB中我可以用Type定义一个同样的结构,问题是该结构中又含有共用体,这个在VB你们怎么定义呢?比如说:typedef struct
    {
        LPCTSTR              strMonitorDesk;
        LPCTSTR              strJoinDesk;
        union
        {
            
            WORD                 wErrorCode;
            BOOL                 bSilent;
            DWORD                dwNoUse;
        } u;
    } AgentNotify_T;
    我在VB里面应该怎么写实现同样功能的结构呢?
      

  3.   

    MY MSN:[email protected] 大家交流一下,谢谢
      

  4.   

    以下是解决方法:
    是的,你必须在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出有数据传入 
      

  5.   

    对你的这个结构在VB里差不多是
    string
    string
    long就可以了,你比刚才那个家伙好,他要模板类型数组,就有点困难,对了,大部分人和我一样上班不能用msn,呵呵:)记得再用我上面写的那个方法即可,记住varptr是long,另外对于它是个保留函数,升级到.net可能费点事最后记得给分~!!  ^_____^!
      

  6.   

    'AgentNotify_T structure define
    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 
      

  7.   

    大家可否留个MSN或者邮箱地址?有空的时候交流与学习一下,谢谢各位了
      

  8.   

    as 0 是什么类型啊? 指针(long)? AgentNotify? (神仙?妖怪? 谢谢^o^)
      

  9.   

    你试试这个,由于MYOCX_NotifyEvent 事件描述的不清楚 所以可能有错误,不行的话发消息给我
    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
      

  10.   

    ByVal tAgentNotify As 0, ByVal tAgentSummary As 0
    是由于这两个参数的结构不确定,所以放在vb里面的时候默认为0。
    这个两个参数在OCX控件里面是返回一个结构的地址,而这个结构很复杂(结构中又包含结构,变量和共用体)所以问题该如何解决呢????
      

  11.   

    baoaya(点头)大哥:
    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,我再弄不出来就交不了差了,谢谢
      

  12.   

    啊? vbscript 不行的 不能使用api
      

  13.   

    baoaya(点头) :
    确实不行,只有改控件的接口了,我那个是要在网页中调用控件的,而且照原来那样提供的接口也就失去了OCX控件的意义,越弄越复杂