0

I have followed the tutorial here http://msdn.microsoft.com/en-us/library/ms185301.aspx to produce a template project that lets me substitute parameters in my code using a wizard.

This works for all my C# projects for example if I have the following in my template:

using System.Runtime.Serialization;
using $customvariable$Definitions;

namespace $customvariable$Objects
{
    /// <summary>
    /// $customvariable$ Camera
    /// </summary>
    public class $customvariable$Camera
    {
        #region Constructor
        /// <summary>
        /// Instantiates a new instance of the $customvariable$Camera class
        /// </summary>
        public $customvariable$Camera() :
            base()
        {

        }
        #endregion
    }

I can rename my customvariable to anything I want and it gets generated in the resulting project.

BUT If I do the exact same in a visual C++ project the custom variables do not get replaced.

How can I get this to work for C++ code files as well

Harry Boy
  • 4,159
  • 17
  • 71
  • 122

1 Answers1

1

C++ uses a different methodology for replacing template values. Unfortunately, the syntax is not the same as C#. One possible solution (although maybe not the best) is to have two separate template files and use a "language" flag to determine which one to use. Have a look here and here for the differences.

Here's an example of how it looks in C++...

static AFX_EXTENSION_MODULE [!output PROJ_SOURCE]DLL = { NULL, NULL };

#ifdef _MANAGED
#pragma managed(push, off)
#endif

extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
    // Remove this if you use lpReserved
    UNREFERENCED_PARAMETER(lpReserved);

    if (dwReason == DLL_PROCESS_ATTACH)
    {
        TRACE0("[!output PROJ_SOURCE].DLL Initializing!\n");

        // Extension DLL one-time initialization
        if (!AfxInitExtensionModule([!output PROJ_SOURCE]DLL, hInstance))
            return 0;

        // Saves the DLL instance handle for later use with ChangeResCl. 
        resHandle = hInstance;

In the code above, the name of the dll is replaced in two separate locations using "[!output PROJ_SOURCE]".

rrirower
  • 4,338
  • 4
  • 27
  • 45
  • Thanks, I can get the c++ file names to change when I use the method described above but the parameters in the C++ files dont. I looked at the two links but I cannot see any examples where a C++ file has parameters substituted. – Harry Boy Jul 18 '14 at 13:48