DLL works without borlandmm.dll, but why?


2003-10-11 08:37:12 PM
delphi190
Delphi tells me that if I pass a string to or from a DLL I should use
ShareMem and borlandmm.dll
So, what I do is not pass a string but use PChar (see code below).
Well, ok, this works.
------------------------------------------------------------------------------
Delphi:
function DisplayMsg(Y: PChar; X: Smallint): Boolean; stdcall;
var
i: Integer;
s: String;
begin
s := '';
for i := 1 to X do
begin
s := s + Y^;
Inc(Y);
end;
ShowMessage(s);
Result := True;
end;
VB:
Declare Function DisplayMsg Lib "..\Project1.dll" (ByVal Y As String,
ByVal X As Integer) As Boolean
Dim MyStr As String
MyStr = "blabla"
Call DisplayMsg(MyStr, Len(MyStr))
------------------------------------------------------------------------------
Now, for fun, I just tried to pass a string without using ShareMem.
And this too, does work! But it shouldn't, right? The least it could
do is crash my program. Or shut down my system. But, please don't let
it popup a message with my string in it.
But it does and why is that?
------------------------------------------------------------------------------
Delphi:
function DisplayMsg(s:String): Boolean; stdcall;
begin
ShowMessage(s);
Result := True;
end;
VB:
Declare Function DisplayMsg Lib "..\MyDll.dll" (ByVal s As String) As
Boolean
Call DisplayMsg("blabla")