Simple compilation?

Discussion in 'C++' started by Maya, Dec 6, 2006.

  1. Maya

    Maya Guest

    I'm trying to get a dll out of compiling the following code but I get
    error:

    "function-style initializer appears to be a function definition"

    Although i dont have C++ experience I thought i would get the dll
    without the need to understand the actual code.

    Any help?

    Thank you,

    Maya.


    #include "stdafx.h"
    #include <wchar.h>
    #include <activeds.h>

    #define MMC_REG_NODETYPES L"software\\microsoft\\mmc\\nodetypes"
    #define MMC_REG_SNAPINS L"software\\microsoft\\mmc\\snapins"

    // MMC Extension subkeys

    #define MMC_REG_EXTENSIONS L"Extensions"
    #define MMC_REG_NAMESPACE L"NameSpace"
    #define MMC_REG_CONTEXTMENU L"ContextMenu"
    #define MMC_REG_TOOLBAR L"ToolBar"
    #define MMC_REG_PROPERTYSHEET L"PropertySheet"
    #define MMC_REG_TASKPAD L"Task"

    // DSADMIN key
    #define MMC_DSADMIN_CLSID L"{E355E538-1C2E-11D0-8C37-00C04FD8FE93}"

    HRESULT GetCOMGUIDStr(LPOLESTR *ppAttributeName,IDirectoryObject *pDO,
    LPOLESTR *ppGUIDString);

    HRESULT RegisterNodeType(LPOLESTR pszSchemaIDGUID);

    HRESULT AddExtensionToNodeType(LPOLESTR pszSchemaIDGUID,
    LPOLESTR pszExtensionType,
    LPOLESTR pszExtensionSnapinCLSID,
    LPOLESTR pszRegValue);

    HRESULT RegisterSnapinAsExtension(_TCHAR* szNameString) // NameString
    {
    LPOLESTR szPath = new OLECHAR[MAX_PATH];
    HRESULT hr = S_OK;
    IADs *pObject = NULL;
    VARIANT var;
    IDirectoryObject *pDO = NULL;
    LPOLESTR pAttributeName = L"schemaIDGUID";
    LPOLESTR pGUIDString = NULL;

    //Convert CLSIDs of our "extension objects" to strings
    LPOLESTR wszCMenuExtCLSID = NULL;
    LPOLESTR wszPropPageExtCLSID = NULL;

    hr = StringFromCLSID(CLSID_CMenuExt, &wszCMenuExtCLSID);
    hr = StringFromCLSID(CLSID_PropPageExt, &wszPropPageExtCLSID);

    wcscpy(szPath, L"LDAP://");
    CoInitialize(NULL);
    //Get rootDSE and the schema container's DN.
    //Bind to current user's domain using current user's
    //security context.
    hr = ADsOpenObject(L"LDAP://rootDSE",
    NULL,
    NULL,
    ADS_SECURE_AUTHENTICATION, //Use Secure Authentication
    IID_IADs,
    (void**)&pObject);

    if (SUCCEEDED(hr))
    {
    hr = pObject->Get(L"schemaNamingContext",&var);
    if (SUCCEEDED(hr))
    {
    wcscat(szPath, L"cn=user,");
    wcscat(szPath, var.bstrVal);
    hr = ADsOpenObject(szPath,
    NULL,
    NULL,
    ADS_SECURE_AUTHENTICATION, //Use Secure
    //Authentication
    IID_IDirectoryObject,
    (void**)&pDO);
    if (SUCCEEDED(hr))
    {
    hr = GetCOMGUIDStr(&pAttributeName,
    pDO,
    &pGUIDString);
    if (SUCCEEDED(hr))
    {
    wprintf(L"schemaIDGUID: %s\n", pGUIDString);
    hr = RegisterNodeType(pGUIDString);
    wprintf(L"hr %x\n", hr);
    // Do twice, once for each extension CLSID
    hr = AddExtensionToNodeType(pGUIDString,
    MMC_REG_CONTEXTMENU,
    wszCMenuExtCLSID, //our context menu
    //extension object's CLSID
    szNameString
    );
    hr = AddExtensionToNodeType(pGUIDString,
    MMC_REG_PROPERTYSHEET,
    wszPropPageExtCLSID, //our prop page
    //extension object's CLSID
    szNameString
    );
    }
    }
    }
    }
    if (pDO)
    pDO->Release();

    VariantClear(&var);

    // Free memory.
    CoTaskMemFree(wszCMenuExtCLSID);
    CoTaskMemFree(wszPropPageExtCLSID);

    // Uninitialize COM
    CoUninitialize();
    return 0;
    }

    HRESULT GetCOMGUIDStr(LPOLESTR *ppAttributeName,IDirectoryObject *pDO,
    LPOLESTR *ppGUIDString)
    {
    HRESULT hr = S_OK;
    PADS_ATTR_INFO pAttributeEntries;
    VARIANT varX;
    DWORD dwAttributesReturned = 0;
    hr = pDO->GetObjectAttributes
    (
    ppAttributeName, // objectGUID
    1, // Only objectGUID
    &pAttributeEntries, // Returned attributes
    &dwAttributesReturned //Number of attributes returned
    );
    if (SUCCEEDED(hr) && dwAttributesReturned>0)
    {
    // This step ensures that the correct type is used
    if (ADSTYPE_OCTET_STRING == pAttributeEntries->dwADsType)
    {
    LPGUID pObjectGUID = (GUID*)(pAttributeEntries->
    pADsValues[0].OctetString.lpValue);
    //OLE str to fit a GUID
    LPOLESTR szDSGUID = new WCHAR [39];
    //Convert GUID to string.
    ::StringFromGUID2(*pObjectGUID, szDSGUID, 39);
    *ppGUIDString = (OLECHAR *)CoTaskMemAlloc
    (sizeof(OLECHAR)*(wcslen(szDSGUID)+1));

    if (*ppGUIDString)
    wcscpy(*ppGUIDString, szDSGUID);
    else
    hr = E_FAIL;
    }

    else
    hr = E_FAIL;

    //Free the memory for the attributes.
    FreeADsMem(pAttributeEntries);
    VariantClear(&varX);
    }
    return hr;
    }

    HRESULT RegisterNodeType(LPOLESTR pszSchemaIDGUID)
    {
    LONG lResult;
    HKEY hKey;
    HKEY hSubKey, hNewKey;
    DWORD dwDisposition;
    LPOLESTR szRegSubKey = new OLECHAR[MAX_PATH];

    // first, open the HKEY_LOCAL_MACHINE
    lResult = RegConnectRegistry(NULL, HKEY_LOCAL_MACHINE, &hKey);
    if (ERROR_SUCCESS == lResult)
    {
    // go to the MMC_REG_NODETYPES subkey
    lResult = RegOpenKey(hKey, MMC_REG_NODETYPES, &hSubKey);
    if (ERROR_SUCCESS == lResult)
    {
    // Create a key for the node type of the class represented
    // by pszSchemaIDGUID
    lResult = RegCreateKeyEx(hSubKey, // handle of an open key
    pszSchemaIDGUID, // addr of subkey name
    0L, // reserved
    NULL,
    REG_OPTION_NON_VOLATILE,
    KEY_ALL_ACCESS,
    NULL,
    &hNewKey,
    &dwDisposition);
    RegCloseKey(hSubKey);
    if (ERROR_SUCCESS == lResult)
    {
    hSubKey = hNewKey;
    // Create an extensions key
    lResult = RegCreateKeyEx(hSubKey,
    MMC_REG_EXTENSIONS,
    0L,
    NULL,
    REG_OPTION_NON_VOLATILE,
    KEY_ALL_ACCESS,
    NULL,
    &hNewKey,
    &dwDisposition);
    // Go to the MMC_REG_SNAPINS subkey
    RegCloseKey(hSubKey);
    // Build the subkey path to the NodeTypes key of
    // dsadmin
    wcscpy(szRegSubKey, MMC_REG_SNAPINS); //Snapins key
    wcscat(szRegSubKey, L"\\");
    wcscat(szRegSubKey, MMC_DSADMIN_CLSID); //CLSID for
    //DSADMIN
    wcscat(szRegSubKey, L"\\NodeTypes");
    lResult = RegOpenKey(hKey, szRegSubKey, &hSubKey);
    if (ERROR_SUCCESS == lResult)
    {
    // Create a key for the node type of the class
    // represented by pszSchemaIDGUID
    lResult = RegCreateKeyEx(
    hSubKey, // handle of an open key
    pszSchemaIDGUID, // address of subkey name
    0L, // reserved
    NULL,
    REG_OPTION_NON_VOLATILE,
    KEY_ALL_ACCESS,
    NULL,
    &hNewKey,
    &dwDisposition);
    RegCloseKey(hSubKey);
    }
    }
    }
    }
    RegCloseKey(hSubKey);
    RegCloseKey(hNewKey);
    RegCloseKey(hKey);
    return lResult;
    }

    HRESULT AddExtensionToNodeType(LPOLESTR pszSchemaIDGUID,
    LPOLESTR pszExtensionType,
    LPOLESTR pszExtensionSnapinCLSID,
    LPOLESTR pszRegValue)
    {
    LONG lResult;
    HKEY hKey;
    HKEY hSubKey, hNewKey;
    DWORD dwDisposition;
    LPOLESTR szRegSubKey = new OLECHAR[MAX_PATH];
    HRESULT hr = S_OK;

    // first, open the HKEY_LOCAL_MACHINE
    lResult = RegConnectRegistry(NULL, HKEY_LOCAL_MACHINE, &hKey);
    if (ERROR_SUCCESS == lResult)
    {
    // Build the subkey path to the NodeType specified by
    // pszSchemaIDGUID
    wcscpy(szRegSubKey, MMC_REG_NODETYPES);
    wcscat(szRegSubKey, L"\\");
    wcscat(szRegSubKey, pszSchemaIDGUID);
    // go to the subkey
    lResult = RegOpenKey(hKey, szRegSubKey, &hSubKey);
    if (ERROR_SUCCESS != lResult)
    {
    // Create the key for the nodetype if it doesn't
    // already exist.
    hr = RegisterNodeType(pszSchemaIDGUID);
    if (ERROR_SUCCESS != lResult)
    return E_FAIL;
    lResult = RegOpenKey(hKey,szRegSubKey, &hSubKey);
    }
    // Create an extensions key if one doesn't already exist
    lResult = RegCreateKeyEx(hSubKey,
    MMC_REG_EXTENSIONS,
    0L,
    NULL,
    REG_OPTION_NON_VOLATILE,
    KEY_ALL_ACCESS,
    NULL,
    &hNewKey,
    &dwDisposition);
    RegCloseKey(hSubKey);
    if (ERROR_SUCCESS == lResult)
    {
    hSubKey = hNewKey;
    // Create an extension type subkey if one doesn't
    // already exist
    lResult = RegCreateKeyEx(hSubKey,
    pszExtensionType,
    0L,
    NULL,
    REG_OPTION_NON_VOLATILE,
    KEY_ALL_ACCESS,
    NULL,
    &hNewKey,
    &dwDisposition);
    RegCloseKey(hSubKey);
    if (ERROR_SUCCESS == lResult)
    {
    hSubKey = hNewKey;
    // Add your snap-in to the
    // extension type key if it hasn't been already.
    lResult = RegSetValueEx(hSubKey,
    pszExtensionSnapinCLSID,
    0L,
    REG_SZ,
    (const BYTE*)pszRegValue,
    (wcslen(pszRegValue)+1)*sizeof(OLECHAR));
    }
    }
    }
    RegCloseKey(hSubKey);
    RegCloseKey(hNewKey);
    RegCloseKey(hKey);
    return lResult;
    }
     
    Maya, Dec 6, 2006
    #1
    1. Advertising

  2. Maya

    Jim Langston Guest

    "Maya" <> wrote in message
    news:...
    > I'm trying to get a dll out of compiling the following code but I get
    > error:
    >
    > "function-style initializer appears to be a function definition"
    >
    > Although i dont have C++ experience I thought i would get the dll
    > without the need to understand the actual code.
    >
    > Any help?
    >
    > Thank you,
    >
    > Maya.
    >

    < tons of code snipped >

    It would help if you gave us the line number the error occured on. In fact,
    you can probably just copy that one line and paste it, as this is a common
    problem.
     
    Jim Langston, Dec 6, 2006
    #2
    1. Advertising

  3. Maya

    Maya Guest

    Thank you, its:

    HRESULT RegisterSnapinAsExtension(_TCHAR* szNameString) // NameString
    {

    Maya.


    Jim Langston wrote:

    > "Maya" <> wrote in message
    > news:...
    > > I'm trying to get a dll out of compiling the following code but I get
    > > error:
    > >
    > > "function-style initializer appears to be a function definition"
    > >
    > > Although i dont have C++ experience I thought i would get the dll
    > > without the need to understand the actual code.
    > >
    > > Any help?
    > >
    > > Thank you,
    > >
    > > Maya.
    > >

    > < tons of code snipped >
    >
    > It would help if you gave us the line number the error occured on. In fact,
    > you can probably just copy that one line and paste it, as this is a common
    > problem.
     
    Maya, Dec 6, 2006
    #3
  4. Maya

    Jim Langston Guest

    > Jim Langston wrote:
    >
    >> "Maya" <> wrote in message
    >> news:...
    >> > I'm trying to get a dll out of compiling the following code but I get
    >> > error:
    >> >
    >> > "function-style initializer appears to be a function definition"
    >> >
    >> > Although i dont have C++ experience I thought i would get the dll
    >> > without the need to understand the actual code.
    >> >
    >> > Any help?
    >> >
    >> > Thank you,
    >> >
    >> > Maya.
    >> >

    >> < tons of code snipped >
    >>
    >> It would help if you gave us the line number the error occured on. In
    >> fact,
    >> you can probably just copy that one line and paste it, as this is a
    >> common
    >> problem.



    "Maya" <> wrote in message
    news:...
    > Thank you, its:
    >
    > HRESULT RegisterSnapinAsExtension(_TCHAR* szNameString) // NameString
    > {
    >
    > Maya.


    Well, that's just strange, because RegisterSnapinAsExtension *is* a function
    definition. What's the error number it provides? I"ll try looking at the
    error number in the IDE and see if it gives any clue what the heck it's
    talking about :D
     
    Jim Langston, Dec 6, 2006
    #4
  5. Maya

    Maya Guest

    in Visual Studio 2005 its: error C2448

    The thing is i found this code on
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mmc/mmc/registering_node_type.asp

    And to be honest i don't know if I'm even compiling it correctly to
    start with. I just stick the code in the main header file in my C++
    project. is this the right way to do get a dll? do i need to compile
    this using a different compiler?

    Thanks,

    Maya.

    Jim Langston wrote:

    > > Jim Langston wrote:
    > >
    > >> "Maya" <> wrote in message
    > >> news:...
    > >> > I'm trying to get a dll out of compiling the following code but I get
    > >> > error:
    > >> >
    > >> > "function-style initializer appears to be a function definition"
    > >> >
    > >> > Although i dont have C++ experience I thought i would get the dll
    > >> > without the need to understand the actual code.
    > >> >
    > >> > Any help?
    > >> >
    > >> > Thank you,
    > >> >
    > >> > Maya.
    > >> >
    > >> < tons of code snipped >
    > >>
    > >> It would help if you gave us the line number the error occured on. In
    > >> fact,
    > >> you can probably just copy that one line and paste it, as this is a
    > >> common
    > >> problem.

    >
    >
    > "Maya" <> wrote in message
    > news:...
    > > Thank you, its:
    > >
    > > HRESULT RegisterSnapinAsExtension(_TCHAR* szNameString) // NameString
    > > {
    > >
    > > Maya.

    >
    > Well, that's just strange, because RegisterSnapinAsExtension *is* a function
    > definition. What's the error number it provides? I"ll try looking at the
    > error number in the IDE and see if it gives any clue what the heck it's
    > talking about :D
     
    Maya, Dec 6, 2006
    #5
  6. Maya

    Default User Guest

    Re: Simple compilation? - TPA

    Maya wrote:

    > in Visual Studio 2005 its: error C2448


    Please don't top-post. Your replies belong following or interspersed
    with properly trimmed quotes. See the majority of other posts in the
    newsgroup, or the group FAQ list:
    <http://www.parashift.com/c++-faq-lite/how-to-post.html>
     
    Default User, Dec 6, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    624
  2. C__chp
    Replies:
    4
    Views:
    542
    Puppet_Sock
    Feb 15, 2008
  3. Ashik

    Simple Compilation question

    Ashik, Jun 12, 2008, in forum: C Programming
    Replies:
    2
    Views:
    278
  4. James
    Replies:
    6
    Views:
    381
    James
    Jun 25, 2008
  5. mathieu

    Simple compilation problem

    mathieu, Dec 23, 2008, in forum: Java
    Replies:
    11
    Views:
    627
Loading...

Share This Page