飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 2043|回复: 0

C#NET调用C++ DLL的问题求技术解决

[复制链接]
  • TA的每日心情
    开心
    2024-1-24 21:32
  • 签到天数: 41 天

    [LV.5]常住居民I

    发表于 2016-9-21 11:53:48 | 显示全部楼层 |阅读模式
    大概描述一下 就是NET的程序调用一个自定义C+DLL导出函数 不能够成功 老是出错 麻烦大牛们伸出援助之手
    C++dll导出函数定义返回值类型为
    [C++] 纯文本查看 复制代码
    extern "C" __declspec(dllexport) char* _stdcall GetDefaultMaxStorage()
    {
    	
    	return "1PB" ;
    
    }


    C#NET调用


    [C#] 纯文本查看 复制代码
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    namespace 调用DLL
    {
        public partial class Form1 : Form
        {
            [DllImport("SuperSAN.Plugin.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    
            public static extern string GetDefaultMaxStorage();
            public Form1()
            {
                          
                InitializeComponent();
            }
    
    
            private void button1_Click(object sender, EventArgs e)
            {
    
                string result = GetDefaultMaxStorage();
                if (result != "1PB")
                {
    
                    System.Environment.Exit(System.Environment.ExitCode);
    
                }
                MessageBox.Show(" 调用成功!!");
                return;
    
    
            }
        }
    }
    

    PYG19周年生日快乐!
    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

    快速回复 返回顶部 返回列表