emg*_*mge 5 c api private public
我正在开发一个项目,我需要创建一个API.我使用套接字在服务器(我的应用程序)和客户端(使用我的API的其他应用程序)之间进行通信.
这个项目是c而不是C++
我来自linux背景,这是我的第一个使用Windows,Visual Studio 2008和dll库的项目.
我在客户端和服务器之间进行通信,但是我在两个项目上都有一些重复.我想创建一个库(可能是一个dll文件),两个项目都可以链接到,所以我不需要维护额外的代码.
我还必须创建具有我需要为我的客户提供的API的库.在我想要公开的API函数中,调用这些辅助函数是"重复代码",我不想将这些函数暴露给我的客户端,但我确实希望我的服务器能够使用这些函数.我怎样才能做到这一点?
我将尝试用一个例子来澄清.这就是我的开始.
服务器项目:
int Server_GetPacket(SOCKET sd);
int ReceiveAll(SOCKET sd, char *buf, int len);
int VerifyLen(char *buf);
Run Code Online (Sandbox Code Playgroud)
客户项目:
int Client_SendCommand(int command);
int Client_GetData(int command, char *buf, int len);
int ReceiveAll(SOCKET sd, char *buf, int len);
int VerifyLen(char *buf);
Run Code Online (Sandbox Code Playgroud)
这是我想要最终得到的结果:
//Server Project:
int Server_GetPacket(SOCKET sd);
// library with public and private types
// private API (not exposed to my client)
int ReceiveAll(SOCKET sd, char *buf, int len);
int VerifyLen(char *buf);
// public API (header file available for client)
int Client_SendCommand(int command);
int Client_GetData(int command, char *buf, int len);
Run Code Online (Sandbox Code Playgroud)
谢谢任何帮助将不胜感激.
使用
static int ReceiveAll(SOCKET sd, char *buf, int len);
Run Code Online (Sandbox Code Playgroud)
等,使函数本地到文件/编译单元.
如果将“私有”函数放入 DLL 中,并使其可以通过正常方式从外部调用(例如,可以由加载该库的进程调用),那么它们对于其他函数也将是“公共”的。可以混淆名称和类似的东西,但这可能不是一个好的解决方案。
将它们放入静态链接库而不是 DLL 可能会更好。但请注意,即使在这种情况下,也有人可以明显地反汇编二进制文件并获取代码。
| 归档时间: |
|
| 查看次数: |
2026 次 |
| 最近记录: |