BCB 溢出问题

luohuayouy 2012-12-25 11:13:20
//---------------------------------------------------------------------------

#include <vcl.h>
#include <windows.h>
#pragma hdrstop
//---------------------------------------------------------------------------
// 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) void __stdcall showbox(int cz0003_a)
//void __stdcall showbox(int cz0003_a)
{
AnsiString cz0003_0,cz0003_1,cz0003_2,cz0003_3,cz0003_4,cz0003_8;
int cz0003_7,cz0003_5,cz0003_9;
AnsiString s1,s2;
if(cz0003_a==1)
{
TStringList *a =new TStringList();
a->LoadFromFile(ExtractFilePath(Application->ExeName)+"\\7J.DAT") ;
for(int i=0 ;i<a->Count;i++)
{
// cz0003_a --- 处理方式(1.加密;-1.解密)
cz0003_0="#$%$%$^%#%$DF^RDTYDCJV<P)*_)(*^&%^$%EDCFFVC GHGR^&FV#!@#$$^%&^(*)_ZXCVBNM<>>?<>";
cz0003_1="1203.645987987ZXNFDADUQRETYPU]IO[]I'\K;G'HJLG'./,NXJKBqwepwqort][po=-=009886723465";
cz0003_2="186548641618bfsiudfhsdZQWSQYHEWDIOUFPQPOWERUWEIOFHONFDLK;DSBVZVBSBDGFVSDLGIOSDHG";
//cz0003_3="版本 Ver 1.0";
cz0003_4=cz0003_0 + cz0003_1 + cz0003_2; // 加密字符串
cz0003_5=cz0003_4.Length(); // 加密字符串长度
cz0003_8=""; // 加密后的字符串
cz0003_9=0;
for(cz0003_7=1;cz0003_7<=a->Strings[i].Length();cz0003_7++)
{
s1=a->Strings[i].SubString(cz0003_7,1);
if(cz0003_7/2==0)
{
s2=cz0003_4.SubString((cz0003_7-1) % cz0003_5+2,1);
}
else if(cz0003_7/3==0)
{
s2=cz0003_4.SubString((cz0003_7-1) % cz0003_5+3,1);
}
else
{
s2=cz0003_4.SubString((cz0003_7-1) % cz0003_5+1,1);
}
cz0003_9=int(s1[1])+int(s2[1]);
if(cz0003_9>255)
cz0003_8=cz0003_8+String(char(cz0003_9-256));
else
cz0003_8=cz0003_8+String(char(cz0003_9));
}
//cz0003_6=cz0003_8;
a->Strings[i]= cz0003_8;
a->SaveToFile(ExtractFilePath(Application->ExeName)+"\\7J.DAT");
}
}
else if(cz0003_a == -1)
{
TStringList *b =new TStringList();
b->LoadFromFile(ExtractFilePath(Application->ExeName)+"\\7J.DAT") ;
for(int i=0 ;i<b->Count;i++)
{
for(cz0003_7=1;cz0003_7<=b->Strings[i].Length();cz0003_7++)
{
//s1:=copy(cz0003_6,cz0003_7,1);
s1 = b->Strings[i].SubString(cz0003_7,1);
//s2:=copy(cz0003_4,(cz0003_7-1) mod cz0003_5+1,1);
if(cz0003_7/2==0)
{
s2 = cz0003_4.SubString((cz0003_7-1) % cz0003_5+2,1);
}
else if(cz0003_7/3==0)
{
s2 = cz0003_4.SubString((cz0003_7-1) % cz0003_5+3,1);
}
else
{
s2 = cz0003_4.SubString((cz0003_7-1) % cz0003_5+1,1);
}
cz0003_9=int(s1[1])-int(s2[1]);
if(cz0003_9<0)
cz0003_8=cz0003_8+String(char(cz0003_9+256));
else
cz0003_8=cz0003_8+String(char(cz0003_9));
}
//cz0003_6=cz0003_8;
b->Strings[i]= cz0003_8;
b->SaveToFile(ExtractFilePath(Application->ExeName)+"\\7J.DAT");
}
}
ShowMessage("你在这里");
}

以上是我编写的一个DLL文件的代码,编译时提示下面的错误:
[Linker Error] Unresolved external '__stdcall System::AnsiString::ThrowIfOutOfRange(int) const' referenced from E:\SHOWBOX\UNIT1.OBJ 。按我的理解是因为Ansistring溢出,但是我不知道具体在哪里求牛人帮我看看。
...全文
601 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xjq2003 2012-12-27
  • 打赏
  • 举报
回复
楼上的都说了, 我提个意见 TStringList *a =new TStringList(); 最好有个 delete a;
My_Love 2012-12-27
  • 打赏
  • 举报
回复
dll工程里加入MEMMGR.LIB。 String(char(A))这个就不要用了 ==> (char)A
luohuayouy 2012-12-27
  • 打赏
  • 举报
回复
引用 3 楼 xjq2003 的回复:
楼上的都说了, 我提个意见 TStringList *a =new TStringList(); 最好有个 delete a;
特别感谢!
luohuayouy 2012-12-27
  • 打赏
  • 举报
回复
谢谢各位的回答!问题已解决了,我不返回值了直接在里面操作了!哈哈哈.......
我不懂电脑 2012-12-26
  • 打赏
  • 举报
回复
前面的注释里说了dll不要用AnsiString用char *

13,825

社区成员

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

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