Qt: How to create windows DLL (that exports functions)? - c++

I need to create a windows DLL that exports functions and has a graphical user interface. The reason for the GUI in the DLL is that the DLL serves as a kind of plugin for another 3rd party application. Currently I only have access to Visual Studio Express which AFAIK doesn't support MFC so I'm looking for alternative ways to create a GUI in a DLL. After some research I came across Qt which seems promising. And it seems like it might be easier to just use the Qt Creator IDE rather than Visual Studio Express.
However, how do I create a windows DLL in Qt Creator? (I guess a regular DLL, I don't think a COM or managed DLL will work)
UPDATE:
I got this working! After jumping through several hoops, two important keys were to add
#include <windows.h>
And then to use the Qt/MFC Migration Framework tool (currently officially available at: http://qt.gitorious.org/qt-solutions/qt-solutions/trees/master/qtwinmigrate EDIT: I believe this is the new link: https://github.com/qtproject/qt-solutions/tree/master/qtwinmigrate)
I used this example to get me going:
http://doc.qt.nokia.com/solutions/4/qtwinmigrate/winmigrate-qt-dll-example.html
EDIT: I believe this is the new link http://htmlpreview.github.io/?https://github.com/qtproject/qt-solutions/blob/master/qtwinmigrate/doc/html/winmigrate-qt-dll-example.html

Add the folowing line to the .pro file: TEMPLATE = lib
That's just about all you'll have to do to have QtCreator make your 'app' into a dll.

check qt plugins http://cartan.cas.suffolk.edu/qtdocs/plugins-howto.html

Related

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.

How to get ATL support into an existing Windows application

I'm building an application using Qt 5.3.1 in Visual Studio 2012. I also want to use a hardware library which requires me to add a simple ATL object to the project. This can be done by using a Visual Studio wizard. The wizard complains that my project is neither an MFC executable nor an MFC DLL with full ATL support.
My question is: How can I add this support to my application? In the project properties I configured the project to link to the ATL and use the MFC. It did not work. Both statically and dynamically.
If there's another solution in order to add a simple ATL object to the project, please let me know.
The wizard which adds ATL support works on source code of the C++ project, including both checking if the current code is already ATL project, whether the project is okay for adding ATL support to, and code modification per se.
If the wizard "does not like" something in your project it displays an error which basically means that the wizard does know how to safely modify your source code. It does not however mean that adding ATL support is impossible. And enabling an option in project settings is insufficient since source code needs some explicit initialization stuff.
The best you can do to add ATL support without thinking too much about it, is to create a new empty project that matches the project type you currently have, e.g. MFC application. Then take a snapshot of source code, then add ATL support using the wizard. Then compare changes and duplicate them on your real project. The same applies to next step of adding ATL Simple Object using Visual Studio wizard.
Some relevant links (even though the method above looks the easiest to me):
How To Add ATL Support to an MFC EXE
Adding ATL support to existing mfc application
Add automation support to MFC DLL

Static builds with Qt creator

I am using Qt Creator with Qt 4.7.4 in the SDK given out by Nokia and wish to build an application with no .DLLs or other external libraries (just a standalone .exe) for Windows.
How is this done (please give all possible details as I am new to this)? I understand one can build static apps using Qt only (not Qt creator) but I am using Qt creator.
/How-to-statically-link-qt-4/ link here will help you achieve, what you are trying to do.
I am aware that answers in the form of embedded links is usually discouraged for the fact that if the source of the link goes down the answer becomes meaningless but in this case the content is too big & enriched to be reproduced in here again.

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.

Static linking with a Qt project

I've got a Qt project I've built in Visual Studio 2010 Professional. However, when I run it (in either Debug or Release mode) it asks for a few Qt dll's. It works if I supply the dll's and throw them into System32, but my question is, how do I make it so that all libraries are included in the .exe? I have all of the static libraries I need, I just don't know how to make it so that the app doesn't ask the end user for them.
The correct way is to create a setup program that installs the Qt libraries along with your application. Visual Studio comes with a setup project template that you can use to create your own customized installer easily. Static linking is rarely a good option, for numerous reasons.
However, if you insist on static linking, you'll need to recompile the Qt sources with the -static flag.
A walkthrough is available here for Qt 4.
And if you're using the LGPL version of Qt, make sure you've read the answers to this question and appropriate addressed all legal concerns with your deployment.