Board index » delphi » Creating COM Objects inside DLLs

Creating COM Objects inside DLLs

Hi,

I'm having trouble trying to create an instance of a COM object inside a
DLL.

I use the delphi function CreateComObject, and this raises an exception:
EOleSysError "CoInitialize has not been called.". I'm not sure what this
means.

The same piece of code to create the COM object works fine in a normal exe,
and only causes this problem when I call it inside my DLL.

Does anyone know if I need to create COM objects any differently from within
DLLs, or weather or not the DLL needs to be setup or instantiated
differently if it's going to create COM objs?

Hope somebody can help..

Trevor Mackenzie

 

Re:Creating COM Objects inside DLLs


Quote
> I use the delphi function CreateComObject, and this raises an exception:
> EOleSysError "CoInitialize has not been called.". I'm not sure what this
> means.

It means that your DLL needs to initialize COM by called CoInitialize, eg:

    Succeed(CoInitialize(nil));

Quote
> The same piece of code to create the COM object works fine in a normal
exe,
> and only causes this problem when I call it inside my DLL.

Because Delphi generates the necessary CoInitialize statement for
applications, but not DLLs.

Quote
> Does anyone know if I need to create COM objects any differently from
within
> DLLs, or weather or not the DLL needs to be setup or instantiated
> differently if it's going to create COM objs?

Just add the line above and everything should work.

Oliver

Re:Creating COM Objects inside DLLs


Perfect. Thanks a lot..

Quote
"Oliver Townshend" <oli...@zip.com.au> wrote in message

news:3e7844cd@newsgroups.borland.com...
Quote
> > I use the delphi function CreateComObject, and this raises an exception:
> > EOleSysError "CoInitialize has not been called.". I'm not sure what this
> > means.

> It means that your DLL needs to initialize COM by called CoInitialize, eg:

>     Succeed(CoInitialize(nil));

> > The same piece of code to create the COM object works fine in a normal
> exe,
> > and only causes this problem when I call it inside my DLL.

> Because Delphi generates the necessary CoInitialize statement for
> applications, but not DLLs.

> > Does anyone know if I need to create COM objects any differently from
> within
> > DLLs, or weather or not the DLL needs to be setup or instantiated
> > differently if it's going to create COM objs?

> Just add the line above and everything should work.

> Oliver

Re:Creating COM Objects inside DLLs


<<Trevor Mackenzie:
EOleSysError "CoInitialize has not been called.".

Quote

What Oliver said; and call CoUninitialize when you've
finished, too.

--
Deborah Pate (TeamB) http://delphi-jedi.org

  TeamB don't see posts sent via Google or ISPs
  Use the real Borland server: newsgroups.borland.com
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Creating COM Objects inside DLLs


Quote
> EOleSysError "CoInitialize has not been called.".

> What Oliver said; and call CoUninitialize when you've
> finished, too.

You learn something new every day.  Thanks Deborah.

Oliver

Other Threads