Edouard Durand

Edouard Durand

  • NA
  • 46
  • 19k

How to use a dll encoded in delphi from C# in Visual Studio

Apr 29 2020 4:18 AM

Hello,

I have a dll coded in delphi language which thus contains functions in delphi which I would like to use in C# under Visual Studio 2017.

I want to use for example the GENERATE function contained in test.dll.

Below is an example of C # code I made to use test.dll in delphi in C#.

  1. namespace AppTest  
  2. {  
  3.     Public class Program  
  4.     {  
  5.         [DllImport("test.dll", CharSet = CharSet.Ansi)]  
  6.         public static extern bool GENERATE(string pathfilename);  
  7.   
  8.         static void Main(string[] args)  
  9.         {  
  10.             GENERATE(@"C:\Users\file.txt");  
  11.         }  
  12.     }  
  13. }   

 

But when I test this program, I get the following error:

System.DllNotFoundException: 'Unable to load DLL' test.dll ': The specified module could not be found. (Exception from HRESULT: 0x8007007E) '

How to solve this problem ?

I placed test.dll in the folder that contains the C # source files.

How C# is able to read a dll in delphi if Visual Studio does not know delphi?

Thank you for your help.

 

Answers (2)