Rundll32.exe 如何运行dll中的函数
生活随笔
收集整理的這篇文章主要介紹了
Rundll32.exe 如何运行dll中的函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.概述
? ? ? ? ?winddows的DLL中的函數是可以直接用Rundll32.exe 運行的。但dll導出函數要符合一定格式。
英文原版本如下:
Rundll32 The Run DLL utility (Rundll32.exe) included in Windows enables you to call functions exported from a 32-bit DLL. These functions must have the following syntax:void CALLBACK EntryPoint(HWND hwnd, // handle to owner windowHINSTANCE hinst, // instance handle for the DLLLPTSTR lpCmdLine, // string the DLL will parseint nCmdShow // show state ); Note that EntryPoint is a placeholder for the actual function name. For a list of possible show states, see WinMain.The following is the command-line syntax for Rundll32:rundll32 DllName,FunctionName [Arguments] DllName Specifies the name of the DLL. The name cannot contain spaces, commas, or quotation marks. The utility searches for the DLL using the search criteria documented for the LoadLibrary function. Therefore, it is best to use the short name and provide a full path for the DLL. FunctionName Specifies the name of the function to call in DllName. Requires a comma (without no spaces) between DllName and FunctionName. Arguments Optional arguments for FunctionName. Rundll32 loads the specified DLL using LoadLibrary, obtains the address of the function using the GetProcAddress function, and calls the function with the specified arguments, if any. When the function returns, Rundll32 unloads the DLL and exits.Windows NT/2000: It is possible to create a Unicode version of the function. Rundll32 first tries to find a function named EntryPointW. If it cannot find this function, it tries EntryPointA, then EntryPoint. To create a DLL that supports ANSI on Windows 95/98/Me and Unicode otherwise, export two functions: EntryPointW and EntryPoint.?
譯文:(網上找的)
Rundll32 這個運行DLL的實用工具(Rundll32.exe)是包含在Windows中的,它能讓你去調用從一個32位DLL中導出的函數。但是那些被調用的函數必須遵循以下語法規則:void CALLBACK EntryPoint(HWND hwnd, // 父窗口的句柄HINSTANCE hinst, // DLL的實例句柄LPTSTR lpCmdLine, // DLL將要解析的字符串int nCmdShow // 顯示狀態 ); 請注意那個EntryPoint僅僅是一個為了表示真實函數名的一個占位符。對于一系列可能的顯示狀態,請參見WinMain。下面是Rundll32在命令行下的語法: rundll32 DllName,FunctionName [Arguments] DllName 指定這個DLL的名字。這個名字不能包含空格,逗號,或引號。這個實用工具為了LoadLibrary這個函數,將會用搜索標準文件記錄的方式來搜索這個DLL。因此,對于這個DLL,最好使用短文件名并且提供一個完整路徑。 FunctionName 指定這個在DllName中被調用的函數的名字。要求在DllName和FunctionName之間有一個逗號(不帶任何空格)。 Arguments 對于FunctionName的可選參數。 Rundll32使用LoadLibrary來載入這個指定的DLL,使用GetProcAddress函數來獲取函數地址,然后帶著這個指定的參數(如果有這個參數的話)去調用函數。當這個函數返回時,Rundll32將卸載這個DLL并退出。Windows NT/2000:為這個函數創建一個Unicode版本是可能的。Rundll32首先嘗試去查找一個命名為EntryPointW的函數。如果無法找到該函數,則會接著嘗試EntryPointA,再然后是EntryPoint。為了創建一個在Windows 95/98/Me上支持ANSI和Unicode的DLL,需要導出兩個函數:EntryPointW和EntryPoint。?
調用方法
在命令行中 ?rundll32.exe projectname.dll,dllfun 即可
?
例子:(網上找的)
// dllmain.cpp : Defines the entry point for the DLL application.#include "stdafx.h" #include <stdio.h> #include "fun.h" extern "C" _declspec(dllexport) void __cdecl dllfun(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow); BOOL APIENTRY DllMain( HMODULE hModule,DWORD ?ul_reason_for_call,LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } extern "C" _declspec(dllexport) void __cdecl dllfun(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow){// MessageBox(NULL,L"lll",L"lllkk",MB_OK); StartWork(NULL);return;}?
總結
以上是生活随笔為你收集整理的Rundll32.exe 如何运行dll中的函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android 本地化翻译插件,解放你的
- 下一篇: 14.Nor-Flash操作实例