日期:2014-05-17  浏览次数:20999 次

求助,调用C++DLL函数时出现奇怪问题
新建了个窗体程序,功能就是调用农合的接口DLL,执行DLL里边的netPing函数 成功返回0,失败返回1,DLL是C++写的,代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; 

namespace WindowsFormsApplication1
{
    public class XXXX
    {

        [DllImport("XNHInterface.dll", EntryPoint = "netPing", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern int netPing(ref char a);

    } 
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            char b = 'g';
            int s = 0;
            s=XXXX.netPing(ref b);
            label1.Text = s.ToString();
        }
    }
}


在DEBUG模式下按F5,得到了想要的结果,在release模式下F5调试 出现下图的错误:


然后我去DEBUG和release文件夹下边直接执行生成的EXE文件,2个文件夹的EXE文件都会出现下图的错误
c#?DLL?release? C# DLL debug release