<分区>
我有以下 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 = "_GetVale@4")]
internal static extern string Getvalue();
我这样做只是为了真正地学习和理解。当我调用它时,我得到一个 PInvoke 异常,说我的 CallingConvention 不正确。我确信我的文件中的错误非常小。我知道入口点是“_GetVale@4”,因为我用程序找到了它。如果我无法将其更改为其他任何内容,它会抛出一个未找到的入口点,所以我的问题出在其他地方。
我究竟做错了什么?谢谢!