问题描述
我将首先展示我的代码,以便更容易解释:
我将首先显示我的代码解释更容易:
Hi,
I will show my code first to make explaining easier:
Hi,
I will show my code first to make explaining easier:
//EXE
__declspec(dllimport) exportedDLLfunc(int i):
void exeFunc()
{
for(int i=0; i<10;i++)
exportedDLLfunc(i);
}
//someDLL
__declspec(dllexport) void exportedDLLfunc(int i);
someStruct_t gSome[10];
void exportedDLLfunc(int i)
{
//When exportedDLLfunc is called from the exeFunc() gSome has zero values, NOT NULL
//When exportedDLLfunc is called from the anotherdllfunc gSome is not NULL, and the program works perfectly (original version)
//When exportedDLLfunc is called from both exeFunc() and anotherdllfunc(), gSome has the same pointer address
dllFunc(gSome[i]);
}
void anotherdllfunc(int i)
{
for(int i=0; i<10;i++)
exportedDLLfunc(i);
}
/*
MSVC project properties:
Link->Input->Additional Dependencies: someDLL.lib
*/
注意:
*我没有编译错误或类似的东西。
* Windows,Microsoft Visual Studio 2010
* exportedDLLfunc()可以在里面看到someDLL.dll DependencyWalker
我的问题,为什么从exeFunc()调用gSome时,这些值是否包含在内?
注意:
*我没有编译错误或类似的东西。
* Windows,Microsoft Visual Studio 2010
* exportedDLLfunc()可以在someDLL.dll里面看到DependencyWalker
我的问题,为什么从exeFunc()调用时gSome里面的值都不包含?
Notes:
* I get no compiling errors or anything like that.
* Windows, Microsoft Visual Studio 2010
* exportedDLLfunc() can be seen inside someDLL.dll DependencyWalker
My question, why are the values aren''t contained inside gSome when it is called from exeFunc()?
Notes:
* I get no compiling errors or anything like that.
* Windows, Microsoft Visual Studio 2010
* exportedDLLfunc() can be seen inside someDLL.dll DependencyWalker
My question, why are the values aren''t contained inside gSome when it is called from exeFunc()?
推荐答案
dllFunc(gSome[i]);
将按值传递参数,这意味着gSome [i]的整个结构被复制到堆栈中。可能通过const引用将是一种更好的方法。
will transfer the argument by value, which means that the entire structure of gSome[i] is copied to the stack. Probably going by const reference would be a better way.
这篇关于从导出的函数访问时,UNexported全局变量将被初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!