Function result PChar in Delphi. Empty string.

Function result PChar in Delphi. Empty string.

Anonymous
Not applicable
839 Views
2 Replies
Message 1 of 3

Function result PChar in Delphi. Empty string.

Anonymous
Not applicable
Hi all,

I'm currently writing a DLL using Delphi 5.
When I try to return an empty string as a function result, Result :=
PChar(''), the
result in VBA is not an empty string, but a string with length 4096
containing rubbish.
I'm using the PChar type for all string parameters and function types that
have
anythin to do with strings.

Can anyone help?

Thanks in advance.
Guido Rooms.
0 Likes
840 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Guido - What kind of DLL? ActiveX or just a regular DLL with
exported functions?

If the latter, then how are you declaring the function in
Delphi, and how are you declaring/calling it in VB? Also,
have you tried returning a non-empty string? And, if so,
what happens in that case?

Guido Rooms wrote:
>
> Hi all,
>
> I'm currently writing a DLL using Delphi 5.
> When I try to return an empty string as a function result, Result :=
> PChar(''), the
> result in VBA is not an empty string, but a string with length 4096
> containing rubbish.
> I'm using the PChar type for all string parameters and function types that
> have
> anythin to do with strings.
>
> Can anyone help?
>
> Thanks in advance.
> Guido Rooms.

--
/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* tony.tanzillo@worldnet.att.net */
/* http://ourworld.compuserve.com/homepages/tonyt */
/*********************************************************/
0 Likes
Message 3 of 3

Anonymous
Not applicable
Tony,

It's about a regular DLL.
All my string parameters in Delphi and the function
result types are PChar.
In VBA I'm using ByVal Param As String

But meanwhile I've found the answer :

(1) To pass an empty string as parameter from VBA one has to use
vbNullString
and this parameter can then be tested in Delphi with "if Param = '' then..."
(2) To return an empty string from Delphi, one does not return something
like
"Result := PChar('') but simply "Result := nil"

Anyway, much thanks for your reply.
Guido Rooms
0 Likes