将long转换为Intptr会给出错误 [英] Convert long to Intptr giving an error

查看:162
本文介绍了将long转换为Intptr会给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在此行中,我尝试将Long转换为Intptr(它抛出类似 long无法转换为Intptr 的错误)

Marshal.Copy(byteArray, tmpBmp.Width * (tmpBmp.Height - 1 - i), DirectCast(CLng(bmpDat1.Scan0) + tmpBmp.Width * i, IntPtr), tmpBmp.Width)<br />



任何人都可以修复它吗?
谢谢

解决方案

  Dim  x  IntPtr 
 Dim  y  As  整数 =  123 
x = 新建  IntPtr (y)



编辑==============

由于您正在调用的方法(Marshal.Copy)采用的是IntPtr,因此您不应将计算结果作为long开头.

 Dim   as 整数= bmpDat1.Scan0 + tmpBmp.Width * i
Marshal.Copy(byteArray,tmpBmp.Width *(tmpBmp.Height- 1 -i), new   IntPtr (),tmpBmp.Width)


Hi,

In this line I am trying to convert Long to Intptr (it is throwing a error like long cannot be converted to Intptr)

Marshal.Copy(byteArray, tmpBmp.Width * (tmpBmp.Height - 1 - i), DirectCast(CLng(bmpDat1.Scan0) + tmpBmp.Width * i, IntPtr), tmpBmp.Width)<br />



Can anyone please fix it?
Thank you

解决方案

Dim x As IntPtr
Dim y As Integer = 123
x = New IntPtr(y)



EDIT ==============

Since the method you''re calling (Marshal.Copy) takes an IntPtr, you shouldn''t be making the calculation result a long to begin with.

Dim value as Integer = bmpDat1.Scan0 + tmpBmp.Width * i
Marshal.Copy(byteArray, tmpBmp.Width * (tmpBmp.Height - 1 - i), new IntPtr(value), tmpBmp.Width)


这篇关于将long转换为Intptr会给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆