请问下VB调用DLL回调函数执行后出错有关问题
请教下VB调用DLL回调函数执行后出错问题
工作需要,小弟要硬着头皮做一接口开发,对方给出的是DLL接口,带H头文件函数说明,其中需要通过回调函数接收来自DLL的信息,开发环境是VB 2005,写了个简单的控制台应用程序,调用DLL的函数都正常,问题是回调函数执行以后就会弹窗报错“应用程序发生异常 未知的软件异常(0xc0000409),位置为0*********”,然后确认后退出。百思不得其解,回调函数设置能正常返回True,回调函数也能执行一次并将正确信息打印输出,问题是执行了就报错退出,烦请高人帮忙看看原因,多谢指教!
头文件里的相关说明如下:
typedef struct USSN_TIME_STAMP
{
WORD wYear;
WORD wMonth;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} USSNTIMESTAMP, *LPUSSNTIMESTAMP ;
typedef struct USSN_ERROR_MESSAGE
{
DWORD dwMessageType;
DWORD dwNodeAddress;
USSNTIMESTAMP tsTimeStamp;
}USSNERRORMSG, *LPUSSNERRORMSG;
/*! 信息回调函数.*/
typedef DWORD (*ErrorMsgProc)(LPUSSNERRORMSG);
//! 设置回调函数.
/*!
* @return 布尔型(32位整型)变量.
*/
USSNAPI BOOL FAR PASCAL USSNSetErrorMessage(ErrorMsgProc pFunc);
VB 2005里的程序如下:
Public Structure USSN_TIME_STAMP
Public wYear As UInt16
Public wMonth As UInt16
Public wDay As UInt16
Public wHour As UInt16
Public wMinute As UInt16
Public wSecond As UInt16
Public wMilliseconds As UInt16
End Structure
Public Structure USSN_ERROR_MESSAGE
Public dwMessageType As UInt32
Public dwNodeAddress As UInt32
Public tsTimeStamp As USSN_TIME_STAMP
End Structure
Delegate Function ErrorMsgProc(ByRef LPUSSNERRORMSG As USSN_ERROR_MESSAGE) As UInt32
Declare Function USSNSetErrorMessage Lib "C:\USSNPORT.dll" (ByVal pFunc As ErrorMsgProc) As Boolean
Public Function ErrorMsgProc1(ByRef LPUSSNERRORMSG1 As USSN_ERROR_MESSAGE) As UInt32
Console.WriteLine("USSN error msg received.")
Console.WriteLine("USSN error msg: Message Type:" + Str(LPUSSNERRORMSG1.dwMessageType))
Console.WriteLine("USSN error msg: Node Address:" + Str(LPUSSNERRORMSG1.dwNodeAddress))
Console.WriteLine("USSN error msg: Time: Year-" + Str(LPUSSNERRORMSG1.tsTimeStamp.wYear))
ErrorMsgProc1 = 0
End Function
Sub Main()
...
Console.WriteLine("USSN set error msg proc:" + Str(USSNSetErrorMessage(AddressOf ErrorMsgProc1)))
Console.ReadLine()
End Sub
------解决方案--------------------
工作需要,小弟要硬着头皮做一接口开发,对方给出的是DLL接口,带H头文件函数说明,其中需要通过回调函数接收来自DLL的信息,开发环境是VB 2005,写了个简单的控制台应用程序,调用DLL的函数都正常,问题是回调函数执行以后就会弹窗报错“应用程序发生异常 未知的软件异常(0xc0000409),位置为0*********”,然后确认后退出。百思不得其解,回调函数设置能正常返回True,回调函数也能执行一次并将正确信息打印输出,问题是执行了就报错退出,烦请高人帮忙看看原因,多谢指教!
头文件里的相关说明如下:
typedef struct USSN_TIME_STAMP
{
WORD wYear;
WORD wMonth;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} USSNTIMESTAMP, *LPUSSNTIMESTAMP ;
typedef struct USSN_ERROR_MESSAGE
{
DWORD dwMessageType;
DWORD dwNodeAddress;
USSNTIMESTAMP tsTimeStamp;
}USSNERRORMSG, *LPUSSNERRORMSG;
/*! 信息回调函数.*/
typedef DWORD (*ErrorMsgProc)(LPUSSNERRORMSG);
//! 设置回调函数.
/*!
* @return 布尔型(32位整型)变量.
*/
USSNAPI BOOL FAR PASCAL USSNSetErrorMessage(ErrorMsgProc pFunc);
VB 2005里的程序如下:
Public Structure USSN_TIME_STAMP
Public wYear As UInt16
Public wMonth As UInt16
Public wDay As UInt16
Public wHour As UInt16
Public wMinute As UInt16
Public wSecond As UInt16
Public wMilliseconds As UInt16
End Structure
Public Structure USSN_ERROR_MESSAGE
Public dwMessageType As UInt32
Public dwNodeAddress As UInt32
Public tsTimeStamp As USSN_TIME_STAMP
End Structure
Delegate Function ErrorMsgProc(ByRef LPUSSNERRORMSG As USSN_ERROR_MESSAGE) As UInt32
Declare Function USSNSetErrorMessage Lib "C:\USSNPORT.dll" (ByVal pFunc As ErrorMsgProc) As Boolean
Public Function ErrorMsgProc1(ByRef LPUSSNERRORMSG1 As USSN_ERROR_MESSAGE) As UInt32
Console.WriteLine("USSN error msg received.")
Console.WriteLine("USSN error msg: Message Type:" + Str(LPUSSNERRORMSG1.dwMessageType))
Console.WriteLine("USSN error msg: Node Address:" + Str(LPUSSNERRORMSG1.dwNodeAddress))
Console.WriteLine("USSN error msg: Time: Year-" + Str(LPUSSNERRORMSG1.tsTimeStamp.wYear))
ErrorMsgProc1 = 0
End Function
Sub Main()
...
Console.WriteLine("USSN set error msg proc:" + Str(USSNSetErrorMessage(AddressOf ErrorMsgProc1)))
Console.ReadLine()
End Sub
------解决方案--------------------