我有一个.lib,它有一个我想变成DLL的函数。
在项目属性中,我已经做了两件事,1.在C/C++ ->通用->附加目录中:添加了.h文件的路径。2.在链接器->通用->附加依赖项中:添加了.lib文件的路径
然后我制作了一个.h文件
#ifndef _DFUWRAPPER_H_
#define _DFUWRAPPER_H_
#include <windows.h>
#include "DFUEngine.h"
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport) void helloworld(void);
__declspec(dllexport) void InitDLL();
#ifdef __cplusplus
}
#endif
#endif 并制作了.cpp文件
#include "stdafx.h"
#include "stdio.h"
#include "DFUWrapper.h"
#ifdef _MANAGED
#pragma managed(push, off)
#endif
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
#ifdef _MANAGED
#pragma managed(pop)
#endif
void helloworld(void)
{
printf("hello world DFU");
}
DFUEngine* PyDFUEngine()
{
return new DFUEngine();
}
void delDFUEngine(DFUEngine *DFUe)
{
DFUe->~DFUEngine();
}
void PyInitDLL(DFUEngine *DFUe)
{
return DFUe->InitDLL();
}我用函数helloword进行了测试。我可以在DLL中看到这个函数,但看不到InitDLL函数。我怎么才能解决这个问题呢?请帮帮忙
发布于 2014-04-03 21:08:11
在DLL头文件中定义以下内容
#if defined (_MSC_VER)
#if defined (MY_DLL_EXPORTS)
#define MY_EXPORT __declspec(dllexport)
#else
#define MY_EXPORT __declspec(dllimport)
#endif
#else
#define MY_EXPORT
#endif使用该宏声明您的函数
#ifdef __cplusplus
extern "C" {
#endif
MY_EXPORT void helloworld(void);
MY_EXPORT void InitDLL();
#ifdef __cplusplus
}
#endif 在你的.cpp中
MY_EXPORT void helloworld(void)
{
printf("hello world DFU");
}
MY_EXPORT void InitDLL()
{
/// blahblah
}用MY_DLL_EXPORT定义编译你的动态链接库...但要确保它没有定义何时需要导入...
发布于 2014-04-03 21:29:24
我喜欢从DLL using 中导出函数。
这有一个避免名称损坏的额外好处:不仅是C++复杂的损坏,还包括__stdcall和extern "C"函数(例如_myfunc@12)的损坏。
您可能只想为您的DLL添加一个DEF文件,例如:
LIBRARY MYDLL
EXPORTS
InitDLL @1
helloworld @2
... other functions ...https://stackoverflow.com/questions/22838532
复制相似问题