Calling Delphi DLL from c# to return text

0

Dears. I have simple Delphi DLL like this

function GetConnection: PChar; stdcall; export;
begin
  Result:= 'connection name is ....';
end;
exports
  GetConnection;

and I am trying from C# as the folowing>

using System.Runtime.InteropServices;

namespace ConsoleApplication2
{
    class Program
    {

        [DllImport("C:/Program Files (x86)/Borland/Delphi7/Projects/Project2.dll",
                      CallingConvention = CallingConvention.StdCall,
                      CharSet = CharSet.Unicode)]
        public static extern string
            GetConnection();

        static void Main(string[] args)
        {
            string theresult = "";

            theresult = GetConnection();
            Console.Write(theresult);
            Console.Write("   Press Enter plese:");
            Console.ReadLine();
        }
    }
}

but I received error (ConsoleApplication2.vshost.exe' has exited with code 1073741855 (0x4000001f))

thanks in advance

c#
asked on Stack Overflow Sep 13, 2016 by Wasim Darwish • edited Sep 13, 2016 by O. R. Mapper

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0