views:

44

answers:

2
+1  Q: 

How to amend DLLs

Hello experts,

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();
+1  A: 

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
Andrey
@andrey - thanks for clarifying, I edited the question please check now
Rick
+3  A: 

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.

Justin Niessner
@Justin - Thanks and sorry for not writing well due to the same you unable to understand my problem.Let me try to represent the same:Three methods are in some unmanaged code we are using the dllsNow we use the functions as stated in my original code.Now I have to add a new method this new method will use the above three method in my class library project.This is because we have to supply the dll of this project to some another project. What to do now?
Rick