When I create a new C++ class in visual studio 2010, it generates a class with some template code. How can I modify this template to suit my own needs ?
One problem with finding info about this is most of information about creating templates is for .NET and the process is different for Visual C++. Also the answer is probably not what you want to hear because it involves editing javascript code rather than just editing some template file. It's possible that you can create a brand new wizard that uses a template file, but this is one way to modify the default template without doing that. Modifying the wizard code involves editing a javascript file:
C:\Program Files\Microsoft Visual Studio 10.0\VC\VCWizards\CodeWiz\Generic\Class\Scripts\1033\default.js
The javascript uses the CodeModel to manipulate (or generate, in this case) source code. Inside that file there is an OnFinish function which you can use to modify the class details that are output. You will see a line like this in the file:
var newclass = oCM.AddClass(strClassName,
strHeader, vsCMAddPositionEnd, "", "", vsCMAccessDefault);
to add a new function you would do something like:
newclass.AddFunction("MyFunction", vsCMFunctionFunction,
vsCMTypeRefVoid, vsCMAddPositionEnd, vsCMAccessPublic, strImpl);
You can read about it here:
Inside Visual C++ Wizards
Reference Documentation:
Designing a Wizard
The default templates are in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcprojectitems. Change as appropriate for x86-vs-x64 and VS version.
(If I understand correctly)
I don't think you can modify the code that is auto-generated by a wizard, for example when adding a new class.
You could maybe code a new wizard ?
M.
Checked in MVS 2008...
File: C:\Program Files\Microsoft Visual Studio 9.0\VC\VCWizards\CodeWiz\Generic\Class\Scripts\1033\default.js
Added code (after creating default ctor & dtor in the default.js)
var oCopyCtor = newclass.AddFunction(strClassName+"(const "+strClassName+"& refObj)", vsCMFunctionConstructor, "", vsCMAddPositionEnd, vsCMAccessPrivate, strImpl);
var oAssignmentOperator = newclass.AddFunction("operator=(const "+strClassName+"& rhs)", vsCMFunctionOperator, strClassName+"&", vsCMAddPositionEnd, vsCMAccessPrivate, strImpl);
oAssignmentOperator.BodyText = "if(&rhs == this) { return *this; }\n//TODO: real assignment here...\nreturn *this;\n"
But I still can't figure out how to turn off implementation in *.cpp (x.BodyText = ""; doesn't help), and omitting strImpl parameter puts the implementation in the *.h file
Related
For C++ class can I see the intermediate compilation stage/s? : variable/methods mangling?
some readable representation of generated code for static binding ? vtable?
for students
VS ILDasm is a tool that can decompile code. You could add ILDasm in VS.
Here are the steps:
Select Tools->External Tools->ILDasm
Select the path of ILDasm.exe in Command. The path is generally C:\Program Files\Microsoft SDKs\Windows\vXXX\bin\NETFX 4.0 Tools\ildasm.exe.
Type $(TargetPath) /text/item: in Arguments, then click Apply
I downloaded these 2 codes from GitHub because I want to edit them without having to recompile Point Cloud Library. I have edited the relevant includes so that the new hpp files links to the new h file.
https://github.com/PointCloudLibrary/pcl/blob/master/segmentation/include/pcl/segmentation/supervoxel_clustering.h
https://github.com/PointCloudLibrary/pcl/blob/master/segmentation/include/pcl/segmentation/impl/supervoxel_clustering.hpp
However, I get an error as shown below. It says cend is not a member of a certain class. My question is, why doesn't visual studio underline the errors I get ?
I'd like to configure the VS2015 debugger so that when I'm stepping in into some code (F11), it steps through certain functions .
For example, let's say there is a template class SmartPointer which has an overloaded member -> .
If I have the following statement :
SmartPointer<SomeClass> ptr;
/* initialize ptr */
ptr->method();
The debugger will step into SmartPointer::operator->, exit, then the into method().
I'd like to directly step into method().
Is this possible ?
EDIT : The so called duplicate isn't one because it doesn't work with vs2013 or 2015
Ok I actually found the solution. You have to edit as an administrator:
C:\Program Files (x86)\Microsoft Visual Studio
14.0\Common7\Packages\Debugger\Visualizers\default.natstepfilter
or
C:\Program Files\Microsoft Visual Studio
14.0\Common7\Packages\Debugger\Visualizers\default.natstepfilter
depending if you're under a 64 or 32 bit machine. The add a line like
<Function><Name>SomeFunction</Name><Action>NoStepInto</Action></Function>
HTH
i'm learning about COM through an internet tutorial(http://www.codeguru.com/cpp/com-tech/activex/tutorials/article.php/c5567/Step-by-Step-COM-Tutorial.htm). The first thing is creating a IDL file and compile it to create another 5 files. The detail is after:
Open VS2010
Create Win32 DLL project name AddObj
Add IAdd.idl file with the content
import "unknwn.idl";
[
object,
uuid(1221db62-f3d8-11d4-825d-00104b3646c0),
helpstring("interface IAdd is used for implementing a super-fast addition Algorithm")
]
interface IAdd : IUnknown
{
HRESULT SetFirstNumber(long nX1);
HRESULT SetSecondNumber(long nX2);
HRESULT DoTheAddition([out,retval] long *pBuffer);
};
[
uuid(3ff1aab8-f3d8-11d4-825d-00104b3646c0),
helpstring("Interfaces for Code Guru algorithm implementations .")
]
library CodeGuruMathLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
interface IAdd;
}
After that, follow the tutorial, if i compile IAdd.idl file, it will generate:
--IAdd.h Contains the C++ style interface declarations.
--dlldata.c Contains code for proxy DLL. Useful when invoking the object on a different process/computer.
--IAdd.tlb Binary file , with a well defined format that completely describes our interface IAdd along with all it's methods. This file is to be distributed to all the clients of our COM component.
--IAdd_p.c Contains marshalling code for proxy DLL. Useful while invoking the object on a different process/computer.
--IAdd_i.c Contains the interface IIDs
but when i compile IAdd by right click it and choose compile in shortcut menu, there is no file being generate. But when open view class, i can see IAdd interface with some method.
I also try it by compile it manually by download midl.exe from internet and run in command line but it failed.
I fine a lot of material by google and all said that i can compile idl file by visual studio but i try many time, on my both computer but no file being generate after i compile idl file. I also install new Win7, new visual studio 2010 ultimate but nothing change.
I just created a new project and created a new idl file with the code you specified.If i right click and choose compile it works just fine (VS2010 Ultimate).
Did you choose the correct filetype in the fileproperties of VS?
It should be "IDL File".
Have you used the VS Command Prompt as you tried to compile it manually?
(The VS Command Prompt will set all necessary environment variables)
I'm building a big C++ project on Visual Studio 2008 I'm getting this error message and I don't understand it. Is it a failure to include the .h file?
I know this thread is dated, but I had the exact same problem with a C++ project on Visual Studio 2008, here was my resolution...
One of the things the VS2008 compile told me was that it generated a log on:
"file://C:\Documents and Settings\adam\My Documents\Visual Studio 2008\Projects\MyProject\Debug\BuildLog.htm"
This log demystified the problem for me.
In my case, it had the following explicit error message:
c:\Documents and Settings\adam\My Documents\Visual Studio 2008\Projects\MyProject\MyProject\UnitTests.h(36): Error: Meta object features not supported for nested classes
The problem had been that INSIDE the class I defined here, I defined yet another internal (nested) class, that included the QT macro (so I could define signals and slots):
Q_OBJECT
Obviously QT wasn't happy that this class was nested/internal in another class. So I simply moved the class definition outside (IE made it non-internal).
No, it is not.
Did you look up the error code error PRJ0019.