如何创建一个dll文件?

rojack 2003-12-08 04:19:27
要求:在选择source type的时候选择c类型(不是c++)

哪位大哥给个简单例子,例如实现这样的功能函数
int test(){
return 2;
}
...全文
21 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
rojack 2003-12-08
  • 打赏
  • 举报
回复
各位,谢谢了,
lanren_me 2003-12-08
  • 打赏
  • 举报
回复
啊,去掉extern "C"就可以编译了
lanren_me 2003-12-08
  • 打赏
  • 举报
回复
//---------------------------------------------------------------------------

#include <windows.h>
//---------------------------------------------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, you do not need to
// explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------------------------------------------

#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
extern "C" __declspec (dllexport) int __stdcall mytest()
{
return 2;
}
//---------------------------------------------------------------------------
rojack 2003-12-08
  • 打赏
  • 举报
回复
extern "C" __EXPORT_TYPE int WINAPI test(void);

大哥,这句在纯c里面过不了的啊,只能在c++里面过
fleamboy 2003-12-08
  • 打赏
  • 举报
回复
在.h中加入:

#ifndef MyDllH
#define MyDllH
#ifdef __BUILDING_THE_DLL
#define __EXPORT_TYPE __export
#else
#define __EXPORT_TYPE __import
#endif

extern "C" __EXPORT_TYPE int WINAPI test(void);

#endif

.CPP文件:

int WINAPI test(void)
{
return 2;
}

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧