开发者

How to amend DLLs

We are using an external Dlls as :

[DllImport("DemoExport.dll")]
    public static extern string GetDBConnection(string sDBName);
    [DllImport("DemoExport.dll")]
    public static extern int CreateEmptyDBFromDB(string SourceDBName, string DestinationDBName);
    [DllImport("DemoExport.dll")]

Now, we want开发者_开发问答 to add new method in same pattern. We are looking that is there any way to implement method in DemoExport.dll?So, we can use the method say DemoMethod() like:

[DllImport("DemoExport.dll")]
    public static extern void DemoMethod();

It might look like a crazy question, but we really have need to implement this method so, later on we can use the same.

Additionally, if above is not possible then how to create a new dlls or say how use like DllExport which is not available in C#. So, laterly, anyone can use the method with attribute

[DllImport("dllname.dll")]
publis statis extern void mymeth();


You can't use C# to add a method to an existing pre-compiled *.dll.

You'll have to find the source for the DLL, write your method, re-compile, and then utilize that new method from C#.

EDIT

I'm still not sure what you're asking for in your update. If you want to write a new method that can be used by other C# consumers, then you don't have to do anything special with attributes. Simply write a public method on a public class.

After that, any .NET consumer can add an assembly reference to your class and use your method.

If you want any Windows consumer to be able to use your code, you can investigate COM Interop.

If you're still trying to use a C/C++ dll, then my original answer still stands.


I am not sure that i understood you correctly, but you want to add method to existing dll. If i am correct then it is not possible. other options are:

  • Find sources of that dll, add method and recompile
  • Create new dll and implement method there and use new one's name in DllImport
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜