HOWTO: Install/copy COM file, and register it. 
Author Message
 HOWTO: Install/copy COM file, and register it.

Hi,

I'm having difficulty trying to register a COM object.  Basically what
I'm doing is writing a psuedo installer, that copies new/updated files
to a previous installation, then registers any of those files that
support self-registration.

Everything works fine, except that I get a sharing violation when I try
to call LoadLibrary() on the COM file in question.  I used CopyFile() to
copy the file, does it only queue the file for copying?  If so is there
a way to flush the queue.

My registration code is correct, I snagged it straight from the regsvr32
example in MSDN.  If I register a file that my program has not touched,
it works fine.  I even tried spawning off regsvr32, and got the same
result.  And, if I run regsvr32 on the file while my program is still
active but after the copy, it fails.  But as soon as my program exits,
it will succeed.  So basically I've got it narrowed down to the copy.
Suggestions?  Insights?  Examples?

Here are (basically) the steps I'm taking.
.
.
.
CopyFile(source, destination, false);    // most likely the culprit
if (destinationIsSelfRegistering)
{
   if (! FAILED( OleInitialize(NULL) ) )
   {
        HINSTANCE hLib = LoadLibrary(destination);
        if (hLib != NULL)
        {
            HRESULT (STDAPICALLTYPE * lpDllEntryPoint)(void);
           (FARPROC&)lpDllEntryPoint = GetProcAddress(hLib,
"DllRegisterServer");
            if (lpDllEntryPoint != NULL)
            {
                 (*lpDllEntryPoint)();
            }
            FreeLibrary(hLib);
        }
        OleUninitialize();
    }

Quote:
}

.
.
.

Help.

Matt



Tue, 14 Oct 2003 07:23:14 GMT  
 HOWTO: Install/copy COM file, and register it.
Greets,

    You may want to take a closer look at how your object's
DllRegisterServer() works, the name of the file is retrieved and marked in
the registry by GetModuleFileName() if you are using ATL.  If you copy the
file to a different destination, when it is loaded and registered, it points
to that file's path in the registry whenever the object is instantiated.
Are you deleting the destination file after the registration?

Regards,

Joe


Quote:
> Hi,

> I'm having difficulty trying to register a COM object.  Basically what
> I'm doing is writing a psuedo installer, that copies new/updated files
> to a previous installation, then registers any of those files that
> support self-registration.

> Everything works fine, except that I get a sharing violation when I try
> to call LoadLibrary() on the COM file in question.  I used CopyFile() to
> copy the file, does it only queue the file for copying?  If so is there
> a way to flush the queue.

> My registration code is correct, I snagged it straight from the regsvr32
> example in MSDN.  If I register a file that my program has not touched,
> it works fine.  I even tried spawning off regsvr32, and got the same
> result.  And, if I run regsvr32 on the file while my program is still
> active but after the copy, it fails.  But as soon as my program exits,
> it will succeed.  So basically I've got it narrowed down to the copy.
> Suggestions?  Insights?  Examples?

> Here are (basically) the steps I'm taking.
> .
> .
> .
> CopyFile(source, destination, false);    // most likely the culprit
> if (destinationIsSelfRegistering)
> {
>    if (! FAILED( OleInitialize(NULL) ) )
>    {
>         HINSTANCE hLib = LoadLibrary(destination);
>         if (hLib != NULL)
>         {
>             HRESULT (STDAPICALLTYPE * lpDllEntryPoint)(void);
>            (FARPROC&)lpDllEntryPoint = GetProcAddress(hLib,
> "DllRegisterServer");
>             if (lpDllEntryPoint != NULL)
>             {
>                  (*lpDllEntryPoint)();
>             }
>             FreeLibrary(hLib);
>         }
>         OleUninitialize();
>     }
> }
> .
> .
> .

> Help.

> Matt



Tue, 14 Oct 2003 20:45:29 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Install Shield and registering ATL COM objects

2. COM will not register without VC++ installed

3. HOWTO: Deal with Files -- Move, Copy, Delete

4. trouble copying files from MSDN CD since IE 4.0 installed

5. why Can\'t create COM Instance After registering COM Server Successfully

6. Howto: declare a C function that registers a callback in IDL

7. howto register only whilst running

8. HOWTO: Register a custom sound with my app?

9. HOWTO: Register a custom sound with my app?

10. HOWTO: register own WINCLASS for CDialog-based windows?

11. Q Registers/Subkeys Howto use?

12. Installed Debug Symbols - Now HOWTO configure VC?

 

 
Powered by phpBB® Forum Software