<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
h1
        {mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:24.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
pre
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;}
@page Section1
        {size:612.1pt 792.1pt;
        margin:.4in .2in 7.1pt .5in;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>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:<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>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.<o:p></o:p></span></font></p>
<pre><font size=2 face="Courier New"><span style='font-size:10.0pt'><o:p> </o:p></span></font></pre>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>-Cheers,<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Abhishek <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>References:<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>[1] </span></font><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>“Converting Managed Extensions for C++ Projects from
Pure Intermediate Language to Mixed Mode”, MSDN.com<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
</div>
</body>
</html>