gpt4 book ai didi

c# - LINQPad:尝试使用使用 [DllImport] 的程序集来访问 C++ dll

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:54:28 29 4
gpt4 key购买 nike

我添加了 MyAssembly.dll 作为对我的查询的附加引用,并且工作正常:我可以毫无问题地使用它的各种类。

MyAssembly.dll 中的一个类的其中一个方法引用了另一个 dll (Wrapper.dll)。 Wrapper.dll 使用 [DllImport] 访问 C++ dll (C.dll) 中的功能:

[DllImport("C.dll", CallingConvention = CallingConvention.StdCall, EntryPoint ="CPlusPlusFunction")] internal static extern UInt32 _CPlusPlusFunction([MarshalAs(UnmanagedType.LPWStr)] string file_path);

虽然此方法在从引用 MyAssembly.dll(引用 Wrapper.dll,引用 C.dll)的 MyApp.exe 执行时工作得很好,但在 LINQPad 中我无法让它工作。

如果我只添加对 MyAssembly.dll 的引用并尝试运行该方法,我会得到:

DllNotFoundException: Unable to load DLL 'C.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

如果我只为 Wrapper.dll 添加附加引用,我会得到同样的错误。

如果我为 Wrapper.dll 和 C.dll 添加附加引用,我得到:

Metadata file 'C.dll' could not be opened -- 'An attempt was made to load a program with an incorrect format.'

如果我只为 C.dll 添加附加引用,我会得到同样的错误。

关于如何让它在 LINQPad 中像在 MyApp.exe 中一样工作,有什么想法吗?

最佳答案

您以完全相同的方式执行此操作,您必须将其复制到与 EXE 相同的目录中,以便 Windows 可以找到它。本例中的 LINQPad EXE。 C:\Program Files (x86)\LINQPad4 默认情况下。或者 PATH 上的任何目录,c:\windows\syswow64 是臭名昭著的选择。最好不要那样做。

关于c# - LINQPad:尝试使用使用 [DllImport] 的程序集来访问 C++ dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19031735/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com