幸亏
Hans Passant
给我指指点点
right direction
。如果使用定义函数
__stdcall
它起作用了。
MathLibrary。h类
#pragma once
#ifdef MATHLIBRARY_EXPORTS
#define MATHLIBRARY_API __declspec(dllexport)
#else
#define MATHLIBRARY_API __declspec(dllimport)
#endif
extern "C" MATHLIBRARY_API int __stdcall add_integers(int a, int b);
extern "C" MATHLIBRARY_API int __stdcall get_integer();
MathLibrary。cpp公司
/* MathLibrary.cpp : Defines the exported functions for the DLL application. */
#include "stdafx.h"
#include "MathLibrary.h"
int __stdcall add_integers(int a, int b)
{
return a + b;
}
int __stdcall get_integer()
{
return 69;
}
函数导出为“\u add”_integers@8“和”\u获取_integer@0“我从VBA中这样称呼他们。
Option Explicit
Declare Function add_integers Lib "..\MathLibrary.dll" Alias "_add_integers@8" (ByVal x As Integer, ByVal y As Integer) As Integer
Declare Function get_integer Lib "..\MathLibrary.dll" Alias "_get_integer@0" () As Integer
Public Function test()
Dim x As Integer
Dim y As Integer
Dim i As Integer
x = 42
y = 27
' this returns 69
i = get_integer()
' this also returns 69
i = add_integers(x, y)
End Function