1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

C++で作成したdllをC#で使用する方法

Posted at

仕事でC++で書かれたdllをC#で初めて使用したので、忘却録としてまとめる

開発環境

PC:windows10 pro
IDE:Visual Studio 2010

C#コード(呼び出し側)

hoge.cs
using System.Runtime.InteropServices; ←追加

namespace hogehoge
{
    public class hogeClass
    {
        [DllImport(Library.dll)]
        private static extern IntPtr hoge()
        ・・・・・

    }
}

〇DllImportで、使用したいdllをimport
DllImportを使用する為にSystem.Runtime.InteropServicesを追加する

使用したい関数の修飾子はstatic externにする

型はdll側に合わせて書く
例では、IntPtrとなっている。これはdll側がbyte型のポインタになっているため

※今回はdllから1つの関数しか呼び出していないが、複数呼び出す時は、関数ごとに[DllImport(“hoge.dll”)]を書く必要がある。

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?