menjaraz
menjaraz

Reputation: 7575

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

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

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

Upvotes: 1

Views: 1766

Answers (1)

David Heffernan
David Heffernan

Reputation: 612794

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.

Upvotes: 1

Related Questions