Converting an exe to DLL - Calling the main functi

2019-08-01 15:37发布

问题:

I am trying to convert an exe to dll and manually call the main function from the DLL in my C++ program.

The main function in the code of this exe (generated from another C++ program) looks like this:

int main(int argc, char* argv[])

Now, in my C++ program, earlier I was passing the command line arguments to this exe as follows:
system(somexe test.txt test1.txt test2.txt);

The int argc and argv array are automatically then passed to the exe program. However, I am not sure as to how I would be passing the above parameters if I have to call this function manually. Do I have to manually generate an array everytime with these parameters, and also manually pass the number of elements in this array?

回答1:

just make a string array and pass to main.int argc mean the string number in the array. argv store the string array. for example: int argc = 3; char *argv[3] = {"argc1","argc2","argc3"}; main(argc,argv);



回答2:

Do you know the function printf? You can do it the same way.

int doit(int n1, ...)
{
    va_list arg_ptr;
    int n = n1;
    va_start(arg_ptr, n1);

    while (n > 0)
    {
         va_arg(arg_ptr, int);
    }

    va_end(arg_ptr);
}