<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY text=#000000 bgColor=#ffffff>
<DIV dir=ltr align=left><SPAN class=718065022-01102006><FONT face=Arial
color=#0000ff size=2>Hi Dan, </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=718065022-01102006><FONT face=Arial
color=#0000ff size=2>Thank you for such a comprehensive answer, but although all
executes smoothly, this is still a console application and changing the
subsystem to Windows (to prevent the console window from showing up) brings back
the old error again. However you mentioned that you are using a c# application,
I will give it a try then, </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=718065022-01102006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=718065022-01102006><FONT face=Arial
color=#0000ff size=2>Best, <BR>Tadeusz</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=pl dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Dan Mueller [mailto:d.mueller@qut.edu.au]
<BR><B>Sent:</B> Sunday, October 01, 2006 11:15 PM<BR><B>To:</B> Tadeusz
Dracz<BR><B>Cc:</B> insight-users@itk.org<BR><B>Subject:</B> Re: [Insight-users]
ITK and managed c++ 2005<BR></FONT><BR></DIV>
<DIV></DIV><SMALL><FONT face="Helvetica, Arial, sans-serif">Hi Tadeusz,<BR><BR>I
am indeed using System.Windows.Forms; however not from a C++ application, but a
C# application. So I think there is definitely some hope!<BR><BR>Okay, let's
work this out. I have tried the minimal example you sent me and can confirm that
it <U>does</U> produce the 'System.TypeInitializationException' you were
reporting. I think the issue is with the vcproj file. Are you using CMake to
configure your project? I <B>*highly*</B> recommend using it - in the long run
it will save you heaps of time! CMake can be downloaded from <A
class=moz-txt-link-freetext
href="http://www.cmake.org">http://www.cmake.org</A>.<BR><BR>Using CMake allows
for all the myriad of compilation and linking options to be taken care of
automatically (almost). Because we are using C++/CLI (ie. Managed C++ 2005) we
need to <B>set some of the options by hand</B> (if anyone out there knowns how
to set the below options actually using CMake I would love to here from you!).
Please find attached a CMake script for configuring your minimal example. To
build the example, follow these steps:<BR><BR> 1. Open CMake
and set the source and build paths (usually not the same place to keep things
neat ie. 'out-of-source-build' )<BR> 2. Configure the project,
making sure the ITK_DIR is automatically found (if not you will need to browse
to it by hand)<BR> 3. Open the generated solution
file<BR> 4. Right-click on the project file and select
"Properties".<BR> 5. Navigate to "Configuration Properties
> General" and set "Common Language Runtime support" to on (ie.
/clr).<BR> I have found that just
adding the /clr switch as an additional compilation option using CMake does not
work...anyone out there have any
ideas?<BR> Instead you must change the
"ManagedExtensions" property value in the vcproj file from "0" to
"1".<BR> 6. Navigate to "</FONT></SMALL><SMALL><FONT
face="Helvetica, Arial, sans-serif">Configuration Properties > C/C++ >
Code Generation" and change "Enable C++ Exceptions" to "Yes With SEH Exceptions"
(ie. /EHa)<BR> We need to do this
because the /EHsc switch is not compatiable with the /clr
switch.<BR> Again I have found that
just adding to /EHa switch with CMake does not work. It seems that /EHsc is
deeply entrenched in CMake - I managed to trace it back to<BR>
CMAKE_CXX_FLAGS_INIT in
share/CMake/Modules/Platform/Windows-cl.cmake...but I can't work out how to
override it with /EHa.<BR> 7. Compile the project!<BR><BR>I
have added some more complexity to the minimal example just to make sure
everything is working okay. Using this approach I can instantiate the
ImageFileReader object with no problems.<BR><BR>FYI: I use a little custom
program to 'fix' the output of the CMake project files. It's not an ideal
solution, but it does allow me to use CMake to manage the compilation and
linkage options. I can forward it to you if you are interested. <B>Again, if
anyone on the mailing list knows how to set these options using native CMake,
I'd like to hear from them!</B><BR><BR>Anyway, hope this
helps!<BR><BR>Cheers<BR><BR>Dan</FONT></SMALL><SMALL><FONT
face="Helvetica, Arial, sans-serif"><BR><BR><BR>Tadeusz Dracz
wrote:</FONT></SMALL>
<BLOCKQUOTE cite=mid003101c6e541$d6c92820$0201a8c0@Main type="cite">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR>
<DIV dir=ltr align=left><SPAN class=687253009-01102006><FONT face=Arial
color=#0000ff size=2>Hi Dan, </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006><FONT face=Arial
color=#0000ff size=2>Do you use managed windows forms C++ application?
Because my C++ managed console applications run ok with ITK. If you do,
there would be at least some hope for me that it is
possible.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006><FONT face=Arial
color=#0000ff size=2>I have attached the simplest managed windows forms C++
application. I have removed all additional files and code, to keep it
down to minimum. </FONT></SPAN><SPAN class=687253009-01102006><FONT face=Arial
color=#0000ff size=2>From the standard settings I have changed from /clr:pure
to /clr (Configuration Properties->General->Common Language Runtime
Support), otherwise ITK would not link.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006><FONT face=Arial
color=#0000ff size=2>Before, I have compiled ITK using standard settings
(BUILD_SHARED_LIBS is OFF).</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006><FONT face=Arial
color=#0000ff size=2>There is a workaround that will make it run. This
requires changing:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006><FONT face=Arial
color=#0000ff size=2>Linker->System->Subsystem: Not
Set</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006><FONT face=Arial
color=#0000ff size=2>Linker->Advanced->Entry Point:
Empty</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006><FONT face=Arial
color=#0000ff size=2>But this trick causes a console window to appear and this
is supposed to be a Windows Forms application. </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006><FONT face=Arial
color=#0000ff size=2>This will look all right in the attached
sample, because I have removed the form creation code, but it does not
look pretty in the real application where both the console window
and the form show up.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006><FONT face=Arial
color=#0000ff size=2>Best, </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=687253009-01102006><FONT face=Arial
color=#0000ff size=2>Tadeusz</FONT></SPAN> <BR></DIV><BR>
<DIV class=OutlookMessageHeader lang=pl dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Dan Mueller [<A
class=moz-txt-link-freetext
href="mailto:d.mueller@qut.edu.au">mailto:d.mueller@qut.edu.au</A>]
<BR><B>Sent:</B> Saturday, September 30, 2006 11:14 PM<BR><B>To:</B> <A
class=moz-txt-link-abbreviated
href="mailto:tdracz@o2.pl">tdracz@o2.pl</A><BR><B>Cc:</B> <A
class=moz-txt-link-abbreviated
href="mailto:insight-users@itk.org">insight-users@itk.org</A><BR><B>Subject:</B>
Re: [Insight-users] ITK and managed c++ 2005<BR></FONT><BR></DIV><SMALL><FONT
face="Helvetica, Arial, sans-serif">Hi Tadeusz,<BR><BR>I have been using ITK
with C++/CLI with no problems... I have experienced some "access violation
exceptions" similar to yours below - but only when using a SmartPointer which
has gone out of scope and deleted itself.<BR><BR>Can you provide some more
information, or perhaps a minimal example which
fails?<BR><BR>Cheers<BR><BR>Dan<BR></FONT></SMALL><BR><A
class=moz-txt-link-abbreviated href="mailto:tdracz@o2.pl">tdracz@o2.pl</A>
wrote:
<BLOCKQUOTE cite=mid002b01c6e46e$d297d860$0201a8c0@Main type="cite"><PRE wrap="">Hello,
I have created a sample C++ managed windows forms application that is
supposed to use ITK.
I have added all includes as in a normal unmanaged c++ project. It compiles
without errors and warnings.
But when executed, it throws an exception just at the start. Here is the
contents of the Output window:
First-chance exception at 0x7c96cc82 in App.exe: 0xC0000005: Access
violation reading location 0x0d7cebd9.
First-chance exception at 0x781389db (msvcr80.dll) in App.exe: 0xC0000005:
Access violation writing location 0x0d7cebda.
A first chance exception of type 'System.AccessViolationException' occurred
in App.exe
A first chance exception of type
'<CrtImplementationDetails>.ModuleLoadException' occurred in msvcm80.dll
First-chance exception at 0x7c812a5b in App.exe: Microsoft C++ exception:
[rethrow] at memory location 0x00000000..
An unhandled exception of type 'System.TypeInitializationException' occurred
in Unknown Module.
Additional information: The type initializer for '<Module>' threw an
exception.
System.TypeInitializationException' occurred in Unknown Module.
The application contains just these lines that use ITK:
#include "itkImageFileReader.h"
typedef unsigned short PixelType;
const unsigned int Dimension = 3;
typedef itk::Image< PixelType, Dimension > ImageType;
Is there anybody that could help in this matter?
Regards,
Tadeusz
_______________________________________________
Insight-users mailing list
<A class=moz-txt-link-abbreviated href="mailto:Insight-users@itk.org">Insight-users@itk.org</A>
<A class=moz-txt-link-freetext href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</A>
</PRE></BLOCKQUOTE><PRE wrap=""><HR width="90%" SIZE=4>
using namespace System;
#include "itkImageFileReader.h"
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
        return 0;
}
</PRE></BLOCKQUOTE></BODY></HTML>