0

I have a Qt/VisualStudio application which should start from a removable device without installation. I want to place in the root directory only the executable and all the required DLLs in in a directory "data".

The executable should load the DLLs from "data", but no path to "data" should be set before. The DLL search-path should be hard coded in the exe and it should be (only) ".\data"

Is it possible? I'm using VS2008. I've read the documantation on each linker-parameter, but have not identified a proper yet.

Valentin H
  • 7,240
  • 12
  • 61
  • 111
  • 2
    Can't a launcher help you? – mvidelgauz Aug 15 '16 at 17:17
  • 1
    I think manifest files can do this (am not sure): https://msdn.microsoft.com/en-us/library/aa375365(v=vs.85).aspx – Richard Critten Aug 15 '16 at 17:20
  • 2
    Link everything as [/delayload](https://msdn.microsoft.com/en-us/library/hf3f62bz(v=vs.90).aspx) and have the [helper function](https://msdn.microsoft.com/en-us/library/09t6x5ds(v=vs.90).aspx) `LoadLibrary` the DLLs from the "data" directory. – dxiv Aug 15 '16 at 17:29
  • 3
    You want to put *code* in a directory named "data"?? Bit of a toss up whose going to hate that more, your client's IT staff is the one you shouldn't ignore. But you'll surely hate writing the manifest first. – Hans Passant Aug 15 '16 at 17:33
  • @Hans Passant: DLLs can be data files. That's the whole point of options like `LOAD_LIBRARY_AS_DATAFILE`. – Adrian McCarthy Aug 15 '16 at 19:59
  • @mvidelgauz Currently I do it with a launcher written in c# - a simple application without a console and a window which sets the path and starts my main application. Unfortunatelly, on Windows 10 the .NET seems to be missing. And I don't know how to write a launcher without Qt or C# which won't shot the DOS-console – Valentin H Aug 16 '16 at 12:27
  • 1
    I see you have very good C++ knowledge. Writing a simple app with native Win32 API (using VS, free version if you don't have a paid one) in plain C that will serve as launcher will take ~15 minutes.... (Yes I paid attention to _"which won't shot DOS console"_) – mvidelgauz Aug 16 '16 at 12:34
  • @mvidelgauz: good Idea, I'll go for that. Seems to be more straight forward than modifying manifest. Hopefully it's also easy to assign a custom icon to the application. Thank you! – Valentin H Aug 17 '16 at 13:40

1 Answers1

0

As mvidelgauz suggested, I've implemented a launcher using winapi. It was my first native winapi project, but it took indeed only halh an hour to implement.

  1. I created a default Win32 project in VS2008.

  2. In BOOL InitInstance(HINSTANCE hInstance, int nCmdShow), removed the lines:

    //ShowWindow(hWnd, nCmdShow);
    //UpdateWindow(hWnd);
    
  3. And then instead of them, I added:

    SetCurrentDirectory( L"MyPath" );
    ShellExecute(hWnd, NULL, L"MyApp.exe", L"-l", NULL, SW_HIDE);
    DestroyWindow(hWnd);
    
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Valentin H
  • 7,240
  • 12
  • 61
  • 111
  • 1
    You don't need (and in fact, shouldn't use) the window. Delete all of the code that registers a window class, creates a window, and so on. All you need is literally the `wWinMain` function with two function calls: `SetCurrentDirectory` and `ShellExecute`. The `hWnd` parameter for `ShellExecute` can (and in this case, *should*) be `NULL`, meaning that the operation is not associated with a window. – Cody Gray - on strike Sep 04 '16 at 15:22
  • Thanks! Will try it. – Valentin H Sep 04 '16 at 15:56