[Insight-users] ITK and managed C++ .NET

Luis Ibanez luis.ibanez at kitware.com
Sat Jul 10 22:52:02 EDT 2004


Hi Nick,

The first round of error that your get:

 > C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with
 > /GR-; unpredictable behavior may result

mean that you are not enabling exceptions.

Exceptions *must* be enabled in ITK for two reasons,
one is that ITK use RTTI in order to do dynamic_casting,
and the second reason is that error management in ITK
is based on C++ exceptions.

Since you are configuring your project by hand, you should
select "Properties" in your project and go to

           "Configuration Properties"
           "C++"
           "Code Generation"

and enable:

           "Enable C++ Exceptions"



Regards,



     Luis




-------------------
Nick Arini wrote:
> John,
> 
> I am still having trouble getting ITK to work with managed C++. I have 
> tried approaching the problem from 2 directions.
> 
> 1, Create a managed C++ project (Windows forms app or .NET class library). 
> Include some itk headers and a bit of itk code in the form or in a managed 
> class. Copy the Additional Include Directories, Additional Library 
> Directories and Additional Dependencies lines from a CMake generated 
> unmanaged project (which compiles just fine) to the current project 
> properties. Upon compilation I get the errors below.
> 
> 2, Create an unmanaged project using CMake with ITK set up. Set Use 
> Managed Extensions to Yes in the project properties. Add a new item to the 
> project like a .NET form. I get a message box with the error:
> 
> Managed components can only be added to managed projects. Please convert 
> the project to managed. 
> 
> 
> I am obviously missing something. Can you tell me how you set up a project 
> so these things work together?
> 
> Thanks,
> 
> Nick
> 
> 
> <begin managed code>
> 
> // ITKWrapper.h
> 
> #pragma once
> 
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> 
> using namespace System;
> 
> namespace ITKWrapper
> {
> 
>         public __gc class ConvertITKWrapper
>         {
>                 public:
>                         void doConversion(char *fname1, char *fname2)
>                         {
>                                 // Read in the image 
>                                 typedef  unsigned int PixelType;
>                                 typedef itk::Image< PixelType,  2 >   ImageType;
>                                 typedef itk::ImageFileReader< ImageType >  ReaderType;
> 
>                                 ReaderType::Pointer reader = 
> ReaderType::New();
>                                 reader->SetFileName( fname1 );
> 
>                                 reader->Update();
>                         }
>         };
> }
> 
> <end managed code>
> 
> <begin compile errors>
> 
> Compiling...
> ITKWrapper.cpp
> c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(134) : warning 
> C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
> /GR-; unpredictable behavior may result
> c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(135) : warning 
> C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
> /GR-; unpredictable behavior may result
> c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(136) : warning 
> C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
> /GR-; unpredictable behavior may result
....
...more output was truncated....
...





More information about the Insight-users mailing list