[英]C++ passing command line arguments to 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;
您不能使用rundll32运行任何DLL函数,而只能使用它运行具有以下签名的函数:
void CALLBACK
EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
有关更多信息,请参见MSDN 。 更改GetPage
以使用此函数签名,或者使用该签名创建一个新函数以用作入口点并调用GetPage
。
我将查看这篇Microsoft知识库文章 。 函数的第一个参数是窗口句柄。 您需要更改函数原型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.