Creation of Interface in C# inoder to access some of the function in C# using a vc++ dll
I have created a dll in vc++ and i need this dll to communicate with a C# component can some one 开发者_如何学Pythonhelp me out on how to create the interface in c# so that I can access C# component
I have .net framework 3.5
If your DLL is a .Net library just reference it in your .Net project and your right to go. Porobably needed to build it with Common Lanaguage Standard on though.
If your DLL is a COM library just referece it in your .Net project and it should generate a .Net wrapper for it.
Otherwise you going to have to write an API wrapper for each function you want to invoke. It's been a while since I've done that but there should be some good resources on the web out there on how to.
If I recall you just had to declare the method with the DllImport attribute specifying the dll file name, and then any call to that method will effectively pInvoke it. If the data structures are complex, don't forget that C# supports the reference (&), dereference (*) and arrow pointer (->) operators that C++ does, but you have to delcare the method this is used in as "unsafe". The Marshalling class (I think) also allows you to pin and free up data items so they won't go walk about when being accessed by address.
精彩评论