简体   繁体   中英

C++ passing command line arguments to dll

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;

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM