请教高手:VB dll 调用约定错误!!

ljob2006 2008-02-29 09:34:00
各位高手,我的VB调用DLL,在运行时出现了 dll 调用约定错误! 程序如下,请各位大虾帮忙解决一下!!感恩。。

VB程序:



Option Explicit

'USB User Interface
Public Declare Function Read_USB Lib "DS5000USB_UI.dll" (ByVal mType As Long, ByVal wLength As Long, pBuffer As Any) As Boolean
Public Declare Function Write_USB Lib "DS5000USB_UI.dll" (ByVal cChar As Long) As Boolean

Global Const USB_READ_CMD_REDAY = 0
Global Const USB_READ_CMD_DATA = 1
Global Const ARRAYSIZE = 1024 ' Size of read buffer
Global DSO_IOInitOK As Boolean
Global USB_TimeOutTimer As Long 'USB´«Êä½áÊøʱ¼ä


Sub USB_Init()
' ========================================================================
'
' INITIALIZATION SECTION
'
' ========================================================================

' The application brings the oscilloscope online using ildev. A
' device handle, Dev, is returned and is used in all subsequent
' calls to the device.
Dim retcode As Boolean
Dim ValueStr As String * ARRAYSIZE
Dim buf(255) As Byte
' The application reads the ASCII string from the oscilloscope
' into the ValueStr variable.
retcode = Read_USB(USB_READ_CMD_REDAY, 1, buf(0))

If retcode = False Then
MsgBox "Cann't Connect to USB Device", 48, "USB Init"
DSO_IOInitOK = False
Else
DSO_IOInitOK = True
End If

End Sub
Sub SendToUSB(cmd As String)
Dim retcode As Boolean
Dim buf As String
Dim temp As Long
Dim i As Integer

buf = cmd + Chr$(13)

' The application writes the text in ScopeCommand to the
' oscilloscope.
For i = 1 To Len(cmd) + 1
temp = Asc(buf)
buf = Right(buf, Len(cmd) + 1 - i)
retcode = Write_USB(temp)
If retcode = False Then
MsgBox "Cann't Connect to USB Device", 48, "USB Send Message"
Exit For
End If
Next i

End Sub
Public Function ReadUSB() As String

Dim retcode As Boolean
Dim tmpStr As String
Dim buffer(256) As Byte
Dim i, size As Long
' The application reads the ASCII string from the oscilloscope
' into the ValueStr variable.
USB_TimeOutTimer = 0
buffer(0) = 0
While (buffer(0) = 0 And USB_TimeOutTimer < 20)
retcode = Read_USB(USB_READ_CMD_REDAY, 1, buffer(0))
If retcode = False Then
MsgBox "Can't Connect to USB Device", 48, "USB Read Message"
ReadUSB = ""
Exit Function
End If
DoEvents
Wend
If USB_TimeOutTimer > 19 Then
MsgBox "Read USB time out", 48, "USB Read Message"
tmpStr = ""
Else
size = buffer(0)
retcode = Read_USB(USB_READ_CMD_DATA, size, buffer(0))
If retcode = False Then
MsgBox "Cann't Connect to USB Device", 48, "USB Read Message"
ReadUSB = ""
Exit Function
End If
tmpStr = ""
For i = 0 To size - 1
If (buffer(i) = 10) Then
Exit For
End If
tmpStr = tmpStr + Chr(buffer(i))
Next i
End If
ReadUSB = tmpStr

End Function




DLL函数定义:

(DLL头文件)

// DS5000USB_UI.h : main header file for the DS5000USB_UI DLL
//

#if !defined(AFX_DS5000USB_UI_H__A004624B_F508_4C1D_B0A9_5ABF16885DC8__INCLUDED_)
#define AFX_DS5000USB_UI_H__A004624B_F508_4C1D_B0A9_5ABF16885DC8__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h" // main symbols

#define USB_CTRL_TYPE_LEN 0//¶Á´«ÊäµÄÊý¾ÝµÄ³¤¶È
#define USB_CTRL_TYPE_DATA 1//¶Á´«ÊäµÄÊý¾Ý

extern "C" BOOL EXPORT __stdcall Control_Command_Send(INT devIndex,INT mRequest,INT wValue,INT wIndex,INT wLength);
extern "C" BOOL EXPORT __stdcall Control_Command_Receive(INT devIndex,INT mRequest,INT wValue,INT wIndex,INT wLength,PUCHAR mBuffer);
extern "C" BOOL EXPORT __stdcall Bulk_DataTransfer_Read(INT devIndex,INT wLength,PUCHAR mBuffer);
extern "C" BOOL EXPORT __stdcall Bulk_DataTransfer_Write(INT devIndex,INT wLength,PUCHAR mBuffer);
extern "C" INT EXPORT __stdcall GetDeviceNum();//»ñÈ¡µ±Ç°ÏµÍ³ÖеÄRIGOL ·ÇTMCÉ豸×ÜÊý
/*******************************************************************************

** º¯ÊýÃû³Æ: Read_USB
** ÊäÈë²ÎÊý
** devIndex --- É豸±àºÅ
** type --- ¶ÁÈ¡ÀàÐÍΪÊý¾Ý³¤¶È(USB_CTRL_TYPE_LEN)»òÊý¾ÝÄÚÈÝ(USB_CTRL_TYPE_DATA)
** wLength --- ±¾´Î¶ÁÈ¡µÄ³¤¶È
** mBuffer --- ´æ´¢¶ÁÈ¡Êý¾ÝµÄ¿Õ¼äÖ¸Õë
**
** Êä³ö²ÎÊý:
** ·µ»ØÀàÐÍ --- BOOLÀàÐÍ
**
** Ãè Êö: ¶ÁÈ¡USBÊý¾Ý
********************************************************************************/
extern "C" BOOL EXPORT __stdcall Read_USB(INT devIndex,INT type,INT wLength,PUCHAR mBuffer);
/*******************************************************************************

** º¯ÊýÃû³Æ: Write_USB
** ÊäÈë²ÎÊý
** devIndex --- É豸±àºÅ
** chr --- Ҫͨ¹ýUSB·¢Ë͵ÄÊý¾Ý
**
** Êä³ö²ÎÊý:
** ·µ»ØÀàÐÍ --- BOOLÀàÐÍ
**
** Ãè Êö: ·¢ËÍUSBÊý¾Ý
********************************************************************************/
extern "C" BOOL EXPORT __stdcall Write_USB(INT devIndex,UCHAR chr);

HANDLE OpenDeviceByIndex(INT index);
BOOL CloseDeviceByIndex(INT index);
//BOOL Close_Device_Handle();


#define MAX_BULK_INBUF_SIZE 4096
#define MAX_BULK_OUTBUF_SIZE 4096

#define MAX_CONTROL_INBUF_SIZE 512
#define MAX_CONTROL_OUTBUF_SIZE 512


BOOL CloseIfOpen(VOID);
BOOL Exit(INT res);

extern HANDLE OpenByInterface(
GUID* pClassGuid, // points to the GUID that identifies the interface class
DWORD instance, // specifies which instance of the enumerated devices to open
PDWORD pError // address of variable to receive error status
);

/////////////////////////////////////////////////////////////////////////////
// CDS5000USB_UIApp
// See DS5000USB_UI.cpp for the implementation of this class
//


class CDS5000USB_UIApp : public CWinApp
{
public:
CDS5000USB_UIApp();

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDS5000USB_UIApp)
public:
virtual void OnFinalRelease();
//}}AFX_VIRTUAL

//{{AFX_MSG(CDS5000USB_UIApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};


/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DS5000USB_UI_H__A004624B_F508_4C1D_B0A9_5ABF16885DC8__INCLUDED_)

...全文
270 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
UltraBejing 2008-05-01
  • 打赏
  • 举报
回复
有问题请先GOOGLE,BAIDU
knowledge_Is_Life 2008-04-30
  • 打赏
  • 举报
回复
不知,帮顶
of123 2008-02-29
  • 打赏
  • 举报
回复

extern "C" BOOL EXPORT __stdcall Read_USB(INT devIndex,INT type,INT wLength,PUCHAR mBuffer);

extern "C" BOOL EXPORT __stdcall Write_USB(INT devIndex,UCHAR chr);



Public Declare Function Read_USB Lib "DS5000USB_UI.dll" (Byval devIndex As Long, ByVal mType As Long, ByVal wLength As Long, Byref pBuffer As Byte) As Long

Public Declare Function Write_USB Lib "DS5000USB_UI.dll" (Byval devIndex As Long, Byref cChar As Byte) As Long

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧