[Insight-users] ITK run-time error from DLL - Solved
Abhishek
gattani at aktina.com
Thu Mar 3 13:32:07 EST 2005
Thanks for the responses. But I was able to solve the problem few hours
after posting it. I am explaining the solution for people who might
encounter the problem in some other form:
When you create a Visual C++ Windows Control Library.NET project it creates
by default as a DLL without any linkage to native libraries such as the CRT,
ATL, or MFC, and without any static variables. If you add code that uses
static variables (for example, ITK, ATL, MFC, and CRT libraries use static
variables), you will receive linker warnings at compile time unless you
first convert the project to mixed mode. The answer is to convert the
project to a mixed mode DLL. Read the MSDN article [1] for step-by-step
instructions. In my case I had done that and received no linkage errors but
during run-time I was getting the "Null Reference Exception." as mentioned
previously. Now the consumer of my DLL is a managed C# code. The problem is
that C# was not initializing the DLL. So I added a class called
ManagedWrapper for manual initialization of the DLL. The code for this class
can be found in [1]. This class had two member functions one for
initializing the DLL and one for terminating it. Calling these functions
before and after referring to my DLL solved the problem. My understanding is
that the problem was being caused because ITK uses static variables and they
were not being initialized and the itkNewMacro()was failing to create an
instance, hence the NULL object. Although my DLL had an entry point which is
what [1] achieves, it was not being entered automatically, and the client
had to manually instantiate the DLL. I hope this helps people who encounter
similar problems in the future. Thanks again for all the responses.
-Cheers,
Abhishek
References:
[1] "Converting Managed Extensions for C++ Projects from Pure Intermediate
Language to Mixed Mode", MSDN.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20050303/4cea6395/attachment.htm
More information about the Insight-users
mailing list