Re: Testing Delphi DLL crashes VB6 IDE
- From: "Bruce M. Axtens" <bruce.axtens@xxxxxxxxx>
- Date: Wed, 15 Oct 2008 17:37:01 +0800
Rob Kennedy wrote:
Although the type in foo is now accurate, there's still the problem that s goes out of scope before the function returns, and thus the pointer is not valid by the time it arrives at the caller.
But since the address that s held is probably still within your process's address space, and COM probably hasn't re-allocated it to anything else, it probably still contains the same characters it did a moment ago when it was still a valid pointer, so the caller will blithely read it and get what you were expecting, so it appears to work. But a program that accidentally works most of the time is still broken.
Is this getting any closer?
...
uses Windows, ActiveX;
...
procedure DMesg( sText : WideString; sHead : WideString);
begin
Windows.MessageBoxW(0, PWideChar(sText), PWideChar(sHead), 0);
end;
function foo() : PWideChar;
var s : WideString;
begin
s := 'My dog''s got fleas';
result := ActiveX.SysAllocString(PWideChar(s));
end;
Kind regards,
Bruce.
begin:vcard
fn:Bruce M. Axtens
n:Axtens;Bruce
org:The Protium Project
adr:;;;;;;Australia
email;internet:bruce.axtens@xxxxxxxxx
title:Software Engineer
x-mozilla-html:FALSE
url:http://www.protiumblue.com
version:2.1
end:vcard
- Follow-Ups:
- Re: Testing Delphi DLL crashes VB6 IDE
- From: Jamie
- Re: Testing Delphi DLL crashes VB6 IDE
- From: Rob Kennedy
- Re: Testing Delphi DLL crashes VB6 IDE
- References:
- Testing Delphi DLL crashes VB6 IDE
- From: Bruce M. Axtens
- Re: Testing Delphi DLL crashes VB6 IDE
- From: Rob Kennedy
- Re: Testing Delphi DLL crashes VB6 IDE
- From: Bruce M. Axtens
- Re: Testing Delphi DLL crashes VB6 IDE
- From: Rob Kennedy
- Testing Delphi DLL crashes VB6 IDE
- Prev by Date: Re: Testing Delphi DLL crashes VB6 IDE
- Next by Date: Re: Testing Delphi DLL crashes VB6 IDE
- Previous by thread: Re: Testing Delphi DLL crashes VB6 IDE
- Next by thread: Re: Testing Delphi DLL crashes VB6 IDE
- Index(es):
Relevant Pages
|