我有下面的C++代码:调用C++导出的函数在C#
#pragma once
#include "StdAfx.h"
#include <string>
using namespace std;
using namespace System;
extern "C" __declspec(dllexport) string __stdcall GetVale()
{
return "test";
}
我想通过这样来调用C#这样的功能:
[DllImport("Security.dll", CallingConvention = CallingConvention.StdCall, ExactSpelling = true, EntryPoint = "[email protected]")]
internal static extern string Getvalue();
我这样做只是为了学习并真正理解。当我打电话给我时,我收到一个PInvoke异常,说我的CallingConvention不正确。我相信我的文件中的错误非常小。我知道入口点是“_GetVale @ 4”,因为我使用了一个程序来查找它。如果我不能把它改成其他任何东西,它会抛出一个找不到的入口点,所以我的问题是其他地方的问题。
我究竟做错了什么?谢谢!
您不能调用返回C++对象(如std :: string)的C++函数。 C++/CLI包装器是必需的。 – 2012-03-17 07:44:39