Translating C++ project from .exe to .dll? - c++

I have develped my GUI Application in Qt though Qt Creator IDE & MinGW compiler.
I plan to Open source it under the terms of GNU-LGPL.
Now since I had developed all the source code with my GUI Application in my mind, I am having difficulty in modifying the project so as to build a .dll which others can use in their applications. Here are some of my doubts:
Should I maintain a different sets of source files for .exe project & another for .dll project, considering that I will be maintaining my project on GitHub.
Should I delete all the GUI related code from the .dll project? Or it would be fine to just put bool flag's everywhere GUI is created/modified?
Should I delete those functions which were only used in .exe project & will never be called in .dll project? Or should I let them be as it is?
This is my first time at Application development as well as Open Source development. Since I have developed it myself, I dont have proper guidance.
Thank You.

I would separate the program into two projects. Place the GUI stuff in one project which uses a dll created by your other project. That way you only need to maintain one instance of the dll's code. Having duplicate code in any way is usually a bad idea.
(Credit where credit is due: I got this idea from the third comment in this question. It's about C#, but the solution applies to any kind of project.)

Related

Deployment of Qt app when sources change frequently

I'm currently working on a GUI app that is supposed to decrypt some data and print it on the screen, on Windows and Qt (C++) based. The code works fine and I now have to distribute it.
However, the format of the data to decipher can (and will) evolve, and is described on headers (.h) and sources (.c). Therefore, when this happens, I just have to change these files to the last version, the compilation goes fine and the program runs smoothly. It's a simple drag&drop of the new files in my source folder, really.
I am aware of how to deploy a .exe (with the correct dll and so forth), but I don't think it would work in this case. I briefly looked at how to create installers but i'm not sure that this is the right way to handle the situation (http://doc.qt.io/qtinstallerframework/ifw-creating-installers.html).
How could I distribute this code so that people that want to use it can just change the sources, run a script, and the .exe is generated, even with a computer that does not have Qt ? (but probably mingw32 and only on Windows)
Thanks in advance for your help !
From my understanding, you should include dll's and if the format of the data changes, you can just update and maintain your dll's.
Build your project in release mode and then use QTWinDeploy to finalize the build of the project with all the dependencys the projects require for users without QT.
This is how I maintain and distribute a project similar to yours.
Otherwise, I would recommend looking at self-updating programs.

How to add C++ dll project to Visual Basic references?

I am using Visual Studio 2015 Community Edition and I followed Microsoft's tutorial on creating implicit dll's here https://msdn.microsoft.com/en-us/library/ms235636.aspx and I referenced the dll successfully in a C++ console application (I did it just to see if it would work).
When I tried adding the dll project to the references for a Visual Basic Windows Form Application, I got an error saying "A reference to 'DLL Project Name' could not be added." After some research, I think it's because VB targets the .NET framework while the C++ dll targets Windows, but that's all I managed to figure out. I would greatly appreciate any help on reconciling this, or setting up some solution that involves a C++ dll and a GUI project that uses the dll (I just chose VB for the GUI since it's really quick and easy to set up).
Note that both the DLL project and the Visual Basic project are in the same solution.
Your tutorial won't help you invoke the code from .NET and you are correct in assuming it to be a .NET framework inter-op. issue. You can use p-invoke to import and call the DLL or create a COM wrapper around your DLL and register it in the GAC then reference it via a COM CreateObject call.
Other possibilities are to convert it to a C++/CLI .NET C++ DLL.
References:
P-Invoke
COM
-UPDATE-
I suppose I should also mention that if you target Universal Windows Platform (UWP), it also provides a clean binding across .NET and C++ and hides some of the busy COM wire-up.
A C++ DLL should be added to your *.NET application with a post-build event "xcopy" command like this one:
xcopy "$(SolutionDir)DLL\$(ConfigurationName)"\*.dll "$(TargetDir)"*.* /Y
from your selected project go to Project-->Properties-->Compile-->Build Events-->Post-build event command line
Enter the appropriate copy command.
In the above example, several C++ DLLs were collected in a "DLL" folder in the Solutions Directory. They all get copied to the application folder every time the application is built. There were DEBUG and RELEASE versions of those DLLs in separate sub-folders.
As other posters noted, you also must have correct p-invoke declarations for your C++ DLLs in your *.NET code.

EXE from C++, Sqlite dll if any

I am a Java programmer and have come across a very nasty situation. For POC purposes, I need to write down a small segment of my solution that will run as a standalone application doing something very specific.
I have 2 questions:-
I can write the code, but what I don't know is how do I create an installer and exe out of that C++ code.
Secondly, I need to parse a sqlite db file and show its data in the application. Is there a sqlite windows dll or some C++ library or something that I can use, instead of asking the user to install sqlite (or doing it myself through the installer)? So basically, I don't want an extra program to be pushed in, just a dll or some C++ library..
Please let me know if you have an answer to either or both the issues that I'm facing.
Thanks
Compiling your code will turn it in to an executable. For distribution, you'll want to build it in Release mode. I'm not sure what version of Visual Studio you are using, but you might have a "Setup and Deployment" Project type which will enable you to create an installer. Failing that, you may have to look at InstallShield or a tool like that to ensure that the installer has all necessary files (such as the runtime libraries).
SQLLite is called light for a reason! The source code for it can be incorporated directly in to your project and compiled alongside the rest of the files (see: http://www.sqlite.org/selfcontained.html ). This means no external libraries are necessary to link against, and no extra DLLs need to be redistributed alongside your executable.

what is a project in eclipse?

I've just started working with Eclipse for C++ and I just want to clarify something that I haven't been able to figure out by searching so far. Is a project folder in eclipse only intended to have one program in it? i.e., a what is meant by project is basically a C++ program? And so you're not supposed to store many different programs in one project directory? Am I understanding this correctly?
That is correct, though they are trying to change that:
http://www.eclipse.org/eclipse/development/towards-more-flexible-projects.html
Eclipse requires that the contents of each project be stored in a
single directory on disk. Every file and folder in that directory tree
on disk must belong to the project in the workspace
Project is a project. You could divine you aplication to .dll, .exe, or other stuffs. When you are developing something that could go apart in another solution the you can put apart that piece (.dll for example). When you are developing in Visual Studio you can see that projects are in final a single file that has some own functionality, and the whole program is called solution. Didn't fired up Eclipse for a while, but it goes in the same direction. I can remember that projects in Eclipse were very poor, and meaning of the project was considered with actual language that you use (Java, C/C++, PHP, PYTHON, etc.).
Good definition is that project hold some part of application (if not all of it).

simple GUI addon to existing win console app

I've always been developing simple(console) apps. And even then most problems I had was with starting/porting/CMaking/ libraries to work.
I need to find a gui which is added/used by adding #include "somelibrary.h" to EXISTING c++ project. I've downloaded QT, but it seems I have to create a new QTproject,... and thought alone of including all CUDA,OpenCV,others is making me sick.
I've been experimenting with windows forms (.net?) but there is this managed/unmanaged border with its creepy bugs.
So I'd like to add GUI to existing project (where forms can be designed in completely separate designer).
Do you know any?
Or maybe You'd suggest me different approach?
I suggest you to use CMake and Qt. CMake is better than qmake to manage projects and use additional libraries. Currently Qt is the best multi-platform GUI API.
QT and winforms can be added on to an existing project but it's harder that taking a gui application and adding your project to it. Event driven code is organized differently than procedural code.
You don't need CUDA or OpenCV for a GUI.