在工程项目中,为了不暴露源代码和避免严重耦合,所以将代码封装成 .dll二进制文件,以供项目调用。
这几天,也是在看这些封装dll,并使用Java中的JNA调用c++的dll链接库中的函数,做个笔记!
1、创建dll
新建项目 -> Win32项目 -> 应用程序类型:DLL 附加选项:预编译头、安全开发生命周期检查
2、编写程序
在头文件中添加 mydll.h
#pragma once
#define MYLIBAPI extern "C" __declspec( dllexport )
MYLIBAPI void say(wchar_t* pValue);
struct UserStruct {
long id;
wchar_t* name;
int age;
};
MYLIBAPI void sayUser(UserStruct* pUserStruct);
struct CompanyStruct {
long id;
wchar_t* name;
// UserStruct* users[100];
UserStruct users[100];
int count;
};
struct CompanyStruct2 {
long id;
wchar_t* name;
UserStruct* users[100];
// UserStruct users[100];
int count;
};
MYLIBAPI void sayCompany(CompanyStruct* pCompanyStruct);
MYLIBAPI void sayCompany2(CompanyStruct2