CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Feb 2002
    Posts
    3,788

    How to call a .dll with arguments?

    I have a .dll, say test.dll and i want to call this .dll like:

    test.dll /filename /start address.

    The dll should take the filename and start address as parameters and do something with them inside.

    I mean what the finality should be that the user's Command Prompt should look like in the picture.

    Can this be done?
    Attached Images Attached Images  

  2. #2
    Join Date
    Sep 2003
    Location
    Forever Gone... For Now...
    Posts
    1,515
    About the closest thing that I can think of would be to do something like export a function from your DLL, say "Init". Then you could use RunDll32.exe to call that exported function with the parameters.

    MSDN for RunDll32:
    The Run DLL utility (Rundll32.exe) included in Windows enables you to call functions exported from a 32-bit DLL. These functions must have the following syntax:

    Code:
    void CALLBACK EntryPoint(
      HWND hwnd,        // handle to owner window
      HINSTANCE hinst,  // instance handle for the DLL
      LPTSTR lpCmdLine, // string the DLL will parse
      int nCmdShow      // show state
    );
    Note that EntryPoint is a placeholder for the actual function name. For a list of possible show states, see WinMain.

    The following is the command-line syntax for Rundll32:
    Code:
    rundll32 DllName,FunctionName [Arguments]
    Cool?
    Thought for the day/week/month/year:
    Windows System Error 4006:
    Replication with a nonconfigured partner is not allowed.

  3. #3
    Join Date
    Feb 2002
    Posts
    3,788
    thanks, i will try it.

  4. #4
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: How to call a .dll with arguments?

    Originally posted by myth7676
    I have a .dll, say test.dll and i want to call this .dll like:

    test.dll /filename /start address.
    That's what an exe is for. Why don't you use an exe instead of a DLL? Note that you can export functions from an exe and call them as if the exe was a DLL.

  5. #5
    Join Date
    Oct 2003
    Location
    Romania
    Posts
    127
    Another solution is to re-write the Windows OS in a manner,
    that makes possible to launch a dll

    c:\test.dll /filename /start address

    from command line as you whish.

    Cool?

  6. #6
    Join Date
    Feb 2002
    Posts
    3,788

    Re: Re: How to call a .dll with arguments?

    Note that you can export functions from an exe and call them as if the exe was a DLL.
    Can you show me how can i do that(export functions), please?

  7. #7
    Join Date
    Feb 2002
    Posts
    3,788
    Originally posted by marsh_pottaye
    Another solution is to re-write the Windows OS in a manner,
    that makes possible to launch a dll

    c:\test.dll /filename /start address

    from command line as you whish.

    Cool?
    that's an interesting idea
    ...and after i could build a F16 with your precious help, of course.

  8. #8
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Exactly like from a DLL, that is, either using a .DEF file, or using __declspec(dllexport).

  9. #9
    Join Date
    Sep 2003
    Location
    Forever Gone... For Now...
    Posts
    1,515

    Re: Re: How to call a .dll with arguments?

    Originally posted by gstercken
    That's what an exe is for. Why don't you use an exe instead of a DLL? Note that you can export functions from an exe and call them as if the exe was a DLL.
    I can think of a small handful of reasons why one might wish to do something like this with a DLL, but in general I agree that an EXE would be a better way to go.

    Originally posted by myth7676
    Can you show me how can i do that(export functions), please?
    I believe you would do it the same way you would export a function from a DLL... Via DEF file or _declspec( dllexport )...
    Thought for the day/week/month/year:
    Windows System Error 4006:
    Replication with a nonconfigured partner is not allowed.

  10. #10
    Join Date
    Sep 2003
    Location
    Forever Gone... For Now...
    Posts
    1,515
    Originally posted by marsh_pottaye
    Another solution is to re-write the Windows OS in a manner,
    that makes possible to launch a dll

    c:\test.dll /filename /start address

    from command line as you whish.

    Cool?
    Can you post some source, please?

    Cool?
    Thought for the day/week/month/year:
    Windows System Error 4006:
    Replication with a nonconfigured partner is not allowed.

  11. #11
    Join Date
    Feb 2002
    Posts
    3,788
    Originally posted by gstercken
    Exactly like from a DLL, that is, either using a .DEF file, or using __declspec(dllexport).
    aha, thanks, i'll try it right now.

  12. #12
    Join Date
    Feb 2002
    Posts
    3,788

    Re: Re: Re: How to call a .dll with arguments?

    Originally posted by vicodin451
    I can think of a small handful of reasons why one might wish to do something like this with a DLL, but in general I agree that an EXE would be a better way to go.


    I believe you would do it the same way you would export a function from a DLL... Via DEF file or _declspec( dllexport )...

    Aha, ok, just got it, thanks.

  13. #13
    Join Date
    Oct 2003
    Location
    Romania
    Posts
    127
    Originally posted by myth7676
    I have a .dll, say test.dll and i want to call this .dll like:

    test.dll /filename /start address.

    The dll should take the filename and start address as parameters and do something with them inside.
    Originally posted by myth7676
    that's an interesting idea
    ...and after i could build a F16 with your precious help, of course.
    Originally posted by myth7676
    Aha, ok, just got it, thanks.
    I'm wonderig what you got. Because the conclusion here is as far from your initial wish as F16 key from F1.
    Still consider Windows re-writing.

  14. #14
    Join Date
    Sep 2002
    Posts
    1,747
    You know, marsh, I have this suspicion you might be acting a little sarcastically. Overstating things a bit. Because the way I see it, a couple of choice API interceptions (probably NtCreateProcess to detect for dll and map into a process properly, along with maybe some routines like LdrLoadDll to support their use in a process without an executable), coupled with supplying one's own _CRTDllMain (or whatever you want to call it) which will walk through the processes PEB to get the location of the command-line arguments, and it seems to me you are pretty much there. No need to ever even touch HAL or mess with the PnP manager...
    */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    "It's hard to believe in something you don't understand." -- the sidhi X-files episode

    galathaea: prankster, fablist, magician, liar

  15. #15
    Join Date
    Feb 2002
    Posts
    3,788
    Originally posted by marsh_pottaye
    I'm wonderig what you got. Because the conclusion here is as far from your initial wish as F16 key from F1.
    Still consider Windows re-writing.
    Well, well, well March,

    It seems to me or you're a little bit sarcastic here? Then again maybe it's just my imagination...
    What I got was a very good idea, this is what I've got.
    I had one idea in the start, then people that know better this things changed my mind and now i have a solution that works fine for me. Do you have a problem with that?
    If you do, then make yourself a viable suggestion, instead of just throwing pieces of info from your last neuron alive "Re-write Windows, Re-write Windows...". These things are neither constructive, nor interesting for anyone.
    If you consider that they are, maybe you are in the wrong forum, maybe you want it to sign up for CartoonNetwork and by accident you ended up here...?


    PS: I was thinking about F16 fighter, not at the F16 key.
    ..Now I'm sure that you're in the wrong forum.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured