码迷,mamicode.com
首页 > 编程语言 > 详细

C#NET调用C++X64动态链接库导出函数

时间:2020-03-04 23:01:33      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:string   cli   dll   动态   draw   button   click   成功   export   

 1 // 这是C++定义 DLL 应用程序的导出函数。
 2 //
 3 
 4 #include "stdafx.h"
 5 
 6 char   _Number[255];
 7 
 8 char   _start[255];
 9 
10 char   _finish[255];
11 
12 extern "C" __declspec(dllexport) char*  license_Number()
13 {
14     strcpy_s(_Number, "字符串");
15     return _Number;
16 
17 }
18 
19 extern "C" __declspec(dllexport) char*  license_start()
20 {
21     strcpy_s(_start, "字符串");
22     return _start;
23 
24 }
25 extern "C" __declspec(dllexport) char*  license_finish()
26 {
27     strcpy_s(_finish, "1900172274");
28     return _finish;
29 
30 
31 }

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Runtime.InteropServices;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 using System.Linq;
10 
11 namespace Test
12 {
13     public partial class Form1 : Form
14     {
15         public Form1()
16         {
17             InitializeComponent();
18         }

21 
22         [DllImport("SuperSAN.Plugin.dll", EntryPoint = "GetDefaultMaxStorage")]
23         private static extern IntPtr GetDefaultMaxStorage();
24 
25         [DllImport("SuperSAN.Plugin.dll", EntryPoint = "license_Number")]
26         private static extern IntPtr license_Number();
27 
28         //[DllImport("SuperSAN.Plugin.dll", EntryPoint = "Test")]
29         //private static extern IntPtr Test();
30 
31 
32 
33         private void button1_license_Number_Click(object sender, EventArgs e)
34         {
35             IntPtr intPtr = license_Number();
36             label1.Text = Marshal.PtrToStringAnsi(intPtr);
37             //if (result != "1PB")
38             //{
39 
40             //    System.Environment.Exit(System.Environment.ExitCode);
41             //}
42             MessageBox.Show(" 调用成功!!");
43             return;
44         }
45 
46         private void Form1_Load(object sender, EventArgs e)
47         {
48 
49         }
50     }
51 }

 

 

C#NET调用C++X64动态链接库导出函数

标签:string   cli   dll   动态   draw   button   click   成功   export   

原文地址:https://www.cnblogs.com/wz2988/p/12416474.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!