-2

If I have a project that's primary output is a dll, is there a way to say, convert it to an exe to run? I want my application users to just have to run the file rather then use the dll. I've been wanting to know this for awhile. Sorry if this is a stupid question, still learning c++ :) Any help is appreciated.

  • 2
    You can't "convert" a DLL to an EXE. DLL files don't have an entry point (i.e. a `main()`) because they can't be run, as they are simply a collection of functions. – Reticulated Spline Apr 01 '15 at 02:15
  • You may be able to use `Run32Dll` as the exe wrapper, but you'll need to provide an exported function with the correct signature: http://stackoverflow.com/questions/3207365/how-to-use-rundll32-to-execute-dll-function – MSalters Apr 01 '15 at 08:44

1 Answers1

4

One solution is to create an EXE Project that has just one .cpp file, has just the main function, and calls one of the entry points in the DLL from main. Build the project and you can now run anything from the DLL.

R Sahu
  • 204,454
  • 14
  • 159
  • 270
  • So basically you can reference the dll on an exe? – Queen Hisman III Apr 01 '15 at 02:41
  • @QueenHismanIII, yes, you can. You'll have to add the .lib corresponding to the DLL to the set of libraries used by the linker. When you run the exe, you'll need to make sure that DLL is in the same directory as the exe or it can be found from PATH. – R Sahu Apr 01 '15 at 03:00
  • There's 2 ways of binding to the DLL; you can either use an import library (early binding), or you can use late binding and call `LoadLibrary`, `GetProcAddress` etc. to find the function's addresses by name at runtime – M.M Apr 01 '15 at 03:01
  • @MattMcNabb: There's also a hybrid, delay-loaded DLL's. MSVC can auto-generate the late binding code when you provide the import library. – MSalters Apr 01 '15 at 08:45