掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
DLL上の例外をコピーした文字列をFreeLibraryにアクセスとエラーになる (ID:49506)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
DLL上で例外を発生させ 例外のテキストを文字変数にコピーした後 FreeLibraryの後にコピーした文字変数にアクセスすると エラーが出るのですが バグですかね? var ModuleHandle : HModule; TPExecute: TFarProc; S: String; begin ModuleHandle := LoadLibrary('DUMMY.DLL'); if ModuleHandle <> 0 then begin TPExecute := GetProcAddress(ModuleHandle, 'Execute'); if (TPExecute <> nil) then begin @DLLExecute := TPExecute; try DLLExecute; except on E: Exception do begin S := E.Message; end; end; end; Memo1.Lines.Add(S); FreeLibrary(ModuleHandle); Memo1.Lines.Add(S); //エラーになる end; ---- DUMMY.DLL ----- library DUMMY; uses System.SysUtils, System.Classes, Winapi.Windows; function Execute: Integer;stdcall; var S: String; begin S := 'XXXX'; StrToInt(S); end; exports Execute; begin end. ----- 以下の様にすればエラーは出なくなるのですが ----- var ModuleHandle : HModule; TPExecute: TFarProc; P : array[0..256] of Char; begin ModuleHandle := LoadLibrary('DUMMY.DLL'); if ModuleHandle <> 0 then begin TPExecute := GetProcAddress(ModuleHandle, 'Execute'); if (TPExecute <> nil) then begin @DLLExecute := TPExecute; try DLLExecute; P := 'XXXXXX'; except on E: Exception do begin StrPCopy(P,E.Message); end; end; end; Memo1.Lines.Add(P); FreeLibrary(ModuleHandle); Memo1.Lines.Add(P); end;
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.