现在普通函数可以正常调用,但是回调函数调用不起来.

解决方案 »

  1.   

    在VB.Net下用委托代理能够调用,
    但是在VB6.0下无法正常调用。
    '''''''''''''''''''''''''''''
    'test.bas文件
    option Explicit'声明DLL导出的函数
    Declare Function testCallBack Lib "test.dll" (Byval funAddr AS Long) AS Long'回调方式接收消息
    Public function  funCallBack(Byval retVal AS Integer) AS Integer
    MesgBox Now()
    END function'''''''''''''''''''''''''''''
    'Form1.frm
    option Explicit'启动回调函数
    '运行后出系统错误
    Private Sub Command1_Click()
    Call testCallBack(Address of funCallBack)
    End Sub
      

  2.   

    typedef int (CALLBACK* pFun)testCallBack(int *outPara);
    pFun gCallBack = NULL;extern "C" __declspec(dllexport) void testCallBack(pFun fun);static int i = 0;
    extern "C" __declspec(dllexport) void testCallBack(pFun fun)
    {
    while(TRUE)
    {
    i++;
    int *p = new int[10];
    *p = i;
    gCallBack = fun;
    (*gCallBack)(p);
    free(p);
    p = NULL;
    }
    }
      

  3.   

    VB.Net下可以正常调用, 但是VB6.0下无法调用...
      

  4.   

    http://wenku.baidu.com/view/434d304369eae009581bec43.html
      

  5.   

    '''''' VB.Net调用DLL中接口函数,测试代码Import System.Runtime.InteropServicesPublic Class Form1'声明一个委托代理
    Delegate SUB myDelegate (Byval retVal AS Interger)'声明DLL中接口函数
    <DllImport ("test.dll", CharSet:=CharSet.ansi, CallingConvertinon:=CallingConvertion.Cdecl) > Public Shared Function getSum(Byval a as Integer, Byval b as Integer) AS Integer<DllImport ("test.dll", CharSet:=CharSet.ansi, CallingConvertinon:=CallingConvertion.Cdecl) > Public Shared Function testCallBack(Byval pfun as myDelegate) AS Long'回调方式接收消息
    Public SUB funCallBack(Byval ret AS Integer)
    MsgBox Now()
    print ret
    END SUBPrivate SUB Button1_Click(Byval sender AS System.Object, Byval e AS System.Eventargs) Handles Button1.Click
    Dim retVal AS Integer
    retVal = getSum(5,6)
    Call testCallBack(Address Of funCallBack)END SUBEND Class
      

  6.   

    '定义结构体
    Private Type testStruct
     strKey As String
     strValue As String
    End Type'要查找的字符串
    '<parmas><param name="sid">app_1</param><param name="time">2012</param><param name="SendTime">2020</param></params>Private Sub Command1_Click()Dim strSrc As String
    Dim strTmp As String
    Dim strKey As String
    Dim strValue As String
    Dim strLen As Integer
    Dim iBegin As Integer
    Dim iEnd As IntegerstrSrc = Text1.Text'开始循环找Key Value
    Do While InStr(strSrc, "param name=") > 0iBegin = InStr(1, strSrc, "param name=")
    iEnd = InStr(1, strSrc, "</param>")'取出NameValue组合串
    strTmp = Mid(strSrc, iBegin + 12, iEnd - iBegin - 12)'分别取出Key和Value
    'iBegin = InStr(1, strSrc, "\">")
    iBegin = InStr(1, strTmp, ">")
    strKey = Left(strTmp, iBegin - 2)
    strValue = Right(strTmp, Len(strTmp) - iBegin)Print strKey, strValuestrLen = Len(strSrc)
    strSrc = Right(strSrc, strLen - iEnd)
    LoopMsgBox ("查找结束")End Sub