Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 6th, 2006, 02:45 PM
Maya
Guest
 
Posts: n/a
Default Simple compilation?

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;
}

  #2  
Old December 6th, 2006, 02:45 PM
Jim Langston
Guest
 
Posts: n/a
Default Re: Simple compilation?


"Maya" <kfoury@gmail.comwrote in message
news:1165417774.847452.51220@j72g2000cwa.googlegro ups.com...
Quote:
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.


  #3  
Old December 6th, 2006, 02:55 PM
Maya
Guest
 
Posts: n/a
Default Re: Simple compilation?

Thank you, its:

HRESULT RegisterSnapinAsExtension(_TCHAR* szNameString) // NameString
{

Maya.


Jim Langston wrote:
Quote:
"Maya" <kfoury@gmail.comwrote in message
news:1165417774.847452.51220@j72g2000cwa.googlegro ups.com...
Quote:
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.
  #4  
Old December 6th, 2006, 03:05 PM
Jim Langston
Guest
 
Posts: n/a
Default Re: Simple compilation?

Jim Langston wrote:
Quote:
>
Quote:
>"Maya" <kfoury@gmail.comwrote in message
>news:1165417774.847452.51220@j72g2000cwa.googlegr oups.com...
Quote:
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" <kfoury@gmail.comwrote in message
news:1165418049.936511.124740@j44g2000cwa.googlegr oups.com...
Quote:
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


  #5  
Old December 6th, 2006, 03:15 PM
Maya
Guest
 
Posts: n/a
Default Re: Simple compilation?

in Visual Studio 2005 its: error C2448

The thing is i found this code on
http://msdn.microsoft.com/library/de..._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:
Quote:
Quote:
Jim Langston wrote:
Quote:
"Maya" <kfoury@gmail.comwrote in message
news:1165417774.847452.51220@j72g2000cwa.googlegro ups.com...
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" <kfoury@gmail.comwrote in message
news:1165418049.936511.124740@j44g2000cwa.googlegr oups.com...
Quote:
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
  #6  
Old December 6th, 2006, 06:47 PM
Default User
Guest
 
Posts: n/a
Default Re: Simple compilation? - TPA

Maya wrote:
Quote:
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>
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles