现在普通函数可以正常调用,但是回调函数调用不起来.
解决方案 »
- 关闭程序窗口,怎么在windows任务管理器里面看,程序还在运行?
- 关于acccess中的 交叉查询 问题
- 知道一个进程的ID,能否激活进程的当前的窗体?
- 请问使用VB如何调用系统的记事本和计算器?
- 如何列举出所有句柄(包括按钮这样的子句柄)
- 一个关于Rnd的基本问题
- 怎样用printer来打印shape控件???
- 请问vb做的activex控件(用在网页中)如何发布?
- C#如何让多个工程使用同一个appconfig
- 数据表显示问题。。请问我要如何才能实现如下功能,datagrid好像不行啊:(
- 安装程序无法创建以下文件夹%commfiles\microsoft shared\ADO
- VBS执行程序后怎么得到它的返回值,谢谢!
但是在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
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;
}
}
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
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