请教一下,我用C#调用C++的DLL文件时,C++的DLL文件生成没有报错,C#生成时也没有报错(指点了DLL文件的路径),但是我点击启动调试时出现以下错误,还请指点:
补充说明:我添加C#的应用程序时为控制台应用程序(XAML)
具体代码如下:
C#代码:
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
[DllImport(@"C:\Users\ZHL\Desktop\TEST2016.11.14\TestCPPDLL\Debug\TestCPPDLL.dll", EntryPoint = "Add")]
extern static int Add(int a, int b);
static void Main(string[] args)
{
int c = Add(1, 2);
Console.WriteLine(c);
Console.Read();
}
}
}
C++中TestCPPDLL.cpp代码如下
// TestCPPDLL.cpp : 定义 DLL 应用程序的导出函数。
//
#include "stdafx.h"
#include <iostream>
#include "TestCPPDLL.h"
using namespace std;
TESTCPPDLL_API int __stdcall Add(int a, int b)
{
return a + b;
}
C++中TESTCPPDLL.h中代码如下:
#define TESTCPPDLL_API __declspec(dllexport)
EXTERN_C TESTCPPDLL_API int __stdcall Add(int a, int b);