Rundll32.exe原理及使用, 参数传递问题解决方法(可用于批处理中)



Rundll32.exe参数传递问题解决方法


#include <afxwin.h>   
  1.   
  2. extern "C" __declspec(dllexportvoid F1(int num)  
  3. {  
  4.     CString str;  
  5.     str.Format("%d",num);  
  6.     AfxMessageBox(str);  
  7. }  

本人曾经碰到一个问题,就是按照网上搜索到的说明,Rundll32的用法为:

rundll32 DllName,FunctionName [Arguments]

假设以上DLL编译好后得到L_test1.dll,于是,我在命令行下输入:rundll32 L_test1.dll,F1 888

可是,结果却不是我所期望的弹出一个显示内容为888对话框。这是为什么呢?

 

后来本人又试了很久,还认为网上所说的格式是错误的,于是还试了很多种自己乱想的格式,就像破解密码一样,但依然失败,晕!

最后,我想到了MSDN,于是就有了这一篇译文:http://blog.csdn.net/leng_que/archive/2009/10/07/4639073.aspx

 

 

#include <afxwin.h>   
  1.   
  2. extern "C" __declspec(dllexport)   
  3. void F2(  
  4.         HWND hwnd,        // handle to owner window   
  5.         HINSTANCE hinst,  // instance handle for the DLL   
  6.         LPTSTR lpCmdLine, // string the DLL will parse   
  7.         int nCmdShow      // show state   
  8.         )  
  9. {  
  10.     if ( strlen(lpCmdLine) != 0 )  
  11.     {  
  12.         CString num;  
  13.         num = lpCmdLine;  
  14.         AfxMessageBox(num);  
  15.     }  
  16.     else  
  17.     {  
  18.         AfxMessageBox("lpCmdLine is NULL");  
  19.     }  
  20. }  

看了MSDN上的说明,我终于明白了原因,原来导出函数的原型是有要求的,要像上面这样写的DLL才行,假设这个DLL名为L_test2.dll。

 

运行命令:rundll32 L_test2.dll,F2 888

OK!终于成功了!

 

最后还有一点值得一提,我并没有完全按照MSDN上的那样把导出函数的调用方式声明为CALLBACK方式,因为我发现如果完全按照MSDN上的那种函数导出格式是会失败的!


https://support.microsoft.com/en-us/kb/164787

#include <afxwin.h>   
  1.   
  2. extern "C" __declspec(dllexportvoid F1(int num)  
  3. {  
  4.     CString str;  
  5.     str.Format("%d",num);  
  6.     AfxMessageBox(str);  
  7. }  

本人曾经碰到一个问题,就是按照网上搜索到的说明,Rundll32的用法为:

rundll32 DllName,FunctionName [Arguments]

假设以上DLL编译好后得到L_test1.dll,于是,我在命令行下输入:rundll32 L_test1.dll,F1 888

可是,结果却不是我所期望的弹出一个显示内容为888对话框。这是为什么呢?

 

后来本人又试了很久,还认为网上所说的格式是错误的,于是还试了很多种自己乱想的格式,就像破解密码一样,但依然失败,晕!

最后,我想到了MSDN,于是就有了这一篇译文:http://blog.csdn.net/leng_que/archive/2009/10/07/4639073.aspx

 

 

#include <afxwin.h>   
  1.   
  2. extern "C" __declspec(dllexport)   
  3. void F2(  
  4.         HWND hwnd,        // handle to owner window   
  5.         HINSTANCE hinst,  // instance handle for the DLL   
  6.         LPTSTR lpCmdLine, // string the DLL will parse   
  7.         int nCmdShow      // show state   
  8.         )  
  9. {  
  10.     if ( strlen(lpCmdLine) != 0 )  
  11.     {  
  12.         CString num;  
  13.         num = lpCmdLine;  
  14.         AfxMessageBox(num);  
  15.     }  
  16.     else  
  17.     {  
  18.         AfxMessageBox("lpCmdLine is NULL");  
  19.     }  
  20. }  

看了MSDN上的说明,我终于明白了原因,原来导出函数的原型是有要求的,要像上面这样写的DLL才行,假设这个DLL名为L_test2.dll。

 

运行命令:rundll32 L_test2.dll,F2 888

OK!终于成功了!

 

最后还有一点值得一提,我并没有完全按照MSDN上的那样把导出函数的调用方式声明为CALLBACK方式,因为我发现如果完全按照MSDN上的那种函数导出格式是会失败的!





#include <afxwin.h>   
  1.   
  2. extern "C" __declspec(dllexportvoid F1(int num)  
  3. {  
  4.     CString str;  
  5.     str.Format("%d",num);  
  6.     AfxMessageBox(str);  
  7. }  

本人曾经碰到一个问题,就是按照网上搜索到的说明,Rundll32的用法为:

rundll32 DllName,FunctionName [Arguments]

假设以上DLL编译好后得到L_test1.dll,于是,我在命令行下输入:rundll32 L_test1.dll,F1 888

可是,结果却不是我所期望的弹出一个显示内容为888对话框。这是为什么呢?

 

后来本人又试了很久,还认为网上所说的格式是错误的,于是还试了很多种自己乱想的格式,就像破解密码一样,但依然失败,晕!

最后,我想到了MSDN,于是就有了这一篇译文:http://blog.csdn.net/leng_que/archive/2009/10/07/4639073.aspx

 

 

#include <afxwin.h>   
  1.   
  2. extern "C" __declspec(dllexport)   
  3. void F2(  
  4.         HWND hwnd,        // handle to owner window   
  5.         HINSTANCE hinst,  // instance handle for the DLL   
  6.         LPTSTR lpCmdLine, // string the DLL will parse   
  7.         int nCmdShow      // show state   
  8.         )  
  9. {  
  10.     if ( strlen(lpCmdLine) != 0 )  
  11.     {  
  12.         CString num;  
  13.         num = lpCmdLine;  
  14.         AfxMessageBox(num);  
  15.     }  
  16.     else  
  17.     {  
  18.         AfxMessageBox("lpCmdLine is NULL");  
  19.     }  
  20. }  

看了MSDN上的说明,我终于明白了原因,原来导出函数的原型是有要求的,要像上面这样写的DLL才行,假设这个DLL名为L_test2.dll。

 

运行命令:rundll32 L_test2.dll,F2 888

OK!终于成功了!

 

最后还有一点值得一提,我并没有完全按照MSDN上的那样把导出函数的调用方式声明为CALLBACK方式,因为我发现如果完全按照MSDN上的那种函数导出格式是会失败的!




///

///

///

Rundll32.exe原理

#include <afxwin.h>   
  1.   
  2. extern "C" __declspec(dllexportvoid F1(int num)  
  3. {  
  4.     CString str;  
  5.     str.Format("%d",num);  
  6.     AfxMessageBox(str);  
  7. }  

本人曾经碰到一个问题,就是按照网上搜索到的说明,Rundll32的用法为:

rundll32 DllName,FunctionName [Arguments]

假设以上DLL编译好后得到L_test1.dll,于是,我在命令行下输入:rundll32 L_test1.dll,F1 888

可是,结果却不是我所期望的弹出一个显示内容为888对话框。这是为什么呢?

 

后来本人又试了很久,还认为网上所说的格式是错误的,于是还试了很多种自己乱想的格式,就像破解密码一样,但依然失败,晕!

最后,我想到了MSDN,于是就有了这一篇译文:http://blog.csdn.net/leng_que/archive/2009/10/07/4639073.aspx

 

 

#include <afxwin.h>   
  1.   
  2. extern "C" __declspec(dllexport)   
  3. void F2(  
  4.         HWND hwnd,        // handle to owner window   
  5.         HINSTANCE hinst,  // instance handle for the DLL   
  6.         LPTSTR lpCmdLine, // string the DLL will parse   
  7.         int nCmdShow      // show state   
  8.         )  
  9. {  
  10.     if ( strlen(lpCmdLine) != 0 )  
  11.     {  
  12.         CString num;  
  13.         num = lpCmdLine;  
  14.         AfxMessageBox(num);  
  15.     }  
  16.     else  
  17.     {  
  18.         AfxMessageBox("lpCmdLine is NULL");  
  19.     }  
  20. }  

看了MSDN上的说明,我终于明白了原因,原来导出函数的原型是有要求的,要像上面这样写的DLL才行,假设这个DLL名为L_test2.dll。

 

运行命令:rundll32 L_test2.dll,F2 888

OK!终于成功了!

 

最后还有一点值得一提,我并没有完全按照MSDN上的那样把导出函数的调用方式声明为CALLBACK方式,因为我发现如果完全按照MSDN上的那种函数导出格式是会失败的!


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
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 window
  HINSTANCE hinst,  // instance handle for the DLL
  LPTSTR lpCmdLine, // string the DLL will parse
  int 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.


#include <afxwin.h>   
  1.   
  2. extern "C" __declspec(dllexportvoid F1(int num)  
  3. {  
  4.     CString str;  
  5.     str.Format("%d",num);  
  6.     AfxMessageBox(str);  
  7. }  

本人曾经碰到一个问题,就是按照网上搜索到的说明,Rundll32的用法为:

rundll32 DllName,FunctionName [Arguments]

假设以上DLL编译好后得到L_test1.dll,于是,我在命令行下输入:rundll32 L_test1.dll,F1 888

可是,结果却不是我所期望的弹出一个显示内容为888对话框。这是为什么呢?

 

后来本人又试了很久,还认为网上所说的格式是错误的,于是还试了很多种自己乱想的格式,就像破解密码一样,但依然失败,晕!

最后,我想到了MSDN,于是就有了这一篇译文:http://blog.csdn.net/leng_que/archive/2009/10/07/4639073.aspx

 

 

#include <afxwin.h>   
  1.   
  2. extern "C" __declspec(dllexport)   
  3. void F2(  
  4.         HWND hwnd,        // handle to owner window   
  5.         HINSTANCE hinst,  // instance handle for the DLL   
  6.         LPTSTR lpCmdLine, // string the DLL will parse   
  7.         int nCmdShow      // show state   
  8.         )  
  9. {  
  10.     if ( strlen(lpCmdLine) != 0 )  
  11.     {  
  12.         CString num;  
  13.         num = lpCmdLine;  
  14.         AfxMessageBox(num);  
  15.     }  
  16.     else  
  17.     {  
  18.         AfxMessageBox("lpCmdLine is NULL");  
  19.     }  
  20. }  

看了MSDN上的说明,我终于明白了原因,原来导出函数的原型是有要求的,要像上面这样写的DLL才行,假设这个DLL名为L_test2.dll。

 

运行命令:rundll32 L_test2.dll,F2 888

OK!终于成功了!

 

最后还有一点值得一提,我并没有完全按照MSDN上的那样把导出函数的调用方式声明为CALLBACK方式,因为我发现如果完全按照MSDN上的那种函数导出格式是会失败的!

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值