Trying to create simple COM library using ATL in Visual Studio 2012.
I do:
New ATL Project
Welcome to the ATL Project Wizard
Next
Application Settings - no change (DLL)
Next
Finish
Got a lot of files:
Trying to understand where to add simple function that can be called by COM user. I found only one place where I can add function using wizard:
But I see that something is missing there regarding parameters selection like in,out,retval.
And I was hoping that after adding new function at least IDL file will be updated too, but this not happened.
What is the way of creating simple COM class using ATL from Visual C++ from VS2012 ?
Add a new class
Fill in fields
After this step SomeObject.h, SomeObject.cpp files will be created and added to your solution, the ISomeObject interface declaration will be added to the .idl file.
Go to Class View (the combination ctrl+shift+C by default), select ISomeObject, add a new method
Fill in fields
After this step the someMethod will be added to .idl file, .h file and .cpp file. All you have to do - is to write an implementation of someMethod in .cpp file.
Related
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?
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.
I am trying to learn to develop C++ code with eclipse. I have create a class in a cpp file. Do I need to create an include file by hand (just copy and paste the header definitions), or is there some fancy eclipse button which can create the header file automatically for me?
As far as I know there is no way to generate a header-file out of the cpp. Instead, by using the other direction, it should be possible to generate a method-stub from the function definition within the header (by selecting function-prototype, MenuBar: "Source" > "Implement Method").
Maybe there are some plugins available that do what you want.
Eclipse CDT allows you to write a prototype in the header file, and automatically add it to the C++ file.
Steps to follow
1.Add function prototype to .h file void funct()
2.Select the function name "funct" (try double clicking)
3.In the toolbar click Source -> Implement Method
4.Wizard it up
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
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