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

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

问题描述

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



问题是。我可以编译一个dll中的FastBitmap类,并在VB.NET中使用它吗?




或者是否有一些库可以用来修改VB.NET中的像素数据?



如果类不暴露任何不安全的

/ em>特性在它的公共接口(例如方法接受一个指针),那么你不应该有任何问题使用它从VB.NET。公共语言运行库(CLR)支持不安全的代码,因此C#在编写不安全程序时不会执行任何操作。



,您还可以使用 FastBitmap 类。 runtime.interopservices.marshal.aspxrel =nofollow> Marshal类,它允许使用可以从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天全站免登陆