Reputation: 11
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;
Upvotes: 1
Views: 3819
Reputation: 1204
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.
Upvotes: 1
Reputation: 400274
You cannot use rundll32 to run any DLL function, you can only use it to run functions that have the following signature:
void CALLBACK
EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
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 call GetPage
.
Upvotes: 4