How do I properly import functions from a C++ DLL into my C# Project

前端 未结 2 678
情歌与酒
情歌与酒 2021-01-29 06:32

I could use help with how to properly import several functions from a C++ DLL into my C# application. Here are a couple examples from the C++ side that show what I am trying to

2条回答
  •  灰色年华
    2021-01-29 06:45

    It depends what this DLL is besides written in C++.

    If it is a C++ .NET DLL, you can use it like any other .NET DLL. And like the ones you already use provided by the Framework.

    If it was written with .NET's predecessor COM in mind, you can use COM interop. Backwards compatibiltiy was thought about when making .NET

    If it is neither of those, there is P/Invoke.

    Note that COM interop and P/Invoke usually involve handling naked pointers. That means binarity issues and having to go into Unmanaged Code. I do not envy you for having to go that low level language.

提交回复
热议问题