Re: Testing Delphi DLL crashes VB6 IDE



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



Relevant Pages

  • Re: Testing Delphi DLL crashes VB6 IDE
    ... 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. ... BOSLADCode in 'BOSLADCode.pas'; ... function foo(): PWideString; stdcall; ... You've taken a WideString and told the compiler that it's really a pointer to a WideString. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Testing Delphi DLL crashes VB6 IDE
    ... Result:= 'My dog''s got fleas'; ... function foo(): WideString; ... result:= 'My cat''s on fire'; ...
    (comp.lang.pascal.delphi.misc)