Win32.memcpy C#..............? [英] Win32.memcpy c# ..............?

查看:103
本文介绍了Win32.memcpy C#..............?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码

this is the code

int srcStride = bmData.Stride;
int dstStride = bmData.Stride;
int dst = bmData.Scan0.ToInt32() + dstStride * (height - 1);
int src = pBuffer.ToInt32();
for (int y = 0; y < height; y++)
{
    Win32.memcpy(dst, src, srcStride);
    dst -= dstStride;
    src += srcStride;
}



并且在memcpy中给了我这样的错误
我该如何解决?


调用PInvoke函数``dshow!dshow.Core.Win32 :: memcpy''已使堆栈不平衡.这可能是因为托管PInvoke签名与非托管目标签名不匹配.检查PInvoke签名的调用约定和参数是否与目标非托管签名相匹配



and it gives me an error in memcpy that reads this way
how can i fix that please?


A call to PInvoke function ''dshow!dshow.Core.Win32::memcpy'' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature

推荐答案

您似乎需要进一步了解.NET和CLR的作用以及它与本机代码的区别.

这是一个受管理的平台,因此您不能将对象(在此词的最一般意义上,我指的是对象",包括引用对象和值对象,包括原始对象)解释为真实内存中的对象,并且无法通过复制对象来对其进行直接操作在记忆中.您根本无法直接访问内存.

我什至不问您如何P/Invoke memcpy-没关系.基本上,有两种使用位图内存的方法:可以修复内存并访问内存指针(仅在不安全模式下才可以使用),或者可以使用方法System.Runtime.InteropServices.Marshal.CopyIntPtr Scan0一起使用. >
请从MSDN帮助页面中的System.Drawing.Bitmap.LockBits中查看代码示例: http://msdn.microsoft.com /en-us/library/5ey6h79d.aspx [ ^ ].

另请参见 http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.aspx [ ^ ].

有关对数组复制操作使用.NET项目的不安全选项和指针的信息,请参见 http://msdn.microsoft .com/en-us/library/28k1s2k6.aspx [ ^ ].
有关.NET中的不安全和指针的常规信息,另请参见: http://msdn.microsoft.com/zh-我们/library/t2yzs44b.aspx [ ^ ].

—SA
It looks like you need to learn a bit more on what .NET and CLR do and how it''s different from native code.

This is managed platform, so you cannot interpret objects (I mean "object" in the most general sense of this word here, both reference and value objects, including primitive ones) as objects in real memory and perform direct operations with them by copying them in memory. You simply don''t have direct access to memory.

I don''t even ask how you P/Invoke memcpy — it does not matter. Basically, you have two ways to work with bitmap memory: you can fix memory and get access to memory pointers, which is only possible in unsafe mode, or you can use the method System.Runtime.InteropServices.Marshal.Copy to work with IntPtr Scan0.

Please see the code sample from the MSDN help page for System.Drawing.Bitmap.LockBits: http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx[^].

See also http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.aspx[^].

For using unsafe option of the .NET project and pointers for array copy operations, see http://msdn.microsoft.com/en-us/library/28k1s2k6.aspx[^].
See also for unsafe and pointers in .NET in general: http://msdn.microsoft.com/en-us/library/t2yzs44b.aspx[^].

—SA


我认为您需要更正memcpy方法的声明.它应该是IntPtr而不是int. 此处 [
I think you need to correct the declaration for memcpy method. It should be IntPtr and not int. Here[^] an example.


这篇关于Win32.memcpy C#..............?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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