简体   繁体   English

如何在.net项目中使用非托管dll?

[英]How to use unmanaged dll in .net project?

I'm working on an ASP.NET project which generates screen shots. 我正在开发一个生成屏幕截图的ASP.NET项目。 I want to use gdi32.dll in my project. 我想在我的项目中使用gdi32.dll。 How can I import it? 我该如何导入它?

你需要使用P / Invoke

If the dll is a system dll, you have to add programatically like this: 如果dll是系统dll,你必须以这样的方式添加:

[DllImport("gdi32.dll", CharSet = CharSet.Ansi, BestFitMapping = true, ThrowOnUnmappableChar = true)]

And make sure that the project ( Solution Platform ) is set to 32 or x86 and not to Any CPU . 并确保项目( 解决方案平台 )设置为32x86而不是任何CPU You can find more about it with a simple Google search . 您可以通过简单的Google搜索找到更多相关信息。 Happy coding 快乐的编码

You could use a C++/CLI wrapper, depending on your requirements. 您可以使用C ++ / CLI包装器,具体取决于您的要求。 It makes certain things easier. 它使某些事情变得更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM