How to fix this unmanaged exports trouble using Delphi/C#

烂漫一生 提交于 2019-12-11 08:18:35

问题


I came across Unmanaged exports technique in this anwser on SO.

  • I can manage myself to have simplest project working on SharpDevelop, albeit I don't have a good command of C#.
  • I want to use the excellent Gavaghan.Geodesy (.Net/C#) library written by Mike Gavaghan.
  • I want to avoid interoperability through COM.
  • I definitely use Delphi. I only want to harness the library with it.

I managed to build the following code :

using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;

namespace DelphiNET
{
    internal static class UnmanagedExports
{
    [DllExport("add", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
    public static int add(int left, int right) {
        return left + right;            
        }

    }
}

I probed it with Delphi but was in vain.

I checked the output dll with a PE editor but It turned out to have no export data at all.

I miss something and I'm confused.

Edit:

Please - Help me fix the trouble


回答1:


I managed to get this to work like this:

  1. Download the C# Project template. This requires Visual Studio but you should be fine with the Express version.
  2. Create a new project based on the template.
  3. Build that project.
  4. Load the DLL in Dependency Walker to see that it does indeed export the function. I succeeded in calling the function from Delphi.

Note that the path to find the DLL is bin\Debug\x86. There is a DLL in bin\Debug but this has no exports. Perhaps that's what you have been looking at.



来源:https://stackoverflow.com/questions/8431313/how-to-fix-this-unmanaged-exports-trouble-using-delphi-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!