Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.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_C++_Visual Studio_Dll_Coding Style - Fatal编程技术网

C++ 正确编写DLL

C++ 正确编写DLL,c++,visual-studio,dll,coding-style,C++,Visual Studio,Dll,Coding Style,我仍然不能完全确定如何在VisualStudio中正确编写DLL 文件.h #ifndef UPLOAD_H_ # define UPLOAD_H_ # ifdef UPLOAD_EXPORT # define UPLOAD_API __declspec(dllimport) # else # define UPLOAD_API __declspec(dllexport) # endif // UPLOAD_EXPORT #include <Windows.h> #inclu

我仍然不能完全确定如何在VisualStudio中正确编写DLL

文件.h

#ifndef UPLOAD_H_
# define UPLOAD_H_

# ifdef UPLOAD_EXPORT
#  define UPLOAD_API __declspec(dllimport)
# else
#  define UPLOAD_API __declspec(dllexport)
# endif // UPLOAD_EXPORT

#include <Windows.h>
#include <WinInet.h>

extern "C" UPLOAD_API int uploadFTP(
    const char *...,
    const char *...,
    const char *...,
    const char *...,
    const char *...,
    const char *...);

#endif // UPLOAD_H_
这实际上是可行的,但在MSDN上可以在.h文件中写入:

#ifdef MATHFUNCSDLL_EXPORTS
#define MATHFUNCSDLL_API __declspec(dllexport) 
#else
#define MATHFUNCSDLL_API __declspec(dllimport) 
#endif
这实际上与我所做的相反,它们没有在.cpp文件的函数上指定MATHFUNCSDLL_API

编辑:

解决方案->上载\u导出未在项目属性/C++/预处理器下正确定义MSDN的.h文件中的
\define
语句是正确的。您在构建DLL时定义了
UPLOAD\u EXPORTS
,因此所有UPLOAD\u API函数都将声明为
dllexport
。您不会在其他任何地方定义它,因此所有客户端都会将它们视为
dllimport


<>强> ps:你可能想声明你的函数<代码> WiAPI > /Cord>(如果你想用C语言和C++语言之外的话,它就意味着<代码>但是请注意,使用
dllexport
而不是.def文件导出带有特定于调用约定的修饰(前导下划线等)的函数名。

您对它们如何在MSDN上定义函数有何看法@Medinoc“您不在其他任何地方定义它…”-那么.def文件呢?它是多余的吗?我不确定在声明和定义中指定MYDLL_API是否重要。但我认为这两种方法都没有坏处,而且可读性更高。@fiscblog.def文件是一种不使用u declspec导出函数的替代方法。不适用于(我所知)的C++类,但在用于导出C函数时更容易使用DLL。检查您是否重建了所有的,并且在整个DLL项目的项目选项中定义了AppAddiaAPI。
#ifdef MATHFUNCSDLL_EXPORTS
#define MATHFUNCSDLL_API __declspec(dllexport) 
#else
#define MATHFUNCSDLL_API __declspec(dllimport) 
#endif