C++将命令行参数传递给 dll
环境:Windows XP SP3、Visual C++ 2010 Express、DLL 模板
我试图将命令行参数传递给我的 dll 函数
示例:“c:\Development>rundll32, getpage.dll,GetPage http://www.google.ca"
当我传递以下字符串“http://www.google.ca”时,我会得到随机数(假设地址位置?)
#include "stdafx.h"
#include <string.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <urlmon.h>
#include <tchar.h>
#include <fstream>
using namespace std;
extern "C" __declspec(dllexport) LPCWSTR __cdecl GetPage(LPCWSTR URL);
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ){
return TRUE;
}
LPCWSTR GetPage(LPCWSTR URL){
LPCWSTR status;
HRESULT getpage_status = URLDownloadToFile ( NULL,URL, _TEXT("status.log"), 0, NULL );
/*** Do stuff is working if I pass a static string eg URL = "http://www.google.ca"; I need command line args sent to the function instead***/
return status;
Environment: Windows XP SP3, Visual C++ 2010 Express, DLL Template
I am trying to pass command line arguments to my dll function
Example: "c:\Development>rundll32, getpage.dll,GetPage http://www.google.ca"
When I pass the following string "http://www.google.ca" I get random numbers (assuming address location?)
#include "stdafx.h"
#include <string.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <urlmon.h>
#include <tchar.h>
#include <fstream>
using namespace std;
extern "C" __declspec(dllexport) LPCWSTR __cdecl GetPage(LPCWSTR URL);
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ){
return TRUE;
}
LPCWSTR GetPage(LPCWSTR URL){
LPCWSTR status;
HRESULT getpage_status = URLDownloadToFile ( NULL,URL, _TEXT("status.log"), 0, NULL );
/*** Do stuff is working if I pass a static string eg URL = "http://www.google.ca"; I need command line args sent to the function instead***/
return status;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能使用 rundll32 来运行任何 DLL 函数,只能使用它来运行具有以下签名的函数:
请参阅 MSDN 了解更多信息。更改
GetPage
以使用此函数签名,或者使用该签名创建一个新函数以用作入口点并调用GetPage
。You cannot use rundll32 to run any DLL function, you can only use it to run functions that have the following signature:
See MSDN for more info. Either change
GetPage
to use this function signature, or create a new function with that signature to use as an entry point and have that callGetPage
.我会查看这篇Microsoft 知识库文章。函数的第一个参数是窗口句柄。您需要更改您的函数原型。
I would check out this Microsoft Knowledge Base article. The first parameter to your function is a window handle. You'll need to change your function prototype.