掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
DLLの呼び出し終了時の初期化 (ID:21423)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
はじめまして、番頭と申します。 DelphiのFormat文をC#で利用する為、 以下のような内容のDLLを作成しました。 ↓ここから uses SysUtils, Classes, Dialogs, Windows; {$R *.RES} function DelphiFormat(var FormatString:PChar; OutStr:PChar; Value:double ):boolean; stdcall; var len:integer; tempLong:longint; tempFormat:String[255]; tempBuf:String[255]; LastChar:String[1]; begin try tempFormat:=FormatString; if Pos('%', tempFormat)>0 then begin LastChar := ANSIUpperCase(Copy(tempFormat,Length(tempFormat),1)); if(LastChar='X') or (LastChar='D') or (LastChar='U') then begin tempLong := Round(Value); tempBuf:=Format(tempFormat,[tempLong]); end else begin tempBuf:=Format(tempFormat,[Value]); end; end else begin tempBuf:=FormatFloat(tempFormat, Value); end; len:=Length(tempBuf); if(OutStr<>nil)and(len>0) then begin StrPCopy(OutStr, tempBuf); end; Result:=true; except On E:Exception do begin Result:=false; end; end; end; exports DelphiFormat; begin end. ↑ここまで C#側で上記DLLを次のように利用しています。 ↓ここから // 宣言部 [DllImport("FormatValue.dll", CharSet = CharSet.Ansi , CallingConvention = CallingConvention.StdCall)] private static extern bool DelphiFormat( ref string FormatString, StringBuilder OutStr, double inputValue ); // 利用部:TextBoxで指定した書式でTextBox2の値を書式変換 string formatString = textBox1.Text; StringBuilder outStr = new StringBuilder(256); double inputValue = double.Parse(textBox2.Text); if (DelphiFormat(ref formatString, outStr, inputValue)) ↑ここまで この条件で、C#のプログラムを繰返して実行すると、 タスクマネージャで見た場合、「ページファイルの使用量」が 時間と共に増加していきます。 同じプログラムで、DLL利用部をコメントアウトすると、 ページファイルの増加はありませんでした。 結果として、DLLの中でメモリリークをしているようなので、 終了時に使用メモリを正しく開放したいのですが、 やり方が良く分かりません。 どなたかご存知でしたら、教えていただきたいのですがm(__)m
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.