VB6 中的代码(一个窗体Form1,四个按钮Botton1-4;一个模块)窗体代码:Option ExplicitPrivate Sub Command1_Click()
   '加载驱动,启动时必须!正常
   TestStart
End SubPrivate Sub Command2_Click()
    '测试驱动, 正常
    TestStatus
End SubPrivate Sub Command3_Click()
    '直接调用DLL函数,正常
    Dim dwVal As Long
    Call ReadPort(&H64, dwVal, 1)
    MsgBox dwVal
End SubPrivate Sub Command4_Click()
    '*********通过模块中的函数调用,程序崩溃!!!!!!!
    MsgBox TestGet(&H64)
End SubPublic Function TestRead(addr As Long) As Long
        Dim dwVal As Long
        Call ReadPort(addr, dwVal, 1)
        TestRead = dwVal
End FunctionPrivate Sub Form_Unload(Cancel As Integer)
    '关闭驱动
    StopIoDriver
End Sub模块中的代码:Option ExplicitPublic Declare Function StartIoDriver Lib "RCSGenIO.dll" () As Long
Public Declare Sub StopIoDriver Lib "RCSGenIO.dll" ()Public Declare Sub TestStatus Lib "RCSGenIO.dll" ()
Public Declare Function ReadPort Lib "RCSGenIO.dll" (ByVal addr As Long, ByRef data As Long, what As Long) As Long
Public Const KBC_KEY_CMD = &H64      '键盘命令端口
Public Const KBC_KEY_DATA = &H60    '键盘数据端口
Public Sub TestStart()
    '正常加载,返回>0的数,否则为-1
    MsgBox StartIoDriver
End Sub
Public Function TestGet(addr As Long) As Long
    '这个函数在窗体中调用,程序就崩溃!!!!
    Dim dwVal As Long
    Call ReadPort(&H64, dwVal, 2)
    TestGet = dwVal
End FunctionVC写的Non-MFC 32位DLL,部分代码:#include "windows.h"
#include "RCSGenIOioctl.h"
#include <conio.h>///////////// ////////////导出函数列表////////////////////////
#define DllExport extern "C"__declspec(dllexport)DllExport long StartIoDriver(void);
DllExport void StopIoDriver(void);//发送键盘码:vkcode : 键盘虚拟键值,exCode扩展键值
DllExport BOOL SendKeyCode(long vkCode, long exCode);DllExport long ReadPort(ULONG addr, PVOID data, long what);
........long ReadPort(ULONG addr, PVOID data, long what)
{
   if (hDriver == INVALID_HANDLE_VALUE)
      return -1;   PortOpenParam  openParam;
   ULONG          handle;
   BOOL           status;
   ULONG          retVal;
   DWORD          control;   // Open the requested port
   openParam.portAddress = addr;
   status = DeviceIoControl(hDriver,
                            RCSGENIO_IOCTL_OPEN_PORT,
                            &openParam,
                            sizeof(PortOpenParam),
                            &handle,
                            sizeof(handle),
                            &retVal,
                            NULL
                           );   if (status == FALSE || handle == 0)
      return -1;   // Read data
   PortReadParam  rdParam;
   ULONG          size;   rdParam.devHandle = handle;   switch (what)
   {
   case 4:
      control = RCSGENIO_IOCTL_READ_DWORD;
      size    = sizeof(DWORD);
      break;
   case 2:
      control = RCSGENIO_IOCTL_READ_WORD;
      size    = sizeof(WORD);
      break;
   case 1:
   default:
      control = RCSGENIO_IOCTL_READ_BYTE;
      size    = sizeof(BYTE);
      break;
   } /* end of switch */   status = DeviceIoControl(hDriver,
                            control,
                            &rdParam,
                            sizeof(PortReadParam),
                            data,
                            size,
                            &retVal,
                            NULL
                           );   // Close the requested port   PortCloseParam    closeParam;   closeParam.devHandle = handle;
   DeviceIoControl(hDriver,
                   RCSGENIO_IOCTL_CLOSE_PORT,
                   &closeParam,
                   sizeof(PortCloseParam),
                   NULL,
                   0,
                   &retVal,
                   NULL
                  );
   return 0;
} // RCSPort::ReadPort()