c++ 命令行中的变量值在DLL导出函数中不匹配[重复]

6tqwzwtp  于 2023-05-20  发布在  其他
关注(0)|答案(1)|浏览(82)

此问题已在此处有答案

How to use Rundll32 to execute DLL Function?(1个答案)
7天前关闭
我有这样一个函数的定义:

__declspec(dllexport) int MyFunc(int param1, const char* param2)

whish只将参数写入文件:

WriteLog(std::to_string(param1));
std::string str_param2(param2);
WriteLog(str_param2);

我用这样的命令编译并运行dll:

rundll32 mydll.dll,MyFunc 1 blabla

当我打印我看到的值时:

4457714
MZђ

为什么会这样呢?
如何在param1中传递1?

mbskvtky

mbskvtky1#

解决方案是将函数声明为

__declspec(dllexport) void MyFunc(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)

并获得如下参数:

int param1 = atoi(lpszCmdLine);

相关问题