如何修改DLL

发布于 2024-09-15 10:40:08 字数 725 浏览 3 评论 0原文

我们使用外部 Dll 为:

[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")]

现在,我们想要以相同的模式添加新方法。我们正在寻找是否有任何方法可以在 DemoExport.dll 中实现方法?因此,我们可以使用 DemoMethod() 这样的方法:

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

这可能看起来像一个疯狂的问题,但我们确实需要实现这个方法,所以稍后我们可以使用相同的。

另外,如果上述方法不可行,那么如何创建新的 dll,或者说明如何使用 C# 中不可用的 DllExport。所以,以后任何人都可以使用带有属性的方法

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

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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无声情话 2024-09-22 10:40:08

您无法使用 C# 将方法添加到现有的预编译 *.dll 中。

您必须找到 DLL 的源代码,编写您的方法,重新编译,然后利用 C# 中的新方法。

编辑

我仍然不确定您在更新中要求什么。如果您想编写一个可供其他 C# 使用者使用的新方法,那么您无需对属性执行任何特殊操作。只需在公共类上编写公共方法即可。

之后,任何 .NET 使用者都可以添加对您的类的程序集引用并使用您的方法。

如果您希望任何 Windows 用户都能够使用您的代码,您可以研究 COM Interop。

如果您仍在尝试使用 C/C++ dll,那么我原来的答案仍然有效。

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.

迟月 2024-09-22 10:40:08

我不确定我是否正确理解了您的意思,但您想向现有 dll 添加方法。如果我是对的那就不可能了。其他选项是:

  • 查找该 dll 的源,添加方法并重新编译
  • 创建新的 dll 并在那里实现方法,并在 DllImport 中使用新的名称

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文