[Insight-users] How to extend ITK with DLLs at runtime? Defining ITK_AUTOLOAD_PATH crashes every program!

Parag Chandra pchandra at radonc . unc . edu
Fri, 16 May 2003 11:35:52 -0400


Thanks Koen; that solved the particular problem I was seeing yesterday.
However, I then got a new problem: the itkLoad() symbol was not being
exported from my DLL. Fortunately, itkPNGImageIOFactory had this =
function
properly exported, so I followed its example and prefaced itkLoad() with

extern "C"=20
#ifdef _WIN32
__declspec( dllexport )=20
#endif

Now ObjectFactoryBase was able to obtain a valid handle to the DLL and
instantiate my factory. However, the line

newfactory->m_LibraryPath =3D fullpath;

caused almost the exact same problem as the one I saw yesterday: the
std::string threw an exception when trying to copy the contents of =
fullpath
over. So I then modified itkLoad() from

return myFactory::New(), which uses itkFactoryLessNewMacro,=20

to

return new myFactory(), which also forced me to declare the constructor =
for
myFactory as public, violating one of ITK's design principles. Now
everything works fine, at least for a Debug build under MSVC6. It seems =
to
me that the underlying problem is STL is somehow not 'ready' to be used =
at
such an early point in an ITK program's execution, or at least not in a
consistent manner.

I'm still a little concerned that now I'm actually returning a real =
pointer
instead of a smartpointer, I'm setting myself up for problems later on =
when
ITK's reference counting mechanism tries to automatically delete the =
object.
Can someone more familiar with the plumbing in ITK comment on this? =
Should
Koen's fix get committed to the repository? I checked CVS yesterday and =
it
was not in there. Also, maybe ITK's documentation/user guide should be
updated with this information so that others can easily use the =
pluggable
object factory mechanism. Hope the trouble I went through can help =
someone
else!

Best regards,
-Parag


-----Original Message-----
From: Koen Van Leemput [mailto:koen.vanleemput@hus.fi]=20
Sent: Friday, May 16, 2003 2:32 AM
To: Parag Chandra; insight-users@public.kitware.com
Subject: Re: [Insight-users] How to extend ITK with DLLs at runtime?
Defining ITK_AUTOLOAD_PATH crashes every program!

On Thursday 15 May 2003 19:25, Parag Chandra wrote:
> Thanks for your help Gavin. But now as soon as I define
> ITK_AUTOLOAD_PATH, every program that I've written that links against
> ITK dies unexpectedly inside itk::Directory::Load(). Specifically, at
> the following line inside the do loop:
>
>
>
>     m_Files.push_back(data.name);
>
>


Hi, =20

I never played with ITK_AUTOLOAD_PATH, but I did copy some code from=20
itkObjectFactoryBase some time ago into my own software and got exactly =
the=20
same problem.=20

As it turned out, the line=20

Directory* dir =3D Directory::New();

in itkObjectFactoryBase::LoadLibrariesInPath(const char*) should use a =
smart

pointer instead, i.e.

Directory::Pointer dir =3D Directory::New();

Hope this helps,

- Koen


--=20
*************************************************************************=
***
*=20
Koen Van Leemput, Ph.D.                email : koen.vanleemput@hus.fi=20
Department of Radiology                  phone: +358 9 471 76630       =20
Helsinki University Central Hospital   mobile: +358 50 42 72300       =20
P.O. Box 340                                  fax:      +358 9 471 71342

FIN-00029 HUS

FINLAND

*************************************************************************=
***
*=20