サンプル集  >  C#  >  VC++で作成したDLLの使用B
VC++で作成したDLLの使用B
2010/07/15

DLL作成 で作成したDLLを、C# で利用してみます。

◆環境
OS Windows XP Professional Version 2002 Service Pack 3
VC Microsoft Visual C# 2008 91179-136-7480673-60690

プロジェクトを作り、DllImportを書きます。

Program.cs
 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Runtime.InteropServices;

namespace ConsoleApplication3
{
    class VCDLLTest3
    {
        [DllImport("VCDLLTest3.dll")]
        public static extern int myAdd(int a, int b);
        [DllImport("VCDLLTest3.dll")]
        public static extern int mySubtr(int a, int b);
    }

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("1+2="
                             +VCDLLTest3.myAdd(1, 2)
                             );
            Console.WriteLine("3-4="
                             +VCDLLTest3.mySubtr(3, 4)
                             );
        }
    }
}

実行してみます。

1+2=3
3-4=-1
続行するには何かキーを押してください . . .

正しく動作しました。

▲ PageTop  ■ Home


Copyright (C) 2012 ymlib.com