1

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

Community
  • 1
  • 1
menjaraz
  • 7,551
  • 4
  • 41
  • 81
  • 1
    Have you investigated [RemObjects Hydra](http://www.remobjects.com/hydra/default.aspx)? I haven't used it, but I've investigated it for a project. It looks awesome, and will let you interop between Delphi and .Net easily. – David Dec 08 '11 at 13:48
  • 3
    You've provided *a lot* of background information that seems irrelevant to what you've asked for. If you're *really* asking how it works, you can delete nearly everything you've written and just ask how it works. But if you're only asking how it works because you think the answer will help you get your program working, then you should instead ask *directly* how to get your program working. If knowledge of how Unmanaged Exports works is required, then someone's answer will include that information anyway, so you don't need to ask for it if it's not really what you want. – Rob Kennedy Dec 08 '11 at 14:22
  • @David M: Proprietary solution is not an option for me. – menjaraz Dec 08 '11 at 14:28
  • Which C# compiler are you using? – David Heffernan Dec 08 '11 at 14:36
  • 1
    @Rob Kennedy: I provide them for scrutinity (there might be something wrong), also as an evidence of my prior effort (often required on SO). – menjaraz Dec 08 '11 at 14:36
  • @menjaraz The point is that you appear to have asked a question to which you do not want the answer. It appears to me that you want to know how to make your unmanaged exports work. You don't actually care how they work under the hood, you just want them to work. Rob is suggesting that you edit your question to ask what you want. – David Heffernan Dec 08 '11 at 14:44
  • @David Heffernan: SharpDevelop Version : 4.0.0.7070-dce2df4c .NET Version : 4.0.30319.225 OS Version : Microsoft Windows NT 6.1.7601 Service Pack 1 – menjaraz Dec 08 '11 at 14:46
  • But *your* code is completely irrelevant to how Unmanaged Exports works. And since your code is apparently broken, it doesn't even help to illustrate how the library works. So, do you really want to know how the library works, or do you just want help with your program? – Rob Kennedy Dec 08 '11 at 14:48
  • That's your IDE. Which compiler? – David Heffernan Dec 08 '11 at 14:51
  • @David Heffernan: How can I progress without some (indepth why not) knowledge ? On the other side, getting it to work is also a priority. – menjaraz Dec 08 '11 at 14:53
  • @Rob Kennedy: I think striping off all the (broken/irrelevant) code is tantamount to asking for a bare sample proof of concept. – menjaraz Dec 08 '11 at 15:12
  • You can make *plenty* of progress without in-depth knowledge. I was writing programs for a *decade* before I knew how compilers work. Your comment is the first mention of a proof of concept. A POC won't show how the library works, either. To explain how it works, an answer will need to talk about what input the .Net compiler generates and how the Unmanaged Exports postprocessor uses that information to generate a non-.Net DLL interface. How that DLL gets consumed isn't all that interesting because it should be the same as how any other native DLL gets consumed. – Rob Kennedy Dec 08 '11 at 15:21
  • Also, your recent edit actually makes the question *worse*. Please don't ask for *both* things in one question. They require completely different answers, and those answers will probably come from different people, or perhaps from nobody, if nobody feels qualified to answer both parts. Post separate questions for the separate aspects of your project. Use one to ask how to make your program work, and use the other to ask how Unmanaged Exports works. – Rob Kennedy Dec 08 '11 at 15:23
  • @David Heffernan: 4.0.30319.1 // <<< (but 8.00.50727.4927 for framework version 2.0.50727, 3.5.30729.5420 for .Net version 3.5 also available) – menjaraz Dec 08 '11 at 16:14
  • Which compiler? MS compiler or Mono compiler? – David Heffernan Dec 08 '11 at 16:16
  • @David Heffernan: MS compiler – menjaraz Dec 08 '11 at 17:19

1 Answers1

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I've made it! Thank you for reminding me of Dependency Walker, I know it but it never cross my mind. Insisting on SharpDevelop was hasardous for me, given my poor level on .Net/C#. Moreover it has been extensivly tested by the author on that setup. Delphi rocks. – menjaraz Dec 08 '11 at 18:39
  • I was completely beside the point. It's clear and bright that Rob Kennedy is definitely right stating that the piece of code is broken. My solution doesn't trigger the MSBuild task supposed to allow the so needed export. I've tried later to get a working sample for my setup (SharpDevelop) based on the template (tweak it by hand) but it turns out that "lib.exe" is missing from my tool chain or I still must fix some path somewhere. – menjaraz Dec 09 '11 at 05:04