简体   繁体   中英

DLL made in C#, trying to import to another C# project (DLL can't be on root directory )

Hi guys after a few hour searching and tying what i could find ( since most of I could find is the DLL made on C++ into a C# project and that is not what I want ) I come here with a question :D.

I'm trying to run the program, but want the DLL file to be on another directory ( For example the program is on c:\\Programs\\Program and DLL on c:\\Libs ).

I have made an DLL in C# that have various methods public, that I want to have access in my program.

The DLL I have something like this:

[ComVisible(true)]
[Guid("6E873AA1-1AD6-4325-BBFD-EF22A3EB80CC")]
public interface ITraducoes
{
    [ComVisible(true)]
    void changeLang(String lang);
    [ComVisible(true)]
    void translate(Control form);
    [ComVisible(true)]
    string toolTipText(Control form, String toolTip);
    [ComVisible(true)]
    string[] listText(Control form, String lista);
    [ComVisible(true)]
    string[] getMessagesArray();
    [ComVisible(true)]
    Hashtable getMessagesTable();
}
#region Traducoes Class
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("AE53E0A3-8261-4706-8861-0249F7390642")]
//[ProgId("ITranslate.Traducoes")]
public class Traducoes : ITraducoes
{...

And on the programa I have something like this:

[DllImport("ITranslate.dll", CallingConvention = CallingConvention.Cdecl)]
extern static void translate(Control form);
[DllImport("ITranslate.dll")]
extern static string[] getMessagesArray();

And then I call then like this:

public Form1(string[] args){
    InitializeComponent();                  
    translate(this);
    msg = getMessagesArray();

I hope I haven't miss anything, but if I do, I will do my best to provide it.

EDIT.

Forgot to say, that I'm geting this error

Unable to find an entry point named 'translate' in DLL 'ITranslate.dll'

You can't use DllImport to reference C# libraries.

Instead, add a reference to the DLL in your project and use it just as any other reference (eg. System.Windows.Forms etc.).

You don't have to have the class ComVisible or anything - all .NET assemblies expose all of their objects and metadata (somewhat limitable using private and such keywords, but in the end, you can get those too with a bit of work).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM