Re: Testing Delphi DLL crashes VB6 IDE
- From: Rob Kennedy <me3@xxxxxxxxxxx>
- Date: Mon, 13 Oct 2008 00:34:53 -0500
Bruce M. Axtens wrote:
I've had my first go at writing a DLL in Delphi. So far so good. By using a typelib I've been able to pass Widestrings to and from the DLL without difficulty.
What's curious at the moment is that I'm using VB6 as the testbed, and every time I run a test within the IDE, the program runs and then the IDE process suddenly disappears from memory - no error messages, nothing. If I step through the code, everything works fine until I execute the last line, then the IDE disappears.
It might have been useful to include some of those lines that you stepped through. It might also have been useful for you to eliminate those lines until the problem went away, thus revealing which of the lines is actually relevant to the problem.
By contrast, when I compile the test to an EXE the program runs to its end, without error messages etc.
But since the program ran to its end without error messages anyway, you've really learned nothing.
Has anyone had this problem before and is there an obvious solution that's staring me in the face?
Kind regards,
Bruce.
P.S. Source code below, in case it matters:
-- project
library BOSLAD;
uses
ShareMem,
SysUtils,
Classes,
BOSLADCode in 'BOSLADCode.pas';
This DLL does not need ShareMem, SysUtils, or Classes.
exports
version,
DMesg,
foo;
{$R *.res}
begin
end.
-- unit
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;
That value cannot be represented exactly as a Double. Are you sure Double is the best choice?
Also, s is never used.
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;
You've taken a WideString and told the compiler that it's really a pointer to a WideString. You're lying to the compiler. It doesn't care, but the caller of this function probably does.
Next, when the variable s goes out of scope (just before the function returns to its caller), the WideString value it holds is destroyed. From then on, whatever value the function returns in an invalid pointer, no matter what type it has.
--
Rob
.
- Follow-Ups:
- Re: Testing Delphi DLL crashes VB6 IDE
- From: Bruce M. Axtens
- Re: Testing Delphi DLL crashes VB6 IDE
- References:
- Testing Delphi DLL crashes VB6 IDE
- From: Bruce M. Axtens
- Testing Delphi DLL crashes VB6 IDE
- Prev by Date: Newbie questions about Delphi...
- Next by Date: Re: Newbie questions about Delphi...
- Previous by thread: Testing Delphi DLL crashes VB6 IDE
- Next by thread: Re: Testing Delphi DLL crashes VB6 IDE
- Index(es):
Relevant Pages
|