Can I import a class into ClassWizard in VS2010 - c++

Is there a way in VS2010 to import a class from a .h and .cpp file into ClassWizard such that I can use ClassWizard to manipulate it (e.g. add variables etc...) Quite a number of the files that I brought into the project when I moved over from VS2008 do not seem to be available to ClassWizard. Back in VS6, I could do this by manually editing the CLW file, but this is no longer available. See related question
I'm guessing the file that stores this information is MyProjectName.sdf, which is listed as a SQL Server Compact Edition Database File by explorer, but I'm not sure if there are any tools available that would let me edit it.

Figured a workaround. My hunch was that VS2010 was reading the //{{AFX_DATA(CMyClass) comments when existing files are added into a project, so I did the following;
Edit the files to include a set of AFX... comments copied from
another class
Replace the class name with the correct class
Remove the .h and .cpp files from the project
Add the .h files and .cpp files back to the project
The class is now available to ClassWizard.
A bit too much work to be of much benefit on anything other than regularly used classes, might just put together a routine to do this en-masse, i.e. search for project files with classes based on known MFC classes, search for absence of AFX comments and add them if not present, say ten hail marys and fire up ClassWizard.
Also posted on MSDN here

Related

how can creat MFC extention dll with multi class?

I want to create a MFC extention dll, my problem is the class that I want use in client include some header file that implemented in my project, now how can use it in client?
For example the header file class that want to export from my dll is like below
#include "classme1.h"
#include "classme2.h"
class AFX_EXT_CLASS dllclass
{
...
//anthor function
};
When I include this header file in client, the client project has error and need two file "classme1.h" and "classme2.h".
What I do to solve my problem?
Copy the header files in a common place were both projects can read them.
You can define the path in the #include statement, or you can change the project settings for the C++ pre processor to search the files in different additional directories.
Project settings -> C/C++ -> General -> Additional Include Directories.
For complex projects I very often use the Property Manager. You can define specific settings and add them to your current project. It is just a file that allows you easily to customize projects.
Remember that you also need a reference to the LIB file. It must bes specified in the linker section. Or must be added to the project too. (see tip above).
Alternative to xMRi's suggestion is to refactor your extension DLL to remove the need for a client to include your private header files.
Read about PIMPL Idiom (Pointer to IMPLementation), for example here: Why should the "PIMPL" idiom be used?

How can I use enum written in idl in same project (MFC Control)

I have a MFC control that has an idl file "Test.idl" where I define some enum.
However, if I want to use this enum in the MFC control, I have to include the auto generated header "Testidl.h" that is created by midl.
Ok, but I have a periodic problem. If the autogenerated file "Testidl.h" is not existing, I cannot include that file, thus, cannot compile my control and, thus, cannot create the autogenerated file.
The problem is (I guess), hat the MIDL step is done AFTER C++ build.
Am I correct and can I solve this behaviour somehow?
As long as the IDL file is included in the project's Source Files list the MIDL step should be done first and generate the associated .h file.

Cannot share header files with another project

I wanted to have one project which would contain common header files that could be used by other projects in the same solution (Unfortunately I cannot accomplish this task). In order to accomplish this task here is what I tried
1-Created a new C++ console application called common.
2-From the properties of this project I changed the configuration type to static Library.
3-I added a simple header file commonheader.h to the project having a class person and built it as a result I got
C:\Users\Raj\Documents\Visual Studio 2010\Projects\Ctest\Debug\Common.lib
4-Now in order to use that header file from a different project I created another project
called Test. And in the properties of test I added Common as a reference
5-I then tried to access the person class however the VS2010 still complains that it cannot find the person class.
Any suggestions on what I might be doing wrong ? . I added the path
C:\Users\Raj\Documents\Visual Studio 2010\Projects\Ctest\Debug\ in addition include addition files of the Test project. Any ideas how I can access the person class
AFAIK the .lib files only contains the compiled source of your implementations, you still need to include the header files themselves to get access to the interface

Visual Studio C++ able to compile with compile errors (red underlines)

I am having a problem of getting compile errors (red underlines) like:
Error: cannot open source file "stdafx.h"
Here an edited screenshot of the environment:
On the LEFT is my Visual Studio Solution Directory list with the "Show All Files" off.
I am working on a school project, and each Folder are the source files of different parts of the project with different people who are in-charge of them.
For example, Student A and B are incharge of AST and PARSER folders (we will call them sub-projects).
We have an API for each sub-project so other sub-projects know what to call.
At the TOP-CENTER, we have my Source File for a class QueryProcessor. (just the first few lines)
Below it, is the Output for the Build Success.
The red lines are all over all the classes, mainly cause the #include "stdafx.h" cannot be opened by the environment.
On the RIGHT, that is the stdafx.h where we include all the different sub-projects so we save the trouble of each project having a different stdafx.h
However, I am able to build the project. I am pretty sure I am doing this directory/linking wrongly.
This should work
Right click on the solution file
Click Open in Windows Explorer
Find file stdfx.h in explorer and copy the path of the folder
In visual studio solution explorer, Right click on the project file
Click properties-> C/C++ -> General
In the Additional Include Directories paste the path
Combining folders and virtual folders in VC is from my point of view messy because the virtual folders indicate that all files are in one directory and the folders created on the harddrive obviously indicate that all files are in different directories. You can combine it if you know what's going on but in your case I would not recommend it.
I assume you missunderstand the purpose of stdafx.h The purpose of this header file is NOT to put all header filles into it and then just include it to all other files. Here is a SO question about this Purpose of stdafx.h
After cleaning up your stdafx.h file include as many header files into your .cpp files and only put these includes in your header files if they are required in the header file
Turn on show all files, now you will work with actual folders and you can be sure that if you adress a folder like "PKB" that this folder really exists since you can see it in the left solution explorer.
If you use using namespace std; for example make sure you also include the required header files. You might think "hey I already included e.g. iostream in another header file which I now include in this header file so I don't need it" That will really destroy you when you work with bigger projects.
Oh and regarding the stdafx.h include problem as soon as you switch to show all files I assume you will realise that stdafx is in a different file than the file where you use the include. Maybe something like #include "..\stdafx.h" is required (depending on your structure).
I think it's obivious but if you include a header file the include is allway relative to the file which is including the other header file.
stdafx.h is commonly used for creating a precompiled-header, which essentially is a compile-time optimisation such that the compiler will not continually compile these headers for every compilation unit.
If any of these headers changes, you will need to do a full system rebuild.
In reality it is preferable only to use it to include standard headers plus third-party headers (like boost libraries and similar) that you are not ever going to change.
You may decide that some of your own libraries are "set in stone" and can also be included.
Every project, i.e. every part of the project that is built into a separate unit (DLL or .exe) should have its own precompiled header and its own version of stdafx.h
Projects should only ever include their own .stdafx and not those of other projects, therefore this header file can also be used to define your dllexport macro.
When arranging your project headers you should be aware of:
1. Which headers are included externally
2. Which headers are only included internally, and are not even included indirectly externally.
The latter sort should include your stdafx.h file and should ideally not be in the same directory as those headers included from outside your project.

Managed C++ - ignored Header file

So I’ve got a HEADER(.h) and a SOURCE(.cpp) file in a Managed C++ VS2010 solution.
My solution builds successfully even though I added garbage to the header.
public:
someConstructor(); // assume the syntax is good here
asdf // garbage
Why I did this
My original problem was that I couldn't update my CPP file to add a new constructor. When I added a new constructor to my CPP file, my solution failed to build due to a non-existent overridden member function, i.e. my new constructor. I added garbage to the HEADER file to make sure that VS2010 was actually reading my HEADER file. Obviously it was not.
How can I make sure that VS2010 looks at my HEADER file? It seems to be looking at another HEADER file...
Thanks
If you select the file(s) in question and open up the properties window (View->Properties Window) you can see if your project is looking at the correct file or not. Additionally, if the file is not being included in the build (even though it's in the solution), you can set Include in Project to true.
Note that I'm assuming you're using MSBuild. If you're using some other build system, there may be a different procedure for ensuring the build is using the correct header file.