Re: Testing Delphi DLL crashes VB6 IDE
- From: Jamie <jamie_ka1lpa_not_valid_after_ka1lpa_@xxxxxxxxxxx>
- Date: Fri, 17 Oct 2008 20:21:10 -0400
Bruce M. Axtens wrote:
Rob Kennedy wrote:how about this.
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.
Dmesg(Var sText:WideString,sHead:WideString);
etc///
http://webpages.charter.net/jamie_5"
.
- 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
- Re: Testing Delphi DLL crashes VB6 IDE
- From: Bruce M. Axtens
- Testing Delphi DLL crashes VB6 IDE
- Prev by Date: Re: Delphi language support in CMake build system
- Next by Date: Re: Delphi language support in CMake build system
- Previous by thread: Re: Testing Delphi DLL crashes VB6 IDE
- Next by thread: Re: Testing Delphi DLL crashes VB6 IDE
- Index(es):
Relevant Pages
|