ByVal/ByRef confusion with strings

From: Mike McWhinney (eljainc_at_ameritech.net)
Date: 01/23/04


Date: 22 Jan 2004 21:23:54 -0800

Hello,

I am converting some VB code into Delphi 5.0. I have
come across a construct such as:

Public Declare Function USBm_DeviceVID Lib "USBm.dll"
        (ByVal device As Byte) As Integer

This would translate to the following equivalent in Delphi:

Function USBm_DeviceVID(device:Byte):smallInt; stdcall; external
'USBm.dll'

However when I get to the following:

Function USBm_RecentError Lib "USBm.dll"
        (ByVal errorstring As String) As Integer

I would tend to write this as:

Function USBm_RecentError(errorstring:widestring):smallint; stdcall;
external 'USBm.dll'

However, in the function description it says that 'errorstring' is
returned
with the value of the error. Shouldn't ByVal be ByRef instead in the
previous function? Or should the Delphi function have a var
parameter.

I understand that string parameters are passed as pointers in VB.

Could someone please clear this up for me?

Thanks.

Mike McWhinney



Relevant Pages

  • Re: problem using delphi dll in vc++
    ... I just don't understand how you were able to link a Delphi DLL ... I just don't know where your LIB file is coming from, ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Visual C++ LIB to Delphi
    ... > create a LIB file instead so I can embed it inside the EXE? ... Delphi linker doesn't understand C++ object files entirely, so the only thing you can link in are C ... Delphi entry point. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Writing a library (DLL or LIB)
    ... generate either the C obj or C++ obj files for linking into a LIB? ... >I wrote a DLL in Delphi and the only way I could make it work in C was to ... > create DLL's for other languages to use. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: C++-Library in Delphi-Programm nutzen
    ... Nun muss ich Delphi irgendwiebeibringen, ... die Funktionen passend zu deklarieren, um sie aufrufen zu können. ... ...aber wie bringe ich den ABC-Namespace unter und sage, dass die Funktion aus einer Lib kommt? ...
    (de.comp.lang.delphi.misc)
  • Re: Is D2005 released for W2k or/and WinXP
    ... Chris Burrows schreef: ... I am aware of MSLU, but it won't work with Delphi. ... It is a library that can be linked with visual ...
    (borland.public.delphi.non-technical)