Re: Testing Delphi DLL crashes VB6 IDE
- From: "Bruce M. Axtens" <bruce.axtens@xxxxxxxxx>
- Date: Wed, 15 Oct 2008 12:17:18 +0800
Rob Kennedy wrote:
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.
I stand corrected. And apologies to you, as you sound a little annoyed with my naivete. And what you have said works a treat. Thank you very much for your patience. It is very much appreciated.
Kind regards,
Bruce.
---
library BOSLAD;
uses
BOSLADCode in 'BOSLADCode.pas';
exports
version,
DMesg,
foo;
{$R *.res}
begin
end.
---
interface
function version() : Double; stdcall;
procedure DMesg(sText : PWideChar; sHead : PWideChar ); stdcall;
function foo() : PWideChar; stdcall;
implementation
uses Windows;
var s : WideString;
function version() : Double;
begin
result := 0.001;
end;
procedure DMesg( sText : PWideChar; sHead : PWideChar);
begin
Windows.MessageBoxW(0, sText, sHead, 0);
end;
function foo() : PWideChar;
begin
s := 'My dog''s got fleas';
result := PWideChar(s);
end;
end.
---
// This is the type library for BOSLAD.dll
[
uuid(0C55D7DA-0840-40c0-B77C-DC72BE9D109E),
helpstring("BOSLAD TypeLib"),
lcid(0x0409),
version(1.0)
]
library BOSLAD
{
[
helpstring("Functions in BOSLAD.DLL"),
version(1.0),
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 );
}
};
---
Sub Main()
Dim cfg As New CFGProject.cfg
cfg.Load "test.cfg"
Dim s As String
s = cfg.Recall("msg")
DMesg s, "" & version
s = foo
DMesg s, "" & version
End Sub
---
#test.cfg
msg=毅訜訝
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: Maarten Wiltink
- 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
- Testing Delphi DLL crashes VB6 IDE
- Prev by Date: Re: VCL for Web HTML Rendering
- 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
|