从C ++到C#的非托管DLL导入

问题描述:



我正在尝试将C ++ dll(由某些硬件制造商编写)导入到我正在设计的另一个C#dll中.

由于我是这种Dll导入和Visual Studio(C#,C ++)的新手,因此我很难做到这一点.

我尝试添加作为参考,我将dll放置在物理位置(bin),我尝试使用cmd行注册dll,所有这些均失败
后来我尝试通过为方法创建Delagates来使用反射.

它不起作用,

所以现在尝试对c ++ dll函数中的变量(处理程序)执行MArshalAs.

可以请一些主体提供有关如何将c ++ dll导入另一个c#dll的原始源代码.

我看了一般的例子....但还是没有运气....

在此先感谢...

hi

I am trying to import a C++ dll(writen by some hardware manufacturer) into another C# dll that I am designing.

As i am new to this Dll imports and Visual studio (c#, c++) I am having a hard time to do that.

I tried to add as reference, I placed the dll in to physical location(bin), I tried to Register the dll with cmd line, all these failed
Later I tried to use reflections by creating Delagates for the methods.

it did not work,

so now tried to do the MArshalAs for the variables (Handler) that are in the c++ dll functions.

Can some body please provuid source code for how to Import a c++ dll into another c# dll.

I have looked at general examples....but still no luck....

Thanks in advance...

请查看如何在.NET环境中使用非托管代码. ^ ].
Please look how to use unmanaged codes in .NET environment.Unmanaged codes[^] .


正如我所说,这是一个太笼统的问题;因此没有人可以提供样本".究竟是什么样品?

尝试全部学习:
http://en.wikipedia.org/wiki/PInvoke [ http://msdn.microsoft.com/en-us/library/sd10k43k.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. runtime.interopservices.dllimportattribute.aspx [ ^ ]
http://msdn.microsoft.com/zh-cn/library/system.runtime.interopservices.marshalasattribute(v = VS.100).aspx [
—SA
As I say, this is too general question; so nobody can provide a "sample". A sample for what, exactly?

Try to learn it all:
http://en.wikipedia.org/wiki/PInvoke[^],

Start from here:
http://msdn.microsoft.com/en-us/library/sd10k43k.aspx[^],
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx[^]
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshalasattribute(v=VS.100).aspx[^].

After all, provide a signature of the function you want to P/Invoke and what you try to do, just few lines of code. Use "Improve question".

—SA


一个很好的灵感可能是 pinvoke.net [ ^ ]
A good inspiration could be pinvoke.net[^]