Calling a Delphi DLL from C# produces unexpected results

前端 未结 7 1330
庸人自扰
庸人自扰 2021-01-05 03:29

I have a Delphi DLL that I did not write, but need to call from a C# ASP.NET 3.5 app. Here is the function definition I got from the developers:

function Cr         


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-05 04:10

    jn is right. The function prototype, as given, cannot be easily called directly from C# as long as it is in Delphi's register calling convention. You either need to write a stdcall wrapper function for it - perhaps in another DLL if you don't have source - or you need to get the people who maintain the function to change its calling convention to stdcall.

    Update: I also see that the first argument is a Delphi string. This isn't something that C# can supply either. It should be a PChar instead. Also, it's important to be clear about whether the function is Ansi or Unicode; if the DLL is written with Delphi 2009 (or later), then it is Unicode, otherwise it is Ansi.

提交回复
热议问题