Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从DLL函数调用非DLL函数_C++_Dll - Fatal编程技术网

C++ 从DLL函数调用非DLL函数

C++ 从DLL函数调用非DLL函数,c++,dll,C++,Dll,我正在编写一个DLL: #include "stdafx.h" _DLLAPI int __stdcall myDLLFunc() { return test(4); } int test(int arg) { return arg * arg; } 但当我尝试在MS VC++Express中编译它时,它会说: 错误C3861:“测试”:找不到标识符 如何从myDLLFunc调用test? 我是否错过了显而易见的事情 提前感谢。在代码中将被调用函数放在调用方之前,它应该

我正在编写一个DLL:

#include "stdafx.h"
_DLLAPI int __stdcall myDLLFunc()  
{  
    return test(4);
}
int test(int arg)
{
    return arg * arg;
}
但当我尝试在MS VC++Express中编译它时,它会说:

错误C3861:“测试”:找不到标识符

如何从
myDLLFunc
调用
test
? 我是否错过了显而易见的事情


提前感谢。

在代码中将被调用函数放在调用方之前,它应该可以编译。C++不为调用函数做“向前看”,必须在任何使用之前声明。
#include "stdafx.h"

int test(int arg)
{
    return arg * arg;
}_DLLAPI int __stdcall myDLLFunc()  

{  
    return test(4);
}

通常,您会将函数的声明(在头文件中)与定义(在代码文件中)分开,以降低依赖关系的复杂性。

在代码中将被调用函数放在调用方之前,它应该编译。C++不为调用函数做“向前看”,必须在任何使用之前声明。
#include "stdafx.h"

int test(int arg)
{
    return arg * arg;
}_DLLAPI int __stdcall myDLLFunc()  

{  
    return test(4);
}

通常,您会将函数的声明(在头文件中)与定义(在代码文件中)分开,以降低依赖关系的复杂性。

或者您可以在myDLLFunc()上方不移动test()而执行test()的前向声明。@Ganesh-谢谢,我添加了一个关于头/代码分离的注释,或者您可以执行test()的前向声明没有将test()移到myDLLFunc()之上。@Ganesh-谢谢,我添加了一个关于头/代码分离的注释