将EXE文件转化为DLL文件的方法比较简单,只需要使用Visual Studio等开发工具,将EXE文件的代码和数据封装成一个DLL文件即可。具体操作如下:

第一种:

  • 1)在Visual Studio中创建一个新的DLL项目。
  • 2)将EXE文件中的代码和数据复制到DLL项目中,在本地目录中将源码文件夹拷至dll项目中。
  • 3)修改DLL项目的代码,将其中与EXE文件相关的部分进行调整。__declspec(dllexport)、头文件声明、无效参数删除等
  • 4)编译DLL项目,生成目标格式的DLL文件。

1)在Visual Studio中创建一个新的DLL项目。

文件->新建->项目

dll转为python dll文件怎么转化为mp4_Visual

选择visual c++->控制台应用程序->确认

dll转为python dll文件怎么转化为mp4_Visual_02

下一步

dll转为python dll文件怎么转化为mp4_dll转为python_03

DLL->附加项去除->完成

dll转为python dll文件怎么转化为mp4_c++_04

2)将EXE文件中的代码和数据复制到DLL项目中,在本地目录中将源码文件夹拷至dll项目中。

右击->在文件资源管理器中打开文件夹

dll转为python dll文件怎么转化为mp4_头文件_05

选择项目文件夹

dll转为python dll文件怎么转化为mp4_Visual_06

资源文件->添加->现有项

dll转为python dll文件怎么转化为mp4_c++_07

选择刚才添加的项目->将源文件夹选择添加进去

dll转为python dll文件怎么转化为mp4_头文件_08

3)修改DLL项目的代码,将其中与EXE文件相关的部分进行调整。__declspec(dllexport)、头文件声明、无效参数删除等

找到main函数

dll转为python dll文件怎么转化为mp4_dll转为python_09

修改main函数调用名等

dll转为python dll文件怎么转化为mp4_头文件_10

修改为如下图

dll转为python dll文件怎么转化为mp4_dll转为python_11

资源文件右击->添加

dll转为python dll文件怎么转化为mp4_main函数_12

选择头文件 重命名

dll转为python dll文件怎么转化为mp4_头文件_13

Main函数中添加头文件引用

dll转为python dll文件怎么转化为mp4_头文件_14

将下列内容添加至main函数所在文件最末尾

dll转为python dll文件怎么转化为mp4_main函数_15

右击项目->属性

dll转为python dll文件怎么转化为mp4_头文件_16

常规->配置类型->动态库

dll转为python dll文件怎么转化为mp4_dll转为python_17

选择为release

dll转为python dll文件怎么转化为mp4_头文件_18

生成->重新生成解决方案

dll转为python dll文件怎么转化为mp4_头文件_19

完成!

第二种方式:

  1. 将项目属性中生成文件从exe改为dll
  2. 修改项目main函数函数名,并添加__declspec(dllexport)
  3. 将dll项目生成的main复制到原项目中
  4. 编译DLL项目,生成目标格式的DLL文件。

1)将项目属性中生成文件从exe改为dll

前面与第一种一致

dll转为python dll文件怎么转化为mp4_Visual_20

dll转为python dll文件怎么转化为mp4_头文件_21

2)修改项目main函数函数名,并添加__declspec(dllexport)

dll转为python dll文件怎么转化为mp4_头文件_22

项目自带main函数

dll转为python dll文件怎么转化为mp4_main函数_23

修改后的项目main函数

dll转为python dll文件怎么转化为mp4_Visual_24

3)将dll项目生成的main复制到原项目中,添加到最后即可

dll转为python dll文件怎么转化为mp4_c++_25

将属性中的生成改为dll

dll转为python dll文件怎么转化为mp4_头文件_26

dll转为python dll文件怎么转化为mp4_头文件_27

dll转为python dll文件怎么转化为mp4_Visual_28

生成

dll转为python dll文件怎么转化为mp4_main函数_29

完成!