我正在从 DLL 调用一个 void 函数,其中参数通过引用传递。 每当我调用它时,函数都会执行,但参数变量不受影响。 谁能告诉我我做错了什么?
#include <iostream>
#include <windows.h>
using namespace std;
class ck
{
public:
unsigned short cm, mb, nm;
};
int main()
{
ck temp;
typedef void(WINAPI *func)(ck);
func ini_v;
HINSTANCE LibDLL = NULL;
LibDLL = LoadLibrary("Ini_vector.dll");
if (LibDLL != NULL)
{
ini_v = (func)GetProcAddress(LibDLL, "ini_vector");
ini_v(temp);
cout << "nm = " << temp.nm << " cm = " << temp.cm<<" bm = "<< temp.mb << endl << endl << "END";
FreeLibrary(LibDLL);
LibDLL = NULL;
}
else
cout << "ERROR." << endl;
cin.get();
return 0;
}
//This is the function included in the DLL
extern "C" __declspec(dllexport)
void ini_vector(ck& C)
{
C.nm = 11;
C.cm = 39;
C.mb = 23;
}