The Win32 Rundll and Rundll32 Interface Related Topics
The Win32 Rundll and Rundll32 Interface Related Topics
Microsoft Knowledge Base Article Q164787
Applies to: Windows95, Windows 98, Windows NT4
Summary
Win32 contains two command-line utility programs named Rundll.exe and Rundll32.exe that allow you to invoke a function exported from a DLL, either 16-bit or 32-bit. However, Rundll and Rundll32 programs do not allow you to call any exported function from any DLL. For example, you can not use these utility programs to call the Win32 API (Application Programming Interface) calls exported from the system DLLs. The programs only allow you to call functions from a DLL that are explicitly written to be called by them. This article provides more details on the use of Rundll and Rundll32 programs under Windows NT and Windows 95/98. The Rundll and Rundll32 utility programs were originally designed only for internal use at Microsoft. But the functionality provided by them is sufficiently generic that they are now available for general use. Note that Windows NT 4.0 ships only with the Rundll32 utility program and supports only Rundll32.
More Information
Rundll vs. Rundll32
Rundll loads and runs 16-bit DLLs, whereas Rundll32 loads and runs 32-bit DLLs. If you pass the wrong type of DLL to Rundll or Rundll32, it may fail to run without indicating any error messages.
Rundll Command Line
The command line for Rundll is as follows:
RUNDLL.EXE <dllname>,<entrypoint> <optional arguments>
An example is as follows:
RUNDLL.EXE SETUPX.DLL,InstallHinfSection 132 C:.INF
There are 3 issues to consider carefully in the above command line:
Rundll or Rundll32 search for the given DLL filename in the standard places (see the documentation for the LoadLibrary() function for details). It is recommended that you provide a full path to the DLL to ensure that the correct one is found. For best results, use the short file name instead of the long file name to ensure that no illegal characters will appear. Note in particular that this means a DLL in the "C:Files" folder should be converted to its short name.
The may not contain any spaces or commas or quotation marks. This is a limitation in the Rundll command line parser.
In the above command line, the comma (,) between the <dllname> and the <entrypoint> function name is extremely important. If the comma separator is missing, Rundll or Rundll32 will fail without indicating any errors. In addition, there cannot be any white spaces in between the <dllname>, the comma, and the <entrypoint> function.
How Rundll Works
Rundll performs the following steps:
It parses the command line.
It loads the specified DLL via LoadLibrary().
It obtains the address of the <entrypoint> function via GetProcAddress().
It calls the <entrypoint> function, passing the command line tail which is the <optional arguments>.
When the <entrypoint> function returns, Rundll.exe unloads the DLL and exits.
How to Write Your DLL
In your DLL, write the function with the following prototype:
16-bit DLL:
void FAR PASCAL __loadds
EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
32-bit DLL:
void CALLBACK
EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
Again, there are 3 issues to consider with the EntryPoint function:
Obviously, the name "EntryPoint" should be replaced with the actual name of your entry point function. Note that the Rundll32's entry point is completely unrelated to the DllEntryPoint function in a 32-bit DLL which handles process and thread attach/detach notifications.
The entry point function for Rundll32 must be defined with the _stdcall calling convention (CALLBACK defaults to using the _stdcall attribute). If the _stdcall attribute is missing, then the function defaults to _cdecl calling convention and then Rundll32 will terminate abnormally after calling the function.
Since you must declare the function with _stdcall calling convention as described above, it follows that the Visual C++ compiler will actually export it as _EntryPoint@16 if the DLL is written in C or will use further name decoration if the DLL is written in C++. So, be careful to use the correctly exported name in the command line for Rundll or Rundll32. If you want to avoid using decorated names, use a .def file and export the entry point function by name. Please refer to the product documentation and the following article for further information on name decoration when using Visual C++ compilers:
ARTICLE ID: Q140485
TITLE : Exporting PASCAL-Like Symbols in 32-bit DLLs
The parameters to the Rundll entry point are as follows:
hwnd - window handle that should be used as the owner window for any windows your DLL creates
hinst - your DLL's instance handle
lpszCmdLine - ASCIIZ command line your DLL should parse
nCmdShow - describes how your DLL's windows should be displayed.
In the following example:
RUNDLL.EXE SETUPX.DLL,InstallHinfSection 132 C:.INF
Rundll would call the InstallHinfSection() entrypoint function in Setupx.dll and pass it the following parameters:
hwnd = (parent window handle)
hinst = HINSTANCE of SETUPX.DLL
lpszCmdLine = "132 C:.INF"
nCmdShow = (whatever the nCmdShow was passed to CreateProcess)
Note that it is the function (or InstallHinfSection() in the above example) that has to parse its own command line (the lpszCmdLine parameter above) and use the individual parameters as necessary. Rundll.exe parses only up to the optional arguments passed to its command line. The rest of the parsing is up to the function.
Special Notes On Differences Between Windows 95 And Windows NT
On Windows NT, the behavior of Rundll32.exe is slightly different, in order to accommodate UNICODE command lines.
Windows NT first attempts to GetProcAddress for <EntryPoint>W. If this entry point is found, then the prototype is assumed to be:
void CALLBACK
EntryPointW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow);
This is the same as the ANSI EntryPoint, except that the lpszCmdLine parameter is now a UNICODE string.
If the <EntryPoint>W entry point is not found, then Windows NT will GetProcAddress for <entrypoint>A and for <entrypoint>. If either is found, then it is considered an ANSI entry point and is treated the same way as Windows 95. Therefore, if you want your DLL to run on Windows 95 with ANSI support and on Windows NT with UNICODE support, you should export two functions: EntryPointW and EntryPoint. On Windows NT, the EntryPointW function will be called with a UNICODE command line; on Windows 95, the EntryPoint function will be called with an ANSI Command line.
The Win32 Rundll and Rundll32 Interface Related Topics的更多相关文章
- Microsoft Win32 to Microsoft .NET Framework API Map
Microsoft Win32 to Microsoft .NET Framework API Map .NET Development (General) Technical Articles ...
- Win32 多线程的创建方法和基本使用
Win32多线程的创建方法主要有: (1)CreateThread() (2)_beginthread()&&_beginthreadex() (3)AfxBeginThread() ...
- DLL Dynamic-Link Library Search Order
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx A system can contain ...
- 命令安装VS
Installing Visual Studio Visual Studio 2015 Other Versions Visual Studio 2013 Visual Studio 2010 ...
- Optimizing Performance: Data Binding(zz)
Optimizing Performance: Data Binding .NET Framework 4.5 Other Versions Windows Presentation Founda ...
- (转) Deep Reinforcement Learning: Playing a Racing Game
Byte Tank Posts Archive Deep Reinforcement Learning: Playing a Racing Game OCT 6TH, 2016 Agent playi ...
- [ZZ] cbuffer和tbuffer
http://blog.chinaunix.net/uid-20235103-id-2578297.html Shader Model 4支持的新东西,通过打包数据可以获得更好的性能.原文转发:Sha ...
- 【转】 Build a RESTful Web service using Jersey and Apache Tomcat 2009
Build a RESTful Web service using Jersey and Apache Tomcat Yi Ming Huang with Dong Fei Wu, Qing GuoP ...
- debugging books
https://blogs.msdn.microsoft.com/debuggingtoolbox/2007/06/08/recommended-books-how-to-acquire-or-imp ...
随机推荐
- IPsec学习笔记
IPsec是什么 IPsec(IP Security)是一系列为IP通信提供安全性的协议和服务的集合,工作在IP层,可以为上层协议和应用提供透明的安全服务.IPsec提供两种安全机制:认证和加密. 认 ...
- poj1273
赤裸裸的最大流 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstr ...
- 0行代码实现任意形状图片展示--android-anyshape
前言 在Android开发中, 我们经常会遇到一些场景, 需要以一些特殊的形状显示图片, 比如圆角矩形.圆形等等.关于如何绘制这类形状, 网上已经有很多的方案,比如自定义控件重写onDraw方法, 通 ...
- mysql添加事件
begin declare debug int; set @debug = 0; if @debug = 1 then insert into task_monitor(info) values('s ...
- Sqlserver在现有数据库中插入数据
需求:1.客户提供的excel表和数据库中的表结构总是有一些差距,id的生成,各种字段的关联等等 2. 如何在Excel中生成Guid. 1.在Excel的宏中执行以下代码: Private Decl ...
- .NetCore Linux环境下安装InfluxDB以及配置设置
Linux下安装 确定需要安装的版本,我的linux是干净的,所以我需要先安装wget yum -y install wget 下载安装 wget https://dl.influxdata.com/ ...
- Taints和Tolerations联用,将pod部署到k8s的master节点
一般,k8s的master为了保持高性能,在这个主节点上只运行一些管理必须的POD. 如果我们限于资源,或是一些监控类的pod要部署到master节点呢? 昨天遇到这个问题,按网上通用的方法,未解决, ...
- [转] 对vuex的表象理解(笔记)
一个东西,首先要知道为什么用它,为什么要vuex,官方解释为了解决繁杂事件订阅和广播,那么事件的$dispatch,$on,怎么就复杂了?许多人是不是感觉后者还挺简单的,对的 如果简单小型项目,那么不 ...
- Marriage is Stable HDU1522 稳定婚姻问题基础
几对男女 给出每个人心中的优先级 进行最合理的匹配 要打印名字的话必须有一个名字数组 英文名用map 稳定婚姻问题: 每次循环遍历所有的男的 每个男的对目前未被拒绝的并且优先级最高的进行预匹配 ...
- SpringBoot详细研究-03系统集成
据说杰克船长被黑客盗片了,看来信息安全依然任重而道远,本文以此为引子,来介绍下spring boot对于系统集成方面的支持. Spring Security提供一套安全框架,通过IOC和AOP来实现安 ...