C++将命令行参数传递给 dll

发布于 2024-10-22 19:09:58 字数 999 浏览 3 评论 0原文

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

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

还给你自由 2024-10-29 19:09:58

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

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

请参阅 MSDN 了解更多信息。更改 GetPage 以使用此函数签名,或者使用该签名创建一个新函数以用作入口点并调用 GetPage

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.

爱殇璃 2024-10-29 19:09:58

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文