1

环境: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;
4

2 回答 2

4

您不能使用 rundll32 运行任何 DLL 函数,只能使用它运行具有以下签名的函数:

  void CALLBACK
  EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);

有关详细信息,请参阅MSDN。要么更改GetPage为使用此函数签名,要么使用该签名创建一个新函数以用作入口点并进行调用GetPage

于 2011-03-16T18:50:29.937 回答
1

我会查看这篇Microsoft 知识库文章。函数的第一个参数是窗口句柄。您需要更改函数原型。

于 2011-03-16T18:50:57.403 回答