简体   繁体   English

用C#编写的DLL,试图导入到另一个C#项目(DLL不能在根目录下)

[英]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. 嗨,大家经过几个小时的搜索和搭售我能找到的东西(因为我能找到的大部分是在C ++上制作的DLL到C#项目中,这不是我想要的)我带着一个问题来到这里: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 ). 我正在尝试运行该程序,但希望DLL文件位于另一个目录中(例如,程序位于c:\\ Programs \\ Program和DLL:c:\\ Libs上)。

I have made an DLL in C# that have various methods public, that I want to have access in my program. 我已经在C#中创建了一个具有各种公共方法的DLL,我想在我的程序中访问它。

The DLL I have something like this: DLL我有这样的事情:

[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' 无法在DLL“ITranslate.dll”中找到名为“translate”的入口点

You can't use DllImport to reference C# libraries. 您不能使用DllImport来引用C#库。

Instead, add a reference to the DLL in your project and use it just as any other reference (eg. System.Windows.Forms etc.). 相反,在项目中添加对DLL的引用,并将其用作任何其他引用(例如, System.Windows.Forms等)。

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). 您不必拥有ComVisible类或任何东西 - 所有.NET程序集都会公开它们的所有对象和元数据(使用private和此类关键字有些限制,但最终,您可以通过一些工作获得这些关键字)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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