用c#能不能创建动态链接库DLL供外部程序调用呢?
如果能,怎么做.举个小例.是不是实现后外部程序对其的调用就像是在使用系统API一样.
如果不是,如何调用.或者问题可以总结为:如何创建自己的API以供其他任何语言调用.

解决方案 »

  1.   


    用c#能不能创建动态链接库DLL供外部程序调用 这个应该可一二
      

  2.   

    创建项目时,选择类库就可以生成DLL了
    你把DLL当成自己的API就行了
      

  3.   

    至于调用,将它添加到引用,然后using XXX; 就可以调用了
      

  4.   


    我要提供给别的程序使用,就像你想做在使用api一样.不是在内部使用.
      

  5.   

    至于调用,将它添加到引用,然后using XXX; 就可以调用了
      

  6.   

    我要提供给别的程序员使用,就像你现在在使用系统[user32.dll]的api一样.不是在内部使用.
    或者理解成时我想用c#写一个[user32.dll]之类的东西.
      

  7.   

    添加类库生成dll文件也可添加使用Activex控件
    在其他项目引用DLL。using 命名空间
    看看petshop
      

  8.   


    我不是只要在c#里调用,而是要在所有语言中都适用,就像系统的API.
    如果要在c#里调用的话,要的效果是用这种方式来调用:        [DllImport(@"E:\My Documents\Visual Studio 2008\Projects\实验\MyDLL\MyDLL\bin\Debug\MyDLL.dll")]
            static extern int ADD(int a, int b);
    而不是using XXX;
      

  9.   

    将它添加到引用,然后using XXX; 就可以调用了这里只是指出在C#这样来用!在别的程序当然就是其它语言的用法!只是用法问题!!
      

  10.   

    把Dll编译成共享程序集, 使用时引用就行了。
      

  11.   

    C#只能编写托管的DLL,调用时不能像系统API那样调用。
      

  12.   


    那你说说,比如是c吧,怎么调用c#写出了的dll呢.
      

  13.   


    非托管代码可以调用托管DLL 不过还是要依赖CLR的在windows平台下 使用win api 加载托管DLL和动态加载非托管DLL 类似
      

  14.   


    是这样的,我想做一个DLL文件,里边就一个函数,供各种语言的程序员在编程时直接进行调用.
    请问最方便最简单的方式是什么呢?优先考虑用c#来写这个文件.实在不行再去玩c++.
      

  15.   

    做成com、activex、webservice做成com调用
    http://forums.devshed.com/delphi-programming-90/c-dll-need-to-be-used-in-delphi-231122.htmlYou were definitely closer with your second attempt as you can't load a .NET assembly as if it was a normal C-style DLL. If you're getting "Class not registered" error messages in Delphi it simply means the required registry entries were not available.To use your C# class as a COM object, the best thing to do is put all your methods in one or more interfaces then make the class implement each of those interfaces. 
    Example:
    // IAddInterface.cs
    public interface IAddInterface
    {
        int Add(int i1, int i2);
    }// SimpleDll.cs
    using System.Runtime.InteropServices;[ClassInterface(ClassInterfaceType.None)]
    public class SimpleDLL : IAddInterface
    {
        public int Add(int i1, int i2)
        {
            return i1+i2;
        }
    }Compile using: csc /t:library /out:SimpleDll.dll *.csNext, register the assembly as a COM object in the registry using: regasm SimpleDll.dll /tlb:Add.tlb(The above command will also generate a type library for use in Delphi.)Now you can switch over to Delphi, and click Project->Import Type Library (like you did before). Select your .tlb (Add.tlb in this case) and click Create Unit.In your main unit add "ComObj" and "SimpleDLL_TLB" (or whatever your generated unit is called) to your uses list and write the code to call your .NET methods. Example:procedure TForm1.Button1Click(Sender: TObject);
    var
      intfRef: IAddInterface;
      result: Integer;
    begin
      intfRef := CreateComObject(CLASS_SimpleDLL_) as IAddInterface;
      result := intfRef.Add(2, 2);
    .
    .For it to work your Delphi .exe needs to be in the same directory as the .NET DLL.
      

  16.   

    如果要考虑用其它语言如VB、VC、DEPHI调用,不要用C#等.NET环境语言开发动态类库。运行环境高,执行效率低,托管的优点也没了。
      

  17.   

    要给其他语言调用,最好是使用COMC#的机制与COM是不同的模式,C#是写不了真正的COM的,虽然可以把C#的DLL模拟成一个COM使用,但较麻烦,最好使用其他语言开发
      

  18.   

    c#的DLL 更像COM 而不是像C的API 
    强命名DLL 就可以像System.dll一样,但如果在其他计算机上运行,需要复制本地=true