Search code examples
delphidlllazarus

calling a visual studio dll from delphi or lazarus


I need to call a dll from delphi 7 or lazarus. The information on the dll is minimal but I have an example of its use in visual studio: Declarations:

    [DllImport("landwell.dll", EntryPoint = "PTcomm", CharSet = CharSet.Auto)]
    public static extern int PTcomm(int com, int boud, ref int Rcount);
    [DllImport("landwell.dll", EntryPoint = "PTcomm_YPWJ", CharSet = CharSet.Auto)]
    public static extern int PTcomm_YPWJ(int com, int boud, ref int Rcount);

    [DllImport("landwell.dll", EntryPoint = "PTrecord", CharSet = CharSet.Auto)]
    public static extern int PTrecord(int num,byte[] record);

How do I declare and call these functions in Delphi 7 or Lazarus?

The only documentation I have is: 1、Common Transmit: PTcomm(int com,int boud,int *Rcount) Com is for serial port number,boud rate is 9600, *Rcount is for recording the total number
"1" means returning successfully, "0 "means no record,"-1”means opening the port unsuccessfully,“-2 ”means transmiting unsuccessfully

2、Common collecting data PTrecord(int num,byte record[8]) record{8} means 8byte(including the reader number), num means the serial number "1" means return successfully,"0" means return unsuccessfully I only have an example in Visual Studio which I cannot even try as it was written in an older version of VS and the automatic conversion did not work. At this time I have no intention of learning VS. The declarations mentionned earlier in the post come from that example. I have been accused of not even trying by someone who does not know me and has no idea of what I did. I tried and failed which is the reason I am asking.

Thanks, Jean-Claude


Solution

  • Try these declarations in Delphi and Lazarus:

    function PTcomm(com, boud: Integer; var Rcount: Integer): Integer; stdcall; external 'landwell.dll';
    
    function PTcomm_YPWJ(com, boud: Integer; var Rcount: Integer): Integer; stdcall; external 'landwell.dll';
    
    function PTrecord(num: Integer; rec: PByte): Integer; stdcall; external 'landwell.dll';