[Gdal-dev] GDAL, ECW, and COM

Peng Gao pgao at esri.com
Fri Apr 1 19:57:40 EST 2005


The app hosting GDAL has COM properly initialized. From within this
app, GDALDriver::CreateCopy() is called. Somewhere in ECW driver, the
following is called:

/* -------------------------------------------------------------------- */
/*      Start the compression.                                          */
/* -------------------------------------------------------------------- */
    oCompressor.Write();

It seems that this call creates a worker thread, and this worker thread
does not call CoInitialize(NULL); This worker thread calls back to GDAL
for pixels, and no COM object can be created in this thread. That's my
problem.


> -----Original Message-----
> From: Chapman, Martin [mailto:MChapman at sanz.com]
> Sent: Friday, April 01, 2005 4:15 PM
> To: warmerdam at pobox.com; Peng Gao
> Cc: GDAL Dev
> Subject: RE: [Gdal-dev] GDAL, ECW, and COM
> 
> Frank,
> 
> Anytime you create a new thread on windows using ATL (COM) you need to
> do something like this:
> 
> unsigned long WINAPI ThreadProc(void* p)
> {
> 	try
> 	{
> 		CoInitialize(NULL);
> 
> 		CParseProcessor ParseProcessor;
> 		CParseServer *pParseServer = (CParseServer*) p;
> 
> 		Sleep(100);
> 
> 		ParseProcessor.m_nIdleTime = pParseServer->m_nIdleTime;
> 		ParseProcessor.m_nMailServerPort =
> pParseServer->m_nMailServerPort;
> 		ParseProcessor.m_nProcessMax =
> pParseServer->m_nProcessMax;
> 		ParseProcessor.m_sEmailFrom =
> pParseServer->m_sEmailFrom;
> 		ParseProcessor.m_sEmailSubject =
> pParseServer->m_sEmailSubject;
> 		ParseProcessor.m_sEmailTo = pParseServer->m_sEmailTo;
> 		ParseProcessor.m_sMailServerHost =
> pParseServer->m_sMailServerHost;
> 		ParseProcessor.m_sMailServerPassword =
> pParseServer->m_sMailServerPassword;
> 		ParseProcessor.m_sMailServerProfile =
> pParseServer->m_sMailServerProfile;
> 
> 		ParseProcessor.Run();
> 		delete pParseServer;
> 
> 		CoUninitialize();
> 	}
> 	catch(...)
> 	{
> 		// handle it
> 	}
> 
> 	return 0;
> }
> 
> Martin
> 
> -----Original Message-----
> From: gdal-dev-bounces at xserve.flids.com
> [mailto:gdal-dev-bounces at xserve.flids.com] On Behalf Of Frank Warmerdam
> Sent: Friday, April 01, 2005 3:46 PM
> To: Peng Gao
> Cc: GDAL Dev
> Subject: Re: [Gdal-dev] GDAL, ECW, and COM
> 
> 
> On Apr 1, 2005 5:10 PM, Peng Gao <pgao at esri.com> wrote:
> > I wrote a new GDAL dataset whose implementation uses some COM objects.
> 
> > When I do a CreateCopy() using my dataset as input, it works for most
> > formats except ECW. The error is that COM objects can not be cocreated
> 
> > because CoInitialize() is not called on the thread. The following is
> > the call stack (Windows) when the error occurred. It looks like a
> > different thread from the main thread where GDALDriver::CreateCopy()
> > is invoked.
> >
> > If this is true, can the compressor thread be enclosed in
> > CoInitialize() and CoUninitialize()?
> 
> Peng,
> 
> I'm am not too savvy on COM or multi-threading issues, so you may need
> to spell a few things out for me.
> 
> First, my understanding is that the ECW driver is multi-threaded, and
> uses seperate working threads when compressing.  Furthermore, these
> worker threads end up "calling back" to get the data source the source
> dataset.  So the IO calls on the source file will happen in a thread
> other than the main one used for GDAL.
> 
> I gather it is this being called from a different thread that is causing
> you problems?
> 
> >From the GDAL level I don't really have any access inside the ECW
> compressor thread except for in the callback.  I suppose I could add
> something to do a coinitialize in there on the first callback, but it
> really seems like this is an issue with the COM based driver.  Couldn't
> it do a CoInitialize() internally in any function that gets called by a
> new thread?
> 
> Doing the uninitialize would be quite a bit tricker since there is no
> easy way to know when the last call from the thread has been made.
> 
> Darn, I hate multi-threading.
> 
> Best regards,
> --
> ---------------------------------------+--------------------------------
> ---------------------------------------+------
> I set the clouds in motion - turn up   | Frank Warmerdam,
> warmerdam at pobox.com
> light and sound - activate the windows | http://pobox.com/~warmerdam
> and watch the world go round - Rush    | Geospatial Programmer for Rent
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at xserve.flids.com
> http://xserve.flids.com/mailman/listinfo/gdal-dev



More information about the Gdal-dev mailing list