dll pchar string getmem 内存泄露
时间:2011-08-16
来源:互联网
最近再写 dll 为了通用性(c#可以调用) 输出函数肯定用pchar 作为参数 和 返回值了 这是毫无疑问的
查阅了些资料
http://blog.sina.com.cn/s/blog_4ff1251f0100dsu6.html
并且在其他地方下到一些代码
Delphi(Pascal) code
Delphi(Pascal) code
都用到了 内存分配函数 可没有释放 势必会造成内存泄露吧(CheckMem.pas检查有)
请问 dll 涉及输出函数中 string 标准写法 如何?
查阅了些资料
http://blog.sina.com.cn/s/blog_4ff1251f0100dsu6.html
并且在其他地方下到一些代码
Delphi(Pascal) code
function StrPch(const stPas: string): PChar; // Pascal -> PChar // 直接使用 PChar 转化有时会转化出错 begin GetMem(Result, Length(stPas) + 1); StrPCopy(Result, stPas); end; function GetSpellCode(szText: PChar; iMode, iCount: Integer): PChar; // Call MakeSpellCode begin Result := StrPch(MakeSpellCode(String(szText), iMode, iCount)); //这里直接用pchar 有时会报错? 搞不懂 end;
Delphi(Pascal) code
function GetAdminPath: ShortString; stdcall; var vPath: pchar vSize: Integer; begin vSize := MAX_PATH; vPath := GetMemory(vSize); ExpandEnvironmentStrings('%HOMEDRIVE%%HOMEPATH%', vPath, MAX_PATH); //ShowMessage(StrPas(vPath)); Result := StrPas(vPath); end;
都用到了 内存分配函数 可没有释放 势必会造成内存泄露吧(CheckMem.pas检查有)
请问 dll 涉及输出函数中 string 标准写法 如何?
作者: chinawcs 发布时间: 2011-08-16
问题1 : 再dll中分配内存还是exe中
问题2 : 再dll中分配内存会自动释放吗
问题3 :dll 返回 pchar 会有不稳定的情况 ?
问题2 : 再dll中分配内存会自动释放吗
问题3 :dll 返回 pchar 会有不稳定的情况 ?
作者: chinawcs 发布时间: 2011-08-16
我在DLL中这样用还没出现过问题
Delphi(Pascal) code
Delphi(Pascal) code
//********取得当前可执行文件名 procedure GetApplicationName(var Lp:String);StdCall; begin StrCopy(PChar(Lp),PChar(ChangeFileExt(ExtractFileName(Application.ExeName),''))); end;
作者: hongss 发布时间: 2011-08-16
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28