Re: Testing Delphi DLL crashes VB6 IDE



Bruce M. Axtens wrote:

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.
how about this.
Dmesg(Var sText:WideString,sHead:WideString);

etc///


http://webpages.charter.net/jamie_5";

.



Relevant Pages

  • Re: Testing Delphi DLL crashes VB6 IDE
    ... 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. ...
    (comp.lang.pascal.delphi.misc)
  • Re: CComPtr strange behaviour
    ... GetUIObjectOf takes an IUnknown* pointer it got from ... and tells the caller that it's really a pointer ...
    (microsoft.public.vc.atl)
  • Re: segfault w/ block, but not file scope
    ... I don't have a problem freeing the allocated memory. ... But when the struct is declared in main (block scope) it will segfault when passing namelist to freeFileNames. ... Since this seems to be just a matter of my understanding scope and pointer parameter passing better, I only included what thought to be relevant code. ... allocates the necessary memory. ...
    (comp.lang.c)
  • Re: Getting around garbage collection
    ... > If it's really just going out of scope, then you would have the same problem ... >>pointer is useless, and breaks my app if I try to use it. ... What Tom said, but I'd like to point out that the stack is your friend. ...
    (comp.lang.cpp)
  • Re: Global variables in files without functions
    ... It's important to find the exact reason for these crashes. ... The first crash is even funny: In the second line of code. ... pointer in a global variable. ... program-wide in scope, but maybe just file-wide. ...
    (comp.lang.c)