register server problems

This is a discussion on register server problems within the Windows Programming forums, part of the Platform Specific Boards category; I have created a com server and stored it in a dll. When I run regsvr32 to register the server ...

  1. #1
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540

    register server problems

    I have created a com server and stored it in a dll. When I run regsvr32 to register the server I revieve an error message stating that the specified module could not be found. I am using regsvr32 like this:
    Code:
    regsvr32 C:\Documents and Settings\Andrew Hunter\My Documents\Visual Studio Projects\COM\Chapter 7\Component7\Debug\Component7.dll
    I was hoping someone would be able to help me out on this. Thanks in advance.

    BTW here is the block of code from my dll that handles the registration and initialization
    Code:
    STDAPI DllRegisterServer() {
    
    	return RegisterServer(g_hModule, CLSID_Component1, g_szFriendlyName, g_szVerIndProgID, g_szProgID);
    }
    //server unregister
    
    STDAPI DllUnregisterServer() {
    
    	return UnregisterServer(CLSID_Component1, g_szVerIndProgID, g_szProgID);
    }
    
    //dll module info
    
    BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, void* lpReserved) {
    
    	if(dwReason == DLL_PROCESS_ATTACH) {
    		g_hModule = hModule;
    	}
    	return true;
    }
    Last edited by andyhunter; 12-15-2004 at 03:06 PM.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    try:

    Code:
    EXTERN_C STDAPI DllRegisterServer() {
    
    	return RegisterServer(g_hModule, CLSID_Component1, g_szFriendlyName, g_szVerIndProgID, g_szProgID);
    }
    //server unregister
    
    EXTERN_C STDAPI DllUnregisterServer() {
    
    	return UnregisterServer(CLSID_Component1, g_szVerIndProgID, g_szProgID);
    }
    
    //dll module info
    
    BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, void* lpReserved) {
    
    	if(dwReason == DLL_PROCESS_ATTACH) {
    		g_hModule = hModule;
    	}
    	return true;
    }
    Though i somehow doubt thats the problem... hmmmmmmmmm. Oh! you know what (its been too long since i've made COM anything). That part of your code is where you are supposed to add information to the system registry. Completely disregard the above code tags. What you need to do is create a GUID for your objects and register them with windows. MSVC++ 6 came with examples of how to do this, I'm sure all newer versions also have them. Likewise DllUnregisterServer() removes the registry entries.
    Last edited by master5001; 12-16-2004 at 06:14 AM.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Hate to ask the obvious, but have you tried

    Code:
    regsvr32 "C:\Documents and Settings\Andrew Hunter\My Documents\Visual Studio Projects\COM\Chapter 7\Component7\Debug\Component7.dll"

  4. #4
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Fordy, you are a genius; I did leave out the quotation marks. God! I am an idiot. Unfortunately, now I am recieving the error message that the DllRegisterServer entry was not found, both with and without the additional extern C code tags. I have even forward defined the functions as so:
    Code:
    extern "C" __declspec(dllexport) HRESULT STDAPICALLTYPE DllRegisterServer();
    extern "C" __declspec(dllexport) HRESULT STDAPICALLTYPE DllUnregisterServer();

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Did you read what I said? Your actual functions are not doing what they are supposed to. Those functions need to add your GUID's for your DLL to the registry and remove them (respectively). You are not properly using them.

  6. #6
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Well this is how I am trying to register it:

    Code:
    return RegisterServer(g_hModule, CLSID_Component1, g_szFriendlyName, g_szVerIndProgID, g_szProgID);
    And that function is this:

    Code:
    //
    // Register the component in the registry.
    //
    HRESULT RegisterServer(HMODULE hModule,            // DLL module handle
                           const CLSID& clsid,         // Class ID
                           const char* szFriendlyName, // Friendly Name
                           const char* szVerIndProgID, // Programmatic
                           const char* szProgID)       //   IDs
    {
    	// Get server location.
    	char szModule[512] ;
    	DWORD dwResult =
    		::GetModuleFileName(hModule, 
    		                    szModule,
    		                    sizeof(szModule)/sizeof(char)) ;
    	assert(dwResult != 0) ;
    
    	// Convert the CLSID into a char.
    	char szCLSID[CLSID_STRING_SIZE] ;
    	CLSIDtochar(clsid, szCLSID, sizeof(szCLSID)) ;
    
    	// Build the key CLSID\\{...}
    	char szKey[64] ;
    	strcpy(szKey, "CLSID\\") ;
    	strcat(szKey, szCLSID) ;
      
    	// Add the CLSID to the registry.
    	setKeyAndValue(szKey, NULL, szFriendlyName) ;
    
    	// Add the server filename subkey under the CLSID key.
    	setKeyAndValue(szKey, "InprocServer32", szModule) ;
    
    	// Add the ProgID subkey under the CLSID key.
    	setKeyAndValue(szKey, "ProgID", szProgID) ;
    
    	// Add the version-independent ProgID subkey under CLSID key.
    	setKeyAndValue(szKey, "VersionIndependentProgID",
    	               szVerIndProgID) ;
    
    	// Add the version-independent ProgID subkey under HKEY_CLASSES_ROOT.
    	setKeyAndValue(szVerIndProgID, NULL, szFriendlyName) ; 
    	setKeyAndValue(szVerIndProgID, "CLSID", szCLSID) ;
    	setKeyAndValue(szVerIndProgID, "CurVer", szProgID) ;
    
    	// Add the versioned ProgID subkey under HKEY_CLASSES_ROOT.
    	setKeyAndValue(szProgID, NULL, szFriendlyName) ; 
    	setKeyAndValue(szProgID, "CLSID", szCLSID) ;
    
    	return S_OK ;
    }

  7. #7
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Thankyou all for your help, I greatly appreciated it. I figured out the problem, it turns out that my def file listed the exports as private!!!! Can you believe that, anyway thankyou all for helping me along the way.

  8. #8
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    No problem. Thats an interesting problem though. Good job compiler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 11-12-2008, 06:21 PM
  2. Having Buffer Problems With Overlapped I/O --
    By Sargera in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 03:46 PM
  3. Unicode vurses Non Unicode client server application with winsock2 query?
    By dp_76 in forum Networking/Device Communication
    Replies: 0
    Last Post: 05-16-2005, 07:26 AM
  4. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21