0

I have a C# library I am exporting as an extension for a C++ program. I am using the unmanagedexports package to export the functions.

Question Update:
So initially I thought I needed a .def file to accompany my C# dll when it was being imported by the C++ application however after Martheen's comment it seems my dll has no exported functions at all. I am assuming this after the tools MakeDef and DLL Export Viewer both showed the dll as having no exports.

Code I am using is below:

using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using RGiesecke.DllExport;

namespace TestExtension
{
    public class TestClass
    {
        public static AppDomain TestDomain;

        [DllExport("TestFunc")]
        public static void TestFunc(ExtensionClient client, [MarshalAs(UnmanagedType.LPStr)] string args)
        {
            client.Print("TestOutput");
        }
    }
}

The rest of the original question:
The program I am loading them into says it needs a .def file in the documentation. I understand this file is created by C++ programs and documents the exported functionality of a dll. My C# project creates a .pdb file which I understand does a similar thing however it's not in a human readable format and just changing the extension to .def didn't seem to work.

So my question is can I create a .def file for my C# dll or is there another suitable workaround/solution to this problem?

John164
  • 119
  • 1
  • 8
  • 1
    Have you tried https://www.codeguru.com/tools/standalonetools/article.php/c1351/MakeDef--Intelligent-DEF-file-Generator-for-Win32-Apps.htm ? – Martheen May 27 '20 at 02:33
  • I have not tried it but I will and I will update with results. – John164 May 27 '20 at 02:41
  • So it seems I have a worse problem than I thought I did. Using MakeDef I got a fatal error stating it could not read the export table and after running a tool called DLL Export Viewer I found after some quick googling that could also not read the export table. As such I shall update the question to reflect this. Thank you for helping it is very much appreciated. – John164 May 27 '20 at 02:51
  • I don't recall anything actually needing a .def file in 32 bit windows. What you probably want is an import library. GCC ships with a tool to make import libraries from dlls. – Joshua May 27 '20 at 02:59
  • 2
    `using RGiesecke.DllExport;` That hasn't been updated in a really long time. Why not use COM interop, instead, which is the recommended and supported way for unmanaged code to use .NET assemblies? Or use C++/CLI on the other side and communicate directly. – dxiv May 27 '20 at 03:07
  • I was using it mainly because the examples I saw were using it. If you have any guides on using COM interop that cover a situation like this I would be really interested to see them. – John164 May 27 '20 at 04:16
  • 1
    See for example [this](https://stackoverflow.com/a/53016935) and the other links on that page. – dxiv May 27 '20 at 04:32

0 Answers0