Home > Back-end >  For help! Registered COM component failure
For help! Registered COM component failure

Time:09-28

Younger brother recently spare nothing flipped through COM technology to something (to enrich their own knowledge base as a purpose)

Following tutorials do a simple DEMO, the COM component is Inprocess Server, namely a regular DLL, when the user calls to submit two integers a and b, this component is given the value of a + b, using VS created a Win32 DLL project, COM components to the registered on the system now, stuck

I call this the project Fooo

Implementation component registered source code is as follows (imitate Don Box of Essential COM)

Registry. CPP

 
# include "stdafx. H"
# include "Registry. H"
# include "Global h"

Const char * g_RegTable [], [3]={
//format is {key, the value name, value}
{" clsids \ \ {F8771B89-7971-4085-8 f7c140698b d5f - 88} ", 0, "FastAddition"},
{" clsids \ \ {F8771B89-7971-4085-8 f7c140698b d5f - 88} \ \ InprocServer32 ", 0,
(const char *) - 1//rogue value indicating the file name
},
{" clsids \ \ {F8771B89-7971-4085-8 f7c140698b d5f - 88} \ \ ProgID ", 0, Fooo. FastAddition. "1"},
{Fooo. FastAddition. 1, 0, "FastAddition"},
{1 \ \ "Fooo. FastAddition. Clsids", 0, "{F8771B89-7971-4085-8 f7c140698b d5f - 88}"},
};

STDAPI DllRegisterServer (void) {
Retrieves the hr=S_OK;
//look up server 's file name
Char szFileName [MAX_PATH];
GetModuleFileNameA (g_hModule szFileName, MAX_PATH);
//register entries from the table
Int nEntries=sizeof (g_RegTable)/sizeof (* g_RegTable);
For (int I=0; SUCCEEDED (hr) & amp; & I & lt; NEntries; I++) {
Const char * pszKeyName=g_RegTable [I] [0];
Const char * pszValueName=g_RegTable [I] [1];
Const char * pszValue=https://bbs.csdn.net/topics/g_RegTable [I] [2];
//map rogue value to the module file name
If (pszValue=https://bbs.csdn.net/topics/=(const char *) - 1)
PszValue=https://bbs.csdn.net/topics/szFileName;
Hkeys hkeys;
//create the key
Long err=RegCreateKeyA (HKEY_CLASSES_ROOT,
PszKeyName, & amp; Hkeys);
If (err==ERROR_SUCCESS) {
//set the value
Err=RegSetValueExA (hkeys, pszValueName, 0,
REG_SZ, (const BYTE *) pszValue,
(strlen (pszValue) + 1));
RegCloseKey (hkeys);
}
The else {
//if always add a key or value, back out and fail
DllUnregisterServer ();
Hr=SELFREG_E_CLASS;
}
}
Return the hr;
}

STDAPI DllUnregisterServer (void) {
Retrieves the hr=S_OK;
Int nEntries=sizeof (g_RegTable)/sizeof (* g_RegTable);
For (int I=nEntries - 1; I & gt;=0; I -) {
Const char * pszKeyName=g_RegTable [I] [0];
Long err=RegDeleteKeyA (HKEY_CLASSES_ROOT, pszKeyName);
if (err !=ERROR_SUCCESS)
Hr=S_FALSE;
}
Return the hr;
}


The Global. H is defined two Global variables, one is type int is used as the component's internal operations, and a handle to the DLL is HMODULE preserved

The project generates Fooo. DLL

I use Windows 7-64

Administrator privileges to open the CMD, switch to the C: \ Windows \ syswow64, execute the command:
 
Regsvr32 e: \ FoooSln \ Release \ Fooo DLL


Tip me:

DllRegisterServer in E: \ FoooSln \ Release \ Fooo DLL succeeded.

But I go to the registry view HKEY_CLASSES_ROOT \ clsids but couldn't see my registration information (of course, I searched for the registry, or didn't search)

Excuse me, ladies and gentlemen, this may be what causes the registration is not successful? Thank you very much!

CodePudding user response:

Add some log output within the DllRegisterServer function, such as write registry in OutputDebugString see no success,

CodePudding user response:

reference 1st floor ccrun response:
add some log output within the DllRegisterServer function, such as write registry in OutputDebugString see whether success,


Debugging, line 36 return an error code 0 x 5, with FormatMessage is checked the Access is denied. Access denied

CodePudding user response:

reference 1st floor ccrun response:
add some log output within the DllRegisterServer function, such as write registry in OutputDebugString see whether success,

I use administrator privileges to open VS debug, there is no error, all operations are successful but still in the registry could not find the key to write,
  • Related