VB或VB.net中如何调用DLL中的结构体参数最近做一下USB视频采集卡开发,DLL中的录像操作比较复杂,其中有结构
VB或VB.net中如何调用DLL中的结构体参数
最近做一下USB视频采集卡开发,DLL中的录像操作比较复杂,其中有结构体一个函数一直没调好,网上这类的贴子挺多,试了好多次也没试好!
VC声明
- C/C++ code
typedef enum{ VIDEO_ENCORE_CBR = 0, VIDEO_ENCORE_VBR = 1,}ENCOREMODE;typedef struct _tagMediaParam{ ENCOREMODE enEncoreMode; double dbFrameRate; DWORD dwVideoWidth; DWORD dwVideoHeight; DWORD dwBitRate; DWORD dwVBRPeakRate; DWORD dwVBRMaxRate; DWORD dwQuantizer; DWORD dwMotionPrecision; DWORD dwKeyFrmInterval;}VIDEO_ENCORE_PARAM,*PVIDEO_ENCORE_PARAM;typedef enum{ RECTYPE_MP4 = 0, RECTYPE_AVI = 1,}RECTYPE;HYUTIL_API UINT WINAPI HYCreateEncoder(UINT unIndex,UINT unRequestFlag,PVIDEO_ENCORE_PARAM pVideoEncoreParam);HYUTIL_API UINT WINAPI HYCreateRecordFile(UINT unIndex,LPCTSTR szFileName,RECTYPE enType);VC中使用
- C/C++ code
UINT unRet = HYCreateEncoder(m_nDevIndex,unFlag,&m_VideoEncore); HYCreateRecordFile(m_nDevIndex,szFile,enType)
我在VB中的声明
- VB code
Type tagMediaParam enEncoreMode As Integer dbFrameRate As Double dwVideoWidth As Long dwVideoHeight As Long dwBitRate As Long dwVBRPeakRate As Long dwVBRMaxRate As Long dwQuantizer As Long dwMotionPrecision As Long dwKeyFrmInterval As Long End Type '开始/停止媒体数据编码 Public Declare Function HYCreateEncoder Lib "HYUtil.DLL" (ByVal unIndex As Integer, ByVal unRequestFlag As Integer, pVideoEncoreParam As tagMediaParam) As Integer Public Declare Function HYCreateRecordFile Lib "HYUtil.DLL" (ByVal unIndex As Integer, ByVal szFileName As String, enType As Integer) As Integer
VB中使用,但一直提示出错: 无效的函数调用参数
- VB code
Dim sFile As StringsFile = "d:\a.avi"Dim pVE As tagMediaParampVE.dwBitRate = 25pVE.dwVideoWidth = 720pVE.dwVideoHeight = 576xx = HYCreateEncoder(0, 0, pVE) '这个函数出错 无效的函数调用参数xx = HYCreateRecordFile(0, sFile, 1)
[解决办法]
在C, C++中UINT 相当于VB中的LONG
你把所有Integer 改成LONG试试
[解决办法]
上面还有个ENCOREMODE 数据类型。定义了木有
[解决办法]
[解决办法]
1.函数声明中把 pVideoEncoreParam As tagMediaParam 这个改成byval pVideoEncoreParam As tagMediaParam 值传递试试
2.不行的话把xx = HYCreateEncoder(0, 0, pVE)
改成xx = HYCreateEncoder(0, 0, varptr(pVE))
或改成xx = HYCreateEncoder(0, 0,byval varptr(pVE))
