当前位置:网站首页>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
边栏推荐
- 排序5-计数排序
- Use js direct OSS to store files in Alibaba cloud and solve the limitation of large file upload server
- Learn to use MySQL explain to execute the plan, and SQL performance tuning is no longer difficult
- “蔚来杯“2022牛客暑期多校训练营3 ACFHJ
- MySQL5.7及SQLyogV12安装及使用破解及常用命令
- ANSA二次开发 - 在PyCharm上搭建ANSA/META二次开发环境
- 微软:Edge 浏览器已内置磁盘缓存压缩技术,可节省空间占用且不降低系统性能
- asp.net大文件分块上传断点续传demo
- How to set ticdc synchronization data to only synchronize the specified library?
- Microsoft question 100 - do it every day - question 11
猜你喜欢

学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难

Learn to use MySQL explain to execute the plan, and SQL performance tuning is no longer difficult

有趣的 Kotlin 0x0A:Fun with composition

ANSYS二次开发 - MFC界面调用ADPL文件

Fx3 development board and schematic diagram

LeetCode-学会复杂带随机指针链表的题(详解)

有趣的 Kotlin 0x06:List minus list

Debugging methods of USB products (fx3, ccg3pa)

Introduction and implementation of stack (detailed explanation)

Leetcode learn complex questions with random pointer linked lists (detailed explanation)
随机推荐
ANSA二次开发 - 在PyCharm上搭建ANSA/META二次开发环境
微信公众号获取素材列表
"Wei Lai Cup" 2022 Niuke summer multi school training camp 3 a.ancestor lca+ violence count
PHP图片合成技术
排序4-堆排序与海量TopK问题
Ansa secondary development - apps and ansa plug-in management
PHP计算坐标距离
Asp.net large file block upload breakpoint resume demo
HyperMesh运行脚本文件的几种方法
HM二次开发 - Data Names及其使用
PHP image upload
PHP about problems such as memory overflow timeout caused by large amount of data exporting or traversing data
ANSYS二次开发 - MFC界面调用ADPL文件
Multiple commands produce '... /xxx.app/assets.car' problem
优化Hypermesh脚本性能的几点建议
有趣的 Kotlin 0x06:List minus list
Detailed record of steps to configure web server (many references)
Leetcode learn complex questions with random pointer linked lists (detailed explanation)
排序1-插入排序与希尔排序
[pointer internal skill cultivation] character pointer + pointer array + array pointer + pointer parameter (I)