关于API获取粘贴板的问题,希望VB或C的高手进来看看,谢谢了

capCreateCaptureWindowA这个API可以获得摄像头的图像。用SendMessageVideoHwnd,WM_CAP_EDIT_COPY,0,0'截图到... capCreateCaptureWindowA这个API可以获得摄像头的图像。
用SendMessage VideoHwnd, WM_CAP_EDIT_COPY, 0, 0 '截图到剪贴板
然后我打开WIN自带的画图,粘贴时,确实粘贴进去了图像,证明粘贴板中存在的是图像。
然而我用代码:
Private Declare Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function AbortDoc Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GetEnhMetaFileBits Lib "gdi32" (ByVal hEMF As Long, ByVal cbBuffer As Long, lpbBuffer As Byte) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Const CF_UNICODETEXT = 13
Private Const CF_DIB = 8
Private Const CF_DIF = 5
-----------
If IsClipboardFormatAvailable(2) = 1 Then
Dim lpData As Long
Dim nSize As Long
Dim hMem As Long
Dim n As Long
OpenClipboard ByVal 0&
hMem = GetClipboardData(2)
lpData = GlobalLock(hMem)
nSize = GlobalSize(lpData)
MsgBox nSize
's = String(nSize, 0)

'n = GetEnhMetaFileBits(hMem, 0, ByVal 0&)
ReDim img_byt(921653)
CopyMemory img_byt(0), ByVal hMem, 921654
GlobalUnlock hMem
CloseClipboard
End If
上面的代码并不能得到粘贴板中关于图片的数据,代码显的有点凌乱,我乱试了一通,不是内存读写错误就是得到一个空数据,请高手指点一下。谢谢了
展开
 我来答
lidh05
2011-06-17 · TA获得超过298个赞
知道小有建树答主
回答量:133
采纳率:0%
帮助的人:120万
展开全部
nSize=GlobalSize(hMem)
...
CopyMemory img_byt(0), ByVal lpData, nSize ''第二个参数应该是数据地址lpData, 而不是句柄hMem,长度也不能随意,超出实际长度就会发生内存读写错误
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式