I created a dll(in c++) with one method called "changeSize"(in kb) which has the argument "size". So the method basically sets a new size of a file (the file that is stated in the method). Now I want to execute the method of this dll in command prompt.
I've tried to execute the method with the help of "rundll32.exe", so i executed that command in command prompt, but it does not work:
rundll32.exe ChangeSize.dll,changeSize 1024
Question 1: Is it possible to execute a method of a dll with "rundll32.exe" if it needs arguments, or is there a simple way to do it with command prompt or if necessary powershell?
EDIT Now I know that the dll needs to have a special signature, that it is able to be executed with "rundll32.exe".
I have come accross this: https://stackoverflow.com/a/11913860/16104144, which is a short documentation on how to create a dll that can be run with "rundll32.exe".
I have the following code, and when i set the parameter "size" OF MY CODE to any value and build the dll and run it in cmd:
rundll32.exe ChangeSize.dll,EntryPoint
, then it works, but I want to be able to define the size just when i execute the dll with "rundll32.exe" and i don't want to have to define a size before building the dll.
Question 2: Where do i have to add the variable size in my code that "rundll32.exe" knows that the dll needs that argument. The parameter "size" should be "unsigned long int".
So this is my code in the main file(dllmain.cpp):
#include "pch.h"
namespace fs = std::filesystem;
__declspec(dllexport) void CALLBACK EntryPoint(
HWND hwnd,
HINSTANCE hinst,
LPSTR lpszCmdLine,
int nCmdShow
);
void CALLBACK EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
fs::path p = "C:\\Users\\myname\\AppData\\Local\\Temp\\1304.txt";
fs::resize_file(p, size);
int msgboxID = MessageBox(
NULL,
L"Hello World from Run32dll",
L"HelloWorld",
MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2
);
switch (msgboxID)
{
case IDCANCEL:
break;
case IDTRYAGAIN:
break;
case IDCONTINUE:
break;
}
}
Adding the variable to the function and its declaration did not work:
void CALLBACK EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow, unsigned long int size`, unsigned long int size);
As it says here https://learn.microsoft.com/en-us/windows/win32/learnwin32/winmain--the-application-entry-point, the arguments that are passed with this command:
rundll32.exe ChangeSize,changeSize 1024
are saved inside the variable
LPSTR lpszCmdLine
And because it is just one argument I can just replace the variable "size" with (unsigned long int)lpszCmdLine
:
#include "pch.h"
namespace fs = std::filesystem;
__declspec(dllexport) void CALLBACK EntryPoint(
HWND hwnd,
HINSTANCE hinst,
LPSTR lpszCmdLine,
int nCmdShow
);
void CALLBACK EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
fs::path p = "C:\\Users\\myname\\AppData\\Local\\Temp\\1304.txt";
fs::resize_file(p, (unsigned long int)argument;
/*int msgboxID = MessageBox(
NULL,
L"Hello World from Run32dll",
L"HelloWorld",
MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2
);
switch (msgboxID)
{
case IDCANCEL:
break;
case IDTRYAGAIN:
break;
case IDCONTINUE:
break;
}/*
}
___________________________________________________________________________
I have to admit that it's pretty new to me to create *dlls*, but i can not find anything about creating *dlls* with parameters that can be run with "rundll32.exe" and I am very thankful for you even reading this.