2011-03-16 160 views
1

环境:Windows XP SP3时,Visual C++ 2010 Express中,DLL模板C++通过命令行参数对DLL

我试图命令行参数传递给我的DLL函数

例:“C:\发展> 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

无法使用RUNDLL32运行任何DLL功能,你只能用它来运行具有以下签名功能:

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

更多信息,请参见MSDN。请更改GetPage以使用此功能签名,或创建一个具有该签名的新功能以用作入口点并将该号码拨打GetPage

+0

是否有一个如何实现这个MSDN网站没有任何工作示例的工作示例。先谢谢了! – 2011-03-16 23:48:23