如何从c++ / c#调用这个DLL函数
How to call this DLL function from either C++ / C#
我花了很多时间想弄清楚这个问题,所以我想我可以在这里得到一些帮助。基本上我有一个DLL函数像这样在IDL中声明:
[id(1), helpstring("method findFile")] HRESULT findFile(
[in] BSTR fileName,
[out] LONG* someValue
);
我如何确切地声明和调用从c++/c# ?
注意:有一个VB6应用程序成功地调用了这个函数。声明:
Private Declare Function findFile Lib "thedll.dll" ( _
ByVal fileName As String, _
ByRef someValueAs Long _
)
调用:
Dim a As String
Dim b As Long
Dim r As long
a = "image.jpg"
b = -1
r = findFile(a, b)
附录:
我不能保证VB6代码看起来像那样,因为我有可执行文件,我只被告知那部分看起来像什么,所以也许你们是对的,它不匹配。我确实编写了c++ DLL,现在我需要自己编写一些代码来成功地调用DLL,以便尝试一些东西,而不是依赖于那个exe。
DLL函数的c++实现是这样的:
STDMETHODIMP CFinder::findFile(BSTR fileName, LONG* someValue)
{
*someValue = 8;
return S_OK;
}
未经测试的c#声明:
[DllImport("thedll.dll", SetLastError=true)]
static extern int findFile([MarshalAs(UnmanagedType.BStr)]string fileName, out int someValue);
相关文章:
- Visual c ++,使用字符串引用/指针调用 dll 函数
- 在 Microsoft Access SQL 中调用自定义 DLL 函数时传递的内存地址无效
- 调用 "project" 函数和调用 DLL 函数之间的区别
- 代码在 msvcrt .dll函数上设置断点失败
- VB.NET DLL中的C++DLL函数复制
- 在python-ctypes中声明变量并传递给dll函数
- 从 Python 调用 Windows DLL 函数时出错
- 调用 dll 函数时"Run-Time Check Failure #0 - The value of ESP"
- 列出 C# 中的 non-.NET DLL 函数
- 基本 DLL 函数
- 如何在不可修改的源代码中使用 DLL 函数?
- 对需要双精度数组和结构作为输入C++ DLL 函数的 C# 调用
- WScript.CreateObject 在调用 C++ COM dll 函数时返回空
- 如何在 lua cpp 模块中调用托管 c++ dll 函数
- 测试C++ DLL 函数
- 从 C# GUI 将 char * 参数传递给C++ dll 函数
- 使用指针调用C++ DLL 函数
- 在C++中导入 DLL 函数
- #VALUE!在 64 位 Excel 中调用 DLL 函数 (C++) 时
- 如何从 UWP 应用调用"libheif.dll"函数