首页 新闻 会员 周边 捐助

C#做爱国者h5相机的二次开发,遇到PInvoke错误,求解

0
悬赏园豆:50 [待解决问题]

 用C#做爱国者H5相机的二次开发,由于Demo只有VC、VB的,我想将相机捕捉到的画面,动态同步到picturebox1中,但调试出现如下问题,这个PInvoke是什么错,或者C#有其他实现方法吗?

库文件声明:

[DllImport("gdi32.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]

        private static extern int SetStretchBltMode(

            IntPtr hdc,

            int nStretchMode);

 

        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll", CallingConvention = CallingConvention.Cdecl)]

        private static extern long StretchDIBits(

            HDC  hdc,

            long x,

            long y,

            long dx,

            long dy,

            long SrcX,

            long SrcY,

            long wSrcWidth,

            long wSrcHeight,

            object lpBits,

            BITMAPINFOHEADER lpBitsInfo,

            long wUsage,

            long dwRop);

 

  运行报错:

问题补充:

VB6.0怎么转成VB.net ,需要安装第三方的插件吗?

将指定的CallingConvention和CharSet去掉也不行

这是VB的代码:

Private Declare Function StretchDIBits Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal wSrcWidth As Long, ByVal wSrcHeight As Long, lpBits As Any, lpBitsInfo As BITMAPINFO, ByVal wUsage As Long, ByVal dwRop As Long) As Long
Private Declare Function GetDC& Lib "user32" (ByVal hwnd As Long)
Private Declare Function ReleaseDC& Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long)
Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long

Private Sub Timer1_Timer()
Dim bRet As Boolean
Dim dibret As Long
Dim bmi As BITMAPINFO

bmi.bmiHeader.biSize = 40
bmi.bmiHeader.biWidth = video_w
bmi.bmiHeader.biHeight = video_h
bmi.bmiHeader.biPlanes = 1
bmi.bmiHeader.biBitCount = 24
bmi.bmiHeader.biCompression = 0
bmi.bmiHeader.biSizeImage = 0
bmi.bmiHeader.biXPelsPerMeter = 0
bmi.bmiHeader.biYPelsPerMeter = 0
bmi.bmiHeader.biClrUsed = 0
bmi.bmiHeader.biClrImportant = 0

bRet = KZPreviewOneVideoFrameRGB(Video_RGB(0))

Dim mydc As Long
mydc = GetDC(Picture1.hwnd)
SetStretchBltMode mydc, 4
StretchDIBits mydc, 639, 0, -640, 480, 0, 0, video_w, video_h, Video_RGB(0), bmi, 0, &HCC0020
ReleaseDC Picture1.hwnd, mydc
Sleep 3
End Sub

天水Lv的主页 天水Lv | 初学一级 | 园豆:41
提问于:2014-08-21 09:15
< >
分享
所有回答(3)
0

有VB源代码的话,转换成C#应该不难呀,能贴出VB的相应代码看看吗?

XiaoFaye | 园豆:3087 (老鸟四级) | 2014-08-21 09:28

去这里找相应函数和结构体的C#定义。

 

http://www.pinvoke.net/default.aspx/gdi32.stretchdibits

支持(0) 反对(0) XiaoFaye | 园豆:3087 (老鸟四级) | 2014-08-21 17:36
1

先转VB.NET,然后编译,C#就直接能引用了。

Firen | 园豆:5385 (大侠五级) | 2014-08-21 09:46

非常赞同!

支持(0) 反对(0) XiaoFaye | 园豆:3087 (老鸟四级) | 2014-08-21 09:49
0

将指定的CallingConvention和CharSet去掉试试

jello chen | 园豆:7336 (大侠五级) | 2014-08-21 12:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册