Writing DLLs in Delphi

Major Problems with Functions

There is a major problem when using functions that return float type numbers such as single and double. Because of the different methods that Borland and Microsoft use to pass float numbers, you CANNOT return a single or double in a function written in Delphi. The following will work OK :

  function ChangeSingle(x1 : single): integer; export;  {returns integer}
  procedure ChangeSingle(x1 : single; var x2 : single); export;
The following will NOT work:
  function ChangeSingle(x1 : single): single; export;  {returns single}

If you want to use the functionality of a function, a wrapper in VB needs to be used. For example in VB the code would be:

  function VBChangeSingle(x1) as single
      call ChangeSingle(x1, x2)
      ' this corresponds to procedure ChangeSingle
                                        (x1 : single; var x2 : single)	
      ' VB declaration is: declare sub ChangeSingle lib "rgdll" 
                                       (byval x1 as single, x2 as single)
      VBChangeSingle = x2
  end function

Image of arrow to previous article Image of arrow to next article

Image of line
[HOME] [TABLE OF CONTENTS] [SEARCH]