Are the methods from the Delphi library compatible with P / Invoke? And if not, is there any way to make them compatible?

There is access to the source code .dll.

  • on Delphi the native library is written? - Grundy
  • one
    @Grundy: Well, Delphi can have his own name mangling. - VladD
  • one
    @Grundy: I ​​do not know. If you know how, say :) - VladD
  • one
  • one
    Yeah, if the function can be connected via dllimport, then P / Invoke should work. - VladD

1 answer 1

For a start, it is worth looking in the source code with which agreement on calls the functions from the library are exported.

If there is stdcall or cdecl , then such a function can be called without problems through P / Invoke. If the agreement is not specified there, then it will not be so easy.

In this case, if the source code of the library cannot be changed - the simplest solution would be a layer from another Delphi library:

 procedure Foo(...); external 'MyLib.dll'; // ... procedure Foo_Std(...); stdcall; begin Foo(...); end; // ... exports Foo_Std name 'Foo'; 
  • The problem is that they have a non-standard agreement on calls: ru.stackoverflow.com/q/494011/#comment583436_494011 - VladD
  • @VladD if you write the stdcall keyword, then the calling agreement suddenly becomes standard :) - Pavel Mayorov
  • @VladD if they had everything through the box outside the box - then Pascal programs could not use third-party libraries and COM components - but this does not happen. What WinAPI, what the same DirectX - in Delphi work without tricks with parameters. - Pavel Mayorov
  • Yeah, this is important. It may be worth noting the importance of this keyword in the answer. - VladD
  • What does the "importance"? I have the entire answer about this keyword and it was written :) - Pavel Mayorov