小弟做一个摄像头控制程序,需要调用摄像头厂家给的DLL,厂家给的VC.NET函数声明如下:
extern "C"
{ //how to enumerate multi-device, and select one to handle.
//first enumerate devices that are connecting to the PC(call GetVMCUVCDevCount()s).
//if you would like to print the device name string (call GetDevFriendlyNameByIndex())
//second, attach the special device you like.(using AttachUVCDeviceByIndex() function)
//end, detach all device(using  DetachUVCDeviceALL())
DECLDIR ULONG GetVMCUVCDevCount();
DECLDIR ULONG GetDevFriendlyNameByIndex(ULONG iIndex,TCHAR *DevName, ULONG DevNamesize);
DECLDIR BOOL AttachUVCDeviceByIndex(ULONG iIndex);
DECLDIR VOID DetachUVCDeviceALL(); //TRUE for a successful call, FALSE for any error.
//1 for Pressing the Snapshot key, 0 for no operation.
DECLDIR BOOL GetSnapShotStatus(BYTE *SnapShotbStatus);
}
我在VB中声明如下:
Private Declare Function GetSnapShotStatus Lib "UVCXUControl.dll" (ByRef Parm As Long) As Boolean
Private Declare Function GetVMCUVCDevCount Lib "UVCXUControl.dll" () As Long
Private Declare Function AttachUVCDeviceByIndex Lib "UVCXUControl.dll" (ByVal iIndex As Long) As Boolean
Private Declare Sub DetachUVCDeviceALL Lib "UVCXUControl.dll" ()
其中GetVMCUVCDevCount 可用,调用GetSnapShotStatus 时一直提醒实时错误“49”:DLL调用约定错误,
望高人帮忙解决!
谢谢

解决方案 »

  1.   

    Private Declare Function GetSnapShotStatus Lib "UVCXUControl.dll" (ByRef Parm As Long) As Boolean
    改成
    Private Declare Function GetSnapShotStatus Lib "UVCXUControl.dll" (ByVal lpParm As Long) As Boolean
    这里lpParm表示一个指针,即BYTE *SnapShotbStatus,使用varptr获得。
    也可以改成
    Private Declare Function GetSnapShotStatus Lib "UVCXUControl.dll" (ByRef lpBytes As Byte) As Boolean
      

  2.   

    vc的dll中需要把调用模式设为_stdcall才能让vb调用
    比如函数:
    void add  (int a ,int b)
    就无法在VB中调用
    要改为:
    void add _stdcall  (int a ,int b)但我不知道.net有神马变化
      

  3.   

    Private Declare Function AttachUVCDeviceByIndex Lib "UVCXUControl.dll" (ByVal iIndex As Long) As Boolean
    bool  对应改成 long 而不是boolean
    另外
    DECLDIR ULONG GetDevFriendlyNameByIndex(ULONG iIndex,TCHAR *DevName, ULONG DevNamesize);
    DECLDIR ULONG GetVMCUVCDevCount(); ulong 对应参数传递均可声明 x as double, 传进去 varptr(x),vb 中并没有ULONG这个类型,传地址吧,函数返回则应该声明成long