473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

Dec 6 '06 #1
5 4723

"Maya" <kf****@gmail.comwrote in message
news:11*********************@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.
Dec 6 '06 #2
Thank you, its:

HRESULT RegisterSnapinAsExtension(_TCHAR* szNameString) // NameString
{

Maya.
Jim Langston wrote:
"Maya" <kf****@gmail.comwrote in message
news:11*********************@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.
Dec 6 '06 #3
Jim Langston wrote:
>
>"Maya" <kf****@gmail.comwrote in message
news:11*********************@j72g2000cwa.googlegr oups.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" <kf****@gmail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
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
Dec 6 '06 #4
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:
Jim Langston wrote:
"Maya" <kf****@gmail.comwrote in message
news:11*********************@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" <kf****@gmail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
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
Dec 6 '06 #5
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>
Dec 6 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lili | last post by:
I'm having problems creating a simple stored procedure in DB2. Can someone help? Here is the screen dump when I tried to load the stored procedure. Thanks for any help. Create procedure...
10
by: Sune | last post by:
Hi, previously I used Eclipse CDT for compiling my files just to get started with C and leave C++ behind. Now it's time to get a little more serious so I've moved my files to a new workplace and...
8
by: Jim Butler | last post by:
What are the drawbacks if any to this approach of not using the gac for shared components... basically having a central directory located outside of iis, that all web applications have a virtual...
3
by: Dan | last post by:
Hi, I have a problem using an aspx page with a Control on it. I get the following error message Compiler Error Message: CS1595: 'Test.Class2' is defined in multiple places; using definition...
0
by: Dam6 | last post by:
Hello, Having a bit of trouble with a simple login page etc using an access db. (Using DW 2004 and databases from Sean R. Nicholson) I've created a virtual application, added the dw ctrls and...
6
by: thomson | last post by:
Hi all, I have compiled by .net web applicaion in my local machine , and a dll has been created on the bin Directory, And i have copied the entire application using xcopy deployment to a...
3
by: kuiyuli | last post by:
I'm using VC++ .Net to do a simlple program. I tried to use <vector> <list> in the program, and I simply put the folowing lines " #include <list> #include <vector> #include <string> using...
10
by: Ivan Vecerina | last post by:
Here's a relatively simple code snippet: #include <memory> class Base { public: Base(); virtual ~Base(); virtual void f(int a, char const* name);
4
by: =?Utf-8?B?SmFtZXMgUGFnZQ==?= | last post by:
Am i missing somthing simple? I can't access any of the profile names in my code behind i.e; textBox1.text = Profile.test = "some text" here's the web.config: <?xml version="1.0"?> ...
3
by: Ashik | last post by:
I have a simple compilation question, but I haven't been able to find an answer for it anywhere online. I've made a simplified version of my problem using a few files. The main problem is that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.