-2

I have a such difinition of a function:

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

whish is only writing parameters into file:

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

I compile and run dll with such command:

rundll32 mydll.dll,MyFunc 1 blabla

When I print the values I see:

4457714
MZђ

Why is that so?

How to pass a 1 inside of param1?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
xrails
  • 1
  • 1

1 Answers1

0

The solution was to declare function as

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

And get parameters like so:

int param1 = atoi(lpszCmdLine);
xrails
  • 1
  • 1
  • 1
    Please note that `std::atoi` have its problems. First of all there's no validation at all. There's no way to differ between the input `"0"` and the input `"foo"`. If you want validation and error handling use `std::stoi` instead. Secondly, you can't use it if you want to pass multiple arguments, then you need to explicitly parse the string. – Some programmer dude May 12 '23 at 02:41