我可以在VB.NET中使用不安全代码的C#dll吗? [英] Can I use a C# dll with unsafe code in VB.NET?

查看:324
本文介绍了我可以在VB.NET中使用不安全代码的C#dll吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个用于C#的FastBitmap类,它允许您访问和修改位图的像素信息。我已经在一些C#项目中使用它,但现在我需要在VB.NET中。
问题是该类使用不安全的代码,这在VB.NET中不受支持。



问题是。我可以在dll中编译FastBitmap类并在VB.NET中使用它吗?还有一些库可以用来修改VB.NET中的像素数据吗?


$ b class =h2_lin>解决方案

是的,你可以这样做。



如果类没有暴露任何 / em>功能在其公共接口(例如方法采取指针),那么你不应该有任何问题,使用VB.NET。公共语言运行时(CLR)支持不安全的代码,因此当您写入不安全的程序时,C#不会执行任何 magic



,您还可以使用 FastBitmap 类。运行时.interopservices.marshal.aspxrel =nofollow noreferrer>元帅类,它使您可以使用VB.NET可访问的标准.NET接口快速访问内存。但是,在单个项目中混合多种语言的能力是.NET的一大优势。


There is an FastBitmap class for C#, that lets you acces and modify pixel information of am bitmap. I have already used it in some C# project, but I need it now in VB.NET. The problem is that that class uses unsafe code, that is not supported in VB.NET.

The question is. Can I compile the FastBitmap class in a dll and use it in VB.NET?

[EDIT] Or is there some library that can be used to modfy pixel data in VB.NET?

解决方案

Yes, you can do that.

If the class doesn't expose any unsafe features in its public interface (e.g. method taking a pointer) then you shouldn't have any problems using it from VB.NET. The common language runtime (CLR) supports unsafe code, so C# doesn't do any magic when you write unsafe programs.

If you wanted, you could also reimplement the FastBitmap class in VB.NET using the Marshal class, which gives you fast access to memory using a standard .NET interface accessible from VB.NET as well. But the ability to mix multiple languages in a single project is a great advantage of .NET.

这篇关于我可以在VB.NET中使用不安全代码的C#dll吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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