Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8375217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:07:06+00:00 2026-06-09T15:07:06+00:00

Windows has an utility called rundll32.exe that can execute native dynamic link libraries as

  • 0

Windows has an utility called rundll32.exe that can execute native dynamic link libraries as applications.

Say I have a piece of code that prints “Hello World!” to the console. Is it possible to write a library in C++ (preferably Visual C++) that can be executed using rundll32.exe and will run this code? If so, how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:07:07+00:00Added an answer on June 9, 2026 at 3:07 pm

    Googling “rundll32”, the 3rd hit was a link to documentation,

    http://support.microsoft.com/kb/164787

    According to that documentation, rundll32 calls a user-specified function with signature like wWinMain (except the first argument here is a window handle instead of an instance handle),

    void CALLBACK
    EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
    

    So, trying this out:

    // File [foo.def]
    EXPORTS
        sayHello
    
    // File [foo.cpp]
    #include <iostream>
    
    namespace myCode {
    
        void sayHello()
        {
            using namespace std;
            cout << "Hello, world!" << endl;
        }
    
    }    // namespace myCode
    
    #undef UNICODE
    #define UNICODE
    #include <windows.h>
    
    extern "C" 
    __declspec( dllexport )
    void CALLBACK sayHello( HWND, HINSTANCE, wchar_t const*, int )
    {
        AllocConsole();
        freopen( "CONIN$", "r", stdin ); 
        freopen( "CONOUT$", "w", stdout ); 
        freopen( "CONOUT$", "w", stderr ); 
    
        DWORD const infoBoxOptions = MB_ICONINFORMATION | MB_SETFOREGROUND;
        MessageBox( 0, L"Before call...", L"DLL message:", infoBoxOptions );
        myCode::sayHello();
        MessageBox( 0, L"After call...", L"DLL message:", infoBoxOptions );
    }
    

    Building & running:

    [d:\dev\test]
    > cl foo.cpp foo.def user32.lib /MD /LD /D _CRT_SECURE_NO_WARNINGS
    foo.cpp
       Creating library foo.lib and object foo.exp
    
    [d:\dev\test]
    > rundll32 foo.dll,sayHello
    
    [d:\dev\test]
    > _
    

    The output is presented in its own console window, created via AllocConsole, which is generally necessary since rundll32 is a GUI subsystem program (this is also the reason for the freopen calls).

    To present the output in an existing console window one can just omit the calls to AllocConsole and freopen, and redirect standard output of rundll32 to a pipe. E.g. standard output can be piped through Windows’ more when the output is just a few lines, or through some *nix-utility cat for more lines. However, in the standard command interpreter [cmd.exe] it doesn’t work to just redirect the output to con.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the tigris website http://subversion.tigris.org/getting.html#windows has a link to another svn server, which is called
I want to create applications in windows that has complete portability (within windows OSes
I am trying to access a webservice that has Windows authentication . I am
I'm developing a small utility application that needs to detect whether another one has
I have a small utility app written in Visual Basic 6 that has been
Visual Studio registry capture utility has stopped working.... http://easycaptures.com/fs/uploaded/256/9376236710.png Windows 7 Shows build error
Windows has a Performance Counters infrastructure. The OS provides some common counters, and I
Windows 7 has a very nifty way of showing Contributing Artist metadata in Windows
My Windows account has administrator rights on a local SQL Instance. I am able
My Windows driver has a .sys file and a .dll (which I'm guessing is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.