Can I use a C# dll with unsafe code in VB.NET?

痞子三分冷 提交于 2019-12-11 03:21:06

问题


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?


回答1:


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.




回答2:


Fast answer, yes. By the way, did you try it?



来源:https://stackoverflow.com/questions/2307433/can-i-use-a-c-sharp-dll-with-unsafe-code-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!