- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我需要在 C++ 中动态加载一个 dll。
我已遵循本教程 http://msdn.microsoft.com/en-us/library/ms235636.aspx创建 dll,一切正常。
然后我关注了这个http://msdn.microsoft.com/en-us/library/64tkc9y5.aspx并且我对控制台应用程序进行了如下调整:
typedef DOUBLE(CALLBACK* DllFunc)(DOUBLE, DOUBLE);
int _tmain(int argc, _TCHAR* argv[])
{
HINSTANCE hDLL; // Handle to DLL
DllFunc dllFunc1;
DOUBLE p1 = 1.0, p2 = 2.0, r;
hDLL = LoadLibrary(L"MathFuncsDLL");
if (hDLL != NULL)
{
cout << "DLL loaded: " << hDLL << endl;
dllFunc1 = (DllFunc)GetProcAddress(hDLL, "MyMathFuncs@MathFuncs@Multiply");
if (!dllFunc1)
{
// handle the error
FreeLibrary(hDLL);
cout << "Function not found!" << endl;
return -1;
}
else
{
// call the function
r = dllFunc1(p1, p2);
cout << "The result is: " << r << endl;
}
}
else {
cout << "Dll not found" << endl;
return -1;
}
cout << "Press any key to exit." << endl;
int i;
cin >> i;
return 0;
}
DLL 已正确加载且不为空。问题是始终返回 0 的 GetProcAddress() 函数。
我已经尝试过命名空间、类名、方法名的每种组合。我尝试在函数名称中使用作用域运算符 (::) 而不是 @。
我试图将整个命名空间定义为 外部“C”但没有任何改变。每次我运行或调试控制台应用程序时,它都找不到“乘法”函数。
我想我错过了什么......我哪里错了?
编辑
Dependency Walker 向我展示了以下导出表:
现在我想知道函数名称的最后一部分是什么意思...为什么 __declspec(dllexports) 添加这些符号?
最佳答案
欢迎使用 C++ 名称修改。编译器添加到您的函数名称中的所有内容都是为了确保每个具有唯一签名的函数都有一个唯一的名称。 Microsoft 以一种方式进行名称重整,而 GCC/Clang 以另一种方式进行。它不是标准化的,但特定操作系统上的编译器都以相同的方式进行名称修改,因此它们都可以相处。
确保您的名字仍可被人类预测的唯一方法是将导出的 DLL 函数声明为 extern "C"
。但是,这会限制您导出 C 函数。
在我处理过的库中,有一个导出的 C 函数用于初始化库并取回接口(interface)指针。在这种情况下,“接口(interface)”是指没有数据和只有虚函数的抽象虚基类。
这是声明接口(interface)类的正确方法:
struct my_interface
{
virtual int my_function1( int param1, int param2 ) = 0;
virtual int my_function2( const char *param ) = 0;
#if CHOOSE_DESTRUCTION_TYPE
protected:
// Protected non-virtual destructor prevents the use of delete on the interface pointer.
// Must be defined because it will be used as objects of derived types are destructed.
~my_interface() {};
#else
// Public virtual destructor allows the use of delete on the interface pointer.
virtual ~my_interface() = 0;
#endif
private:
// Private copy assignment prevents "*ptr1 = *ptr2".
// This odd syntax CAN be supported, but you probably shouldn't.
// Only needs to be declared because nobody can call it.
my_interface & operator=( const my_interface & );
// Ditto for move assignment.
my_interface & operator=( my_interface && );
};
关于C++ GetProcAddress() 找不到静态类的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26365703/
例如,我有一个父类Author: class Author { String name static hasMany = [ fiction: Book,
代码如下: dojo.query(subNav.navClass).forEach(function(node, index, arr){ if(dojo.style(node, 'd
我有一个带有 Id 和姓名的学生表和一个带有 Id 和 friend Id 的 Friends 表。我想加入这两个表并找到学生的 friend 。 例如,Ashley 的 friend 是 Saman
我通过互联网浏览,但仍未找到问题的答案。应该很容易: class Parent { String name Child child } 当我有一个 child 对象时,如何获得它的 paren
我正在尝试创建一个以 Firebase 作为我的后端的社交应用。现在我正面临如何(在哪里?)找到 friend 功能的问题。 我有每个用户的邮件地址。 我可以访问用户的电话也预订。 在传统的后端中,我
我主要想澄清以下几点: 1。有人告诉我,在 iOS 5 及以下版本中,如果您使用 Game Center 设置多人游戏,则“查找 Facebook 好友”(如与好友争夺战)的功能不是内置的,因此您需要
关于redis docker镜像ENTRYPOINT脚本 docker-entrypoint.sh : #!/bin/sh set -e # first arg is `-f` or `--some-
我是一名优秀的程序员,十分优秀!