Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I composed .Net 3.5 dll with single method, which is to be called by Delphi .exe. Unfortunately it does not work.

The steps: 1. Create C# 3.5 dll with the code:

public class MyDllClass
{
    public static int MyDllMethod(int i)
    {
        MessageBox.Show("The number is " + i.ToString());
    }
}
  1. Go to Assembly Properties --> Assembly Information and checked the "Make Assembly COM-Visible"
  2. Used RegAsm.exe to register my dll

This throws Delphi exception which indicates it cannot connect the dll. What are the steps required to enabled usage of C# managed dll from unmanaged code.

Does any one familiar with good example about the subject?

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
555 views
Welcome To Ask or Share your Answers For Others

1 Answer

You may have more luck skipping the COM part by using my project template for unmanaged exports

class MyDllClass
{
    [DllExport]
    static int MyDllMethod(int i)
    {
        MessageBox.Show("The number is " + i.ToString());
        return i + 2;
    }
}

In Delphi, you'd import it like so:

function MyDllMethod(i : Integer) : Integer; stdcall; extern 'YourAssembly.dll';

I had to vote your question down, though. For not even caring as much as to provide code that would compile. (your C# method doesn't return a value, yet it expects as int)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...