私は、Delphi で DLL を作成することに初めて取り組みました。ここまでは順調ですね。typelib を使用することで、Widestrings を DLL との間で問題なく受け渡すことができました。
現時点で興味深いのは、VB6 をテストベッドとして使用していて、IDE 内でテストを実行するたびに、プログラムが実行され、IDE プロセスが突然メモリから消えてしまうことです。エラー メッセージも何も表示されません。コードをステップ実行すると、最後の行を実行するまですべてが正常に機能し、その後 IDE が消えます。
対照的に、テストを EXE にコンパイルすると、プログラムは最後まで実行され、エラー メッセージなどは表示されません。
誰かが以前にこの問題を抱えていましたか?私を見つめている明らかな解決策はありますか?
重要な場合に備えて、以下のソースコード:
- 事業
library BOSLAD;
uses
ShareMem,
SysUtils,
Classes,
BOSLADCode in 'BOSLADCode.pas';
exports
version,
DMesg,
foo;
{$R *.res}
begin
end.
- 単位
unit BOSLADCode;
interface
function version() : Double; stdcall;
procedure DMesg(sText : WideString; sHead : WideString ); stdcall;
function foo() : PWideString; stdcall;
implementation
uses Windows;
function version() : Double;
var
s : String;
begin
result := 0.001;
end;
procedure DMesg( sText : WideString; sHead : WideString);
begin
Windows.MessageBoxW(0, PWideChar(sText), PWideChar(sHead), 0);
end;
function foo() : PWideString;
var s : WideString;
begin
s := 'My dog''s got fleas';
result := PWideString(s);
end;
end.
-- タイプライブラリ
// This is the type library for BOSLAD.dll
[
// Use GUIDGEN.EXE to create the UUID that uniquely identifies
// this library on the user's system. NOTE: This must be done!!
uuid(0C55D7DA-0840-40c0-B77C-DC72BE9D109E),
// This helpstring defines how the library will appear in the
// References dialog of VB.
helpstring("BOSLAD TypeLib"),
// Assume standard English locale.
lcid(0x0409),
// Assign a version number to keep track of changes.
version(1.0)
]
library BOSLAD
{
// Now define the module that will "declare" your C functions.
[
helpstring("Functions in BOSLAD.DLL"),
version(1.0),
// Give the name of your DLL here.
dllname("BOSLAD.dll")
]
module BOSLADFunctions
{
[helpstring("version"), entry("version")] void __stdcall version( [out,retval] double* res );
[helpstring("DMesg"), entry("DMesg")] void __stdcall DMesg( [in] BSTR msg, [in] BSTR head );
[helpstring("foo"), entry("foo")] void __stdcall foo( [out,retval] BSTR* msg );
} // End of Module
}; // End of Library
WideString の宣言を、それを宣言した関数の外側に移動しました。これにより、変数の有効期間が関数の有効期間よりも長くなることが期待されfoo
ます。それは何の違いもありませんでした。
foo
同様に、関数の呼び出しを VB6 からコメントアウトしました。それも違いはありませんでした。何をしても、コードの最後の行が実行された後に VB6 IDE が停止します。
ローカル変数へのポインタ以外に原因があります。しかし、何?