怎样解决以C开发DLL函式库的语法错误

zhangjin19860305126 2012-08-09 11:53:46
各位大侠,你们好!
我打开C++ Builder 5,在File中选择New,再点击DLL Wizard,我选择Source Type为C,点击OK,以下为出现的东西:
//---------------------------------------------------------------------------

#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;
}
//---------------------------------------------------------------------------
然后我接在后面输入了
Long _declspec (dllexport) _stdcall BCBType_Count(int s,int e)
{
long sum = 0;
for(s;s<=e;s++)
sum+=s;
return sum;
}
保存后,点击了Project中的Build,出现了语法错误:光标指在declspec后面,这是为什么?
...全文
166 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bigfog 2012-08-11
  • 打赏
  • 举报
回复
__declspec(dllexport)
改成
__declspec(dllimport)
  • 打赏
  • 举报
回复
谢谢!
fxworld 2012-08-09
  • 打赏
  • 举报
回复
Long改为 long
  • 打赏
  • 举报
回复
谢谢!
我刚刚在TForm1 *Form1;后面写上了long_declspec(dllexport)_stdcall BCBType_Count(int s,int e);就调试出来了。
但是我还是想用头文件的方式。请大侠们指点。谢谢!
缘中人 2012-08-09
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
各位大侠,问题1解决后,生成了.lib与.dll文件,我把它们拷贝到另外一目录下,并在该目录的工程中执行了Add to Project,将.lib加入进来了。该工程中的程序为:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
int s,e;
s=Edit1->Text.ToInt();
e=Edit2->Text.ToInt();
Edit3->Text=BCBType_Count(s,e);
}
//---------------------------------------------------------------------------
但是Builder后,说BCBType_Count无定义。这主要是没有dll.h(long_declspec(dllexport)_stdcall BCBType_Count(int s,int e);),我该怎么加。我试了好几种方法,都不行。请指点,谢谢!

1,178

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 数据库及相关技术
社区管理员
  • 数据库及相关技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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