I’m making a library which will perform operations to read a processes memory, and get information from said process.
The problem I have is that to call the functions, I have to pass a lot of the variables every time, even if their values haven’t changed.
For instance, ReadProcessMemory requires me to pass:
- Process Handle
- Memory Address
- Main Module Base Address
- Amount of bytes to read
The only thing that will be changing for each read is the Memory Address, so I don’t really need to pass the rest of the variables every time I call the function (I actually have 3 functions which can be reduced in this way, and may have more shortly).
Could anyone give me a brief explanation as to how I should go about this? Will the variables exist at runtime so I can just call the function and use them directly from the DLL file?
You can use named parameters when calling methods with optional parameters.
Call it like so:
Alternatively you could use overloads:
Yet another option is to use a parameters class like so:
Calling like so:
Using the parameters class is likely your preferred approach. The parameters class can be carried around as you process whatever you’re processing. 🙂 Any changes made to it will not be lost…