Adding ATL Simple Object to MFC project - mfc

I created a new MFC project and tried to add ATL Simple Object. VS give an error "the project need to add ATL support"
So I tried:
1 - add ATL Support, as it is, and got "framework already exists", because there is one framework.h in the MFC project;
2 - Add ATL Support with the name framework2. I copied the content of framework2.h to framework.h;
3 - I create a new MFC project, changed the name of framework.h to framework2.h and added ATL Support has framework. Then copied the content of original framework to the new.
No meter what, keep receiving "the project need to add ATL support" message when I try to add ATL Simple Object. Do I need to do something else to add ATL support?
I already create a COM port using an ATL project, but I need to make it using a MFC project to give support to an old MFC program.
I'm using Visual Studio 2019 Community. Already checked the installed packages and didn't find any missing.
installed packages

Related

How to add .ui file in Visual Studio (2010) project and compile it

I'm new in using Qt and I have a problem. I have created a simple window (.ui File) with Qt Designer and saved it.
Now I want compile it with Visual Studio 2010 . How can I add an external .ui file into my Visual Studio Project and compile it?
Should I create a new class in the project? If yes, how?
The best option (and probably the only one unless you are using CMake or similar) is to use the official Visual Studio Qt add-in (download from here): it will handle all the pre-processing steps required by some of Qt functionalities (C++ classes moc'ing, UI compilation...). It will also associate Qt files (.ui, .qrc, .ts) to respective editors.
Basically, you create a new Qt project, then create the .ui (you can use the one that comes with the template), create a class that inherits from the respective widget (QWidget, QDialog, QMainWindow) (again, there is one with the default project). From that class you setup the UI (you link the .ui and the C++ class, let's say), create slots and connect them with the UI elements, etc.
For a step-by-step tutorial please take a look at the official manual, specially the getting started section.

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

Visual Studio: can't add ATL class to ATL project?

So, I'm creating an ATL project in visual studio 2008 using the wizard (recommended here - How to create ActiveX DLL in Visual C++ - and elsewhere)
But I can't add any classes to my project. VS returns the following error:
atl classes can only be added to mfc exe and mfc regular dll projects or projects with full atl support
...the latter of which you'd think an atl project would have, right?
Can anyone offer a fix?
(I've tried both ticking and unticking 'Support COM+ 1.0' when creating the project - I'm not quite sure what to do with this option).
Add "new item..." instead of Add "class...". Then you can select one of the ATL options.
Interesting that your link: "How to create ActiveX DLL in Visual C++" doesn't have any information about creating ATL project :)
Anyway: File - New - Project - ATL - ATL Project - Next - Next - Finish. ATL project is ready.
Project - Add Class - ATL - ATL Simple Object - Add - Fill class name - Finish. ATL class is added.
I discovered this thread on msdn and tried all suggested solutions. The only one that worked was identifying 'isAtlProject()' in the javascript and setting it to return true. That got me to the next dialog.
However, having created the class, the 'Add Method' wizard would then silently fail to add all of the required code to the interface, header and cpp files. I made another thread about this. Turns out the reason for the latter bug was that intellisense was manually disabled (see other thread for details) :- to anyone reading this in future with the same problem, if you fix intellisense first maybe you won't have to bodge the javascript? Give it a go at least!
If you did not create project as "ATL Project".
Make sure atlbase.h is included in stdafx.h then
Add .cpp file (any name) to your project with the following code:
// ATLMod.cpp
/* This is all that is needed to satisfy VS full ATL support requirement
when adding ATL items with the wizards.
Just has to be present in the project. Compilation not required.
Can set "Exclude from build" property to Yes.
*/
#include "stdafx.h"
// ATLMod.h : Declaration of copy of DllMain.h
class CATLProject1Module : public ATL::CAtlDllModuleT< CATLProject1Module >
{
public:
} _AtlModule;

Compiling and Running MFC Applications with Visual Studio 2008?

I was wondering if anyone can provide a detailed explanation on how I can compile and execute a C++ MFC application in Visual Studio 2008 given that I already have a .h and .cpp file only.
I couldn't find a decent and up to date explanation anywhere and when I try to create a plain MFC project in VS08 I get a bunch of xxx.h xxxDoc.h xxxView.h files, I try and replace those files with my own .cpp and .h files but i get a ton of errors when I run it.
So just to summarize, how do I compile and run my MFC project's .h and .cpp files in Visual Studio 2008 and create an .exe?
Thanks in advance.
See here: Creating an MFC Application
This tutorial may help you as well: Introduction to MFC Applications
It depends on what you are trying to do, but deleting the files the wizard creates is not a good idea. They are there because you told it to put them there (by selecting MFC-SDI/MDI), so they are necessary for the basic initialization and such.
If you don't need the Doc/View architecture, you can create a Dialog Based application. Or, you can even use an MDI or SDI app, and not use the Doc and the View, but if you want to delete them you'll have to make sure there are no references to them. What you cannot delete is the "MyProject.cpp" (where the CWinApp derived class lays), which does the initialization of the application.
Another option is to create a Console application with MFC support. To do so, you have to select "Win32 console application" in the wizard and then check "Add headers for MFC".