declspec和stdcall与仅declspec

问题描述

| 我是C ++ dll导入主题的新手,可能是我的问题很简单,但我在Google上找不到它。 我有一个非常简单的C ++ win32 dll:
#include <iostream>

using namespace std;

extern \"C\"
{
    __declspec(dllexport) void __stdcall DisplayHellowFromDLL()
    {
        cout<<\"Hi\"<<endl;
    }
}
当我从C#调用此方法时,我没有任何问题,这是C#代码
namespace UnmanagedTester
{
    class Program
    {
        [DllImport(@\"C:\\CGlobalDll\")]
        public static extern void DisplayHellowFromDLL();

        static void Main(string[] args)
            {
                Console.WriteLine(\"This is C# program\");
                DisplayHellowFromDLL();
            }
        }
    }
如我预期的那样,输出为:\“ This is C#program \” \“ Hi \”。 现在,如果我将C函数的声明更改为:
__declspec(dllexport) void DisplayHellowFromDLL()
没有__stdcall,我也没有任何问题,问题是: 我何时真正需要__declspec(dllexport)TYPE __stdcall?何时只能使用__declspec(dllexport)TYPE? 非常感谢。     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)