当前位置:网站首页>Call DLL file without source code
Call DLL file without source code
2022-07-28 16:47:00 【Royal shadow time】
When using jni perhaps jna call dll When , If dll If it is encrypted , And there is no source file , either .h Header file and do not know the definition of the method, it is difficult to call directly , Need to pass through c Language generates an intermediate Library , Called in the intermediate Library dll
The first thing you need to do is java Define the method to be called , And compile it into class, And then through javah Generate a .h The header file , Generally as follows
The red part is corresponding to us java Method
Then according to the generated .h Header file writing method body
The content of the method body depends on the business , Here, it is mainly to call the third party dll, And then through c Get the return value after the language call , Then go back through our method , Then we can call in our code
Or through a third party dll Generate lib Call statically in the intermediate Library
- function dumpbin Order to obtain dll List of all exported functions of :
dumpbin /exports C:\yourpath\yourlib.dll
2. establish .def file
Now copy all these function names ( Only name!) And paste it into a new text file . name yourlib.def, And will “EXPORTS” Line on top of it . my yourlib.def The documents are as follows :
EXPORTS
_magic_func
_PG_init
exec_get_datum_type
exec_get_datum_type_info
pg_finfo_plpgsql_call_handler
pg_finfo_plpgsql_inline_handler
pg_finfo_plpgsql_validator
plpgsql_DumpExecTree
plpgsql_HashTableInit
plpgsql_IdentifierLookup
plpgsql_add_initdatums
plpgsql_adddatumNow? , From this definition file , You can create .lib The file . So , We use “lib” command
lib /def:C:\mypath\mylib.def /OUT:C:\mypath\mylib.lib /machine:x86
stay VS Add lib Three methods of Library :
Be careful :
1、 Each method should also copy the corresponding DLL File to the corresponding directory , Or set DLL Directory location , The specific method is :"Properties" -> "Configuration Properties" -> "Debugging", stay "Working Directory" Set up dll That's the way
2、 Whether it's setting DLL Catalog , Or is it Lib Catalog , Or the directory of the header file , There are release Version and debug Version differentiation , The settings for each version are independent , To set separately .
Method 1: Add by setting the project configuration lib library .
A、 Add the header file directory of the project : engineering --- attribute --- Configuration properties ---c/c++--- routine --- Attach include directory : Add the directory where the header files are stored .
B、 Add a file reference to lib Static library path : engineering --- attribute --- Configuration properties --- The linker --- routine --- Additional Library Directory : add lib File storage directory .
C Then add the project reference lib file name : engineering --- attribute --- Configuration properties --- The linker --- Input --- Additional dependency : add lib file name .
This method is complicated , And not intuitive , And you may have to fight against debug Version and release Versions are configured differently , Because the two versions of the libraries we generated may be placed in different directories .
I use vs6.0 Compilation of , Yes c The language is unfamiliar , That's how it works
Method 2: Use compiled statements :
#ifdef _DEBUG
#pragma comment(lib,"..\\debug\\LedCtrlBoard.lib")
#else
#pragma comment(lib,"..\\release\\LedCtrlBoard.lib")
#endifThis method is intuitive , convenient , And can be directly distinguished according to the above Debug Version and Release Different directories of versions . Of course , Through macro , More versions can also be distinguished .
But when specifying a directory , Careless mistakes are easy to make .
Method 3: Add library files directly to the project .
Add like you .h and .cpp file , hold lib Add the file to the project file list .
VC in , Switch to " Solution view ",---> Check to add lib The engineering of --> Click on the right -->" add to "-->" Existing items "--> choice lib file --> determine .
It's that simple , Get it done .
This method is applicable in my project debug Version and Release The same... Is used in all versions lib Library file . This saves you 1 Method to configure the environment , It also eliminates the method 2 The possibility of a statement error .
Then introduce a third party into the intermediate Library lib, Then write the business code
Then compile It's like this
java2dll>cl -I J:\java\jkd1.7_32\include -I J:\java\jkd1.7_32\include\win32 -LD java2dll.cpp Dogskin.lib -Fepasencode.dllThen through the generated dll Go through java call
边栏推荐
- Splash (rendering JS service) introduction installation
- Asp.net large file block upload breakpoint resume demo
- LeetCode-学会对无序链表进行插入排序(详解)
- El input limit can only input the specified number
- Early in the morning, pay Bora SMS to say that you won the "prize"? Dealing with server mining virus - kthreaddi
- The video Number finds the golden key, and Tiktok imitates the latecomers
- Redis source code optimization -- binding core
- HDU1847解题思路
- 队列的介绍与实现(详解)
- Abaqus GUI界面解决中文乱码问题(插件中文乱码也适用)
猜你喜欢

排序5-计数排序

Leetcode daily practice - 160. Cross linked list

FX3开发板 及 原理图

微软:Edge 浏览器已内置磁盘缓存压缩技术,可节省空间占用且不降低系统性能

Ansa secondary development - Introduction to interface development tools

egg(十九):使用egg-redis性能优化,缓存数据提升响应效率

Ansa secondary development - apps and ansa plug-in management

HyperMesh运行脚本文件的几种方法

小程序:获取元素节点信息

HM secondary development - data names and its use
随机推荐
ANSA二次开发 - 界面开发工具介绍
500million users, four years earlier than wechat... This app, which has been in operation for 15 years, will be permanently discontinued
Interesting kotlin 0x09:extensions are resolved statically
Installation of QT learning
Leetcode daily practice - 160. Cross linked list
ANSA二次开发 - Apps和ANSA插件管理
[pointer internal skill cultivation] character pointer + pointer array + array pointer + pointer parameter (I)
Nowcode- learn to delete duplicate elements in the linked list (detailed explanation)
asp.net大文件分块上传断点续传demo
Splash (rendering JS service) introduction installation
Leetcode daily practice - the number of digits in the offer 56 array of the sword finger
Design direction of daily development plan
Each account corresponds to all passwords, and then each password corresponds to all accounts. How to write the brute force cracking code
在vs code上配置Hypermesh二次开发环境
"Wei Lai Cup" 2022 Niuke summer multi school training camp 3 acfhj
How to set ticdc synchronization data to only synchronize the specified library?
PHP image upload
Using pyqt to design gui in ABAQUS
Rosen's QT journey 101 models and views in QT quick
局域网无法访问apache服务器