如何从调用程序访问 DLL 的变量?
How to access a DLL's variable from the calling program?
我有一个.dll,我正在尝试使用Unity3D。我需要的是两者之间的实时通信,因此在 DLL 中我有一个循环,它执行一些计算,然后使用参数调用以下函数 myvalue, 0
__declspec(dllexport) double __cdecl MyMathFuncs::Divide(double value, double b)
{
static int numfound = 0;
if(value == -1 && b == -1) //for args -1, -1, this is a...
return numfound; // ...GETTER
else numfound = value ; // if args are other then -1,-1, this is a SETTER
return -1;
}
问题是,每次从 Unity 的 Update(( 函数中调用此函数作为 getter 时,它都会返回零,无论我在另一个函数的循环中将其设置为什么。我在 Visual Studio 中对其进行了测试,并在那里获得了预期的输出 - 所以我想变量的范围或生存期存在问题。我还尝试声明一个全局变量并访问它,但它的值也是零。我该如何解决这个问题?
您的方法确实返回
-
0
如果value
和b
相等-1
-
-1
否则。
你确定最后一个语句不应该return numfound
(或return value
(吗?
设置 numfound = value
对输出没有任何影响,因为您使用每个方法调用重新初始化numfound
。如果你想在方法之外使用它,你是对的,你需要把它作为一个全局变量。
相关文章:
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 从 exe 和 dll 访问静态库中的 extern 变量
- 视觉C++:在 DLL 加载期间,全局变量初始化顺序是否具有确定性?
- 是否可以在C++中基于程序集输出(.dll或.exe)定义变量
- 在python-ctypes中声明变量并传递给dll函数
- 在链接到两个 exe 的 dll 中共享全局变量
- 全局外部指针变量在 DLL 中不可见
- dll 中静态成员变量的生存期
- 如何从DLL检索数组变量?(视觉C )
- 当InProcServer32键定义DLL的完整路径时,path环境变量中为什么需要COM DLL的路径
- Visual Studio (2012) 更改 dll 以导出类和变量
- Dll和非模板类中模板方法中的静态变量
- 将sf::纹理存储在dll中的静态变量中
- DLL libarry 中相同的静态和全局变量
- 在DLL中仅初始化变量一次
- C 如何使DLL从主线程修改变量
- DLL 中的 C++ 静态局部变量初始化会导致_CrtIsValidHeapPointer异常
- 从 DLL 导出全局常量变量
- 我有一个 C# 程序的C++ DLL 变量