Wrapper z C++ do C#

0

Hej ;)

Jestem w trakcie pisania wrappera do C# ....
Mam problem gdyz program dziala mi na moim kompie .. gdzie mam wszystkie biblioteki z C++ itd..
W C# odpala sie wszystko ok;)

Natomiast problem przychodzi kiedy uruchamiam go na innej maszynie ;/
Build przechodzi ok - natomiast visual wywala mi bland przy kompilacji

**Nie można załadować biblioteki DLL 'LandmarkIGSTK.dll': Nie można odnaleźć określonego modułu. (Wyjątek od HRESULT: 0x8007007E)
**

Jesli to możliwe bardzo prosilabym o jakas pomoc, good advice ?
Mecze sie juz z tym pare miesiecy ...;/

Kod z c++ do utworzenia dll - ki :


#if defined(_MSC_VER)
//Warning about: identifier was truncated to '255' characters in the 
//debug information (MVC6.0 Debug)
#pragma warning( disable : 4786 )
#endif

// BeginLatex
// 
// This example illustrates how to use IGSTK's landmark registration 
// component to determine rigid body transformation parameters between 
// an image and the patient coordinate system.
//
// EndLatex

#include <iostream>

// BeginLatex
// 
// To use the registration component, the header file for 
// \doxygen{Landmark3DRegistration} is added:
//
// EndLatex

// BeginCodeSnippet
#include "igstkLandmark3DRegistration.h"
// EndCodeSnippet


#include "igstkLogger.h"
#include "itkStdStreamLogOutput.h"
#include "itkObject.h"
#include "itkCommand.h"
#include "itkMacro.h"

// BeginLatex
// 
// Transform parameters are returned to the application using loaded events. 
// To handle these events, the following \doxygen{Events} 
// and \doxygen{Transform} header files are needed:
//
// EndLatex

// BeginCodeSnippet
#include "igstkEvents.h"
#include "igstkTransform.h"
#include "igstkCoordinateSystemTransformToResult.h" 
// EndCodeSnippet


// BeginLatex
// 
// To fully  utilize the registration component, callbacks need to be set up 
// to observe events that could be thrown by the registration component.  
// For this purpose, the ITK command class is used to derive a callback class.
// The ITK command class implements a subject/observer (command design) pattern.
// A subject notifies an observer by running the \code{Execute } method of 
// the derived callback class. For example, a callback class meant 
// to observe an error in the transform computation is defined as follows:
// 
// EndLatex





// BeginCodeSnippet
class Landmark3DRegistrationErrorCallback : public itk::Command
{
public:
  typedef Landmark3DRegistrationErrorCallback Self;
  typedef itk::SmartPointer<Self>             Pointer;
  typedef itk::Command                        Superclass;
  itkNewMacro(Self);
  void Execute(const itk::Object * itkNotUsed(caller), const itk::EventObject & itkNotUsed(event))
    {

    }
  void Execute(itk::Object * itkNotUsed(caller), const itk::EventObject & itkNotUsed(event))
    {
    std::cerr<<"Error in transform computation"<<std::endl;
    }
protected:
  Landmark3DRegistrationErrorCallback() {};

private:
};
//EndCodeSnippet


class Landmark3DRegistrationInvalidRequestCallback : public itk::Command
{
public:
  typedef Landmark3DRegistrationInvalidRequestCallback Self;
  typedef itk::SmartPointer<Self>                      Pointer;
  typedef itk::Command                                 Superclass;
  itkNewMacro(Self);
  void Execute(const itk::Object * itkNotUsed(caller), const itk::EventObject & itkNotUsed(event) )
    {

    }
  void Execute(itk::Object * itkNotUsed(caller), const itk::EventObject & itkNotUsed(event) )
    {
    std::cerr<<"Invalid input request!!"<<std::endl;
    }
protected:
  Landmark3DRegistrationInvalidRequestCallback() {};

private:
};

// BeginLatex
// 
// Similarly, a callback class needs to be defined to observe the
// \doxygen{CoordinateSystemTransformToEvent} event. This event is loaded with
// transform parameters that are computed by the registration component.  The
// commands are as follows:
// EndLatex

// BeginCodeSnippet
class Landmark3DRegistrationGetTransformCallback: public itk::Command
{
public:
  typedef Landmark3DRegistrationGetTransformCallback    Self;
  typedef itk::SmartPointer<Self>                       Pointer;
  typedef itk::Command                                  Superclass;
  itkNewMacro(Self);

  typedef igstk::CoordinateSystemTransformToEvent TransformEventType;
  
  void Execute( const itk::Object * itkNotUsed(caller), const itk::EventObject & itkNotUsed(event) )
    {
    }
 
  void Execute( itk::Object * itkNotUsed(caller), const itk::EventObject & event )
    {
    std::cout<< " TransformEvent is thrown" << std::endl;
    const TransformEventType * transformEvent =
      dynamic_cast < const TransformEventType* > ( &event );

    const igstk::CoordinateSystemTransformToResult transformCarrier =
      transformEvent->Get();

    m_Transform = transformCarrier.GetTransform();

    m_EventReceived = true;
    } 
  bool GetEventReceived()
    {
    return m_EventReceived;
    }
  igstk::Transform GetTransform()
    {
    return m_Transform;
    }  
protected:

  Landmark3DRegistrationGetTransformCallback()   
    {
    m_EventReceived = true;
    }

private:
  bool m_EventReceived;
  igstk::Transform m_Transform;
};
// EndCodeSnippet


// BeginLatex
// 
// For more information on IGSTK events, see Chapter~\ref{Chapter:Events}.
// After the helper classes are defined, the main function implementation 
// is started, as follows:
//
// EndLatex



extern "C"
{


__declspec(dllexport) void __stdcall Rejestracja( double tab[30], double* pReturn)
  {
// EndCodeSnippet


  igstk::RealTimeClock::Initialize();


// BeginLatex
//
// Next, all the necessary data types are defined:
// 
// EndLatex

// BeginCodeSnippet
  typedef igstk::Object::LoggerType             LoggerType;
  typedef itk::StdStreamLogOutput               LogOutputType;
    
  typedef igstk::Landmark3DRegistration
                            Landmark3DRegistrationType;
  typedef igstk::Landmark3DRegistration::LandmarkPointContainerType
                            LandmarkPointContainerType;
  typedef igstk::Landmark3DRegistration::LandmarkImagePointType 
                            LandmarkImagePointType;
  typedef igstk::Landmark3DRegistration::LandmarkTrackerPointType
                            LandmarkTrackerPointType;
  typedef Landmark3DRegistrationType::TransformType::OutputVectorType 
                            OutputVectorType;
  typedef igstk::Transform  TransformType;
// EndCodeSnippet


// BeginLatex
// 
// Then, the registration component is instantiated as follows:
// 
// EndLatex

// BeginCodeSnippet
  Landmark3DRegistrationType::Pointer landmarkRegister = 
                                        Landmark3DRegistrationType::New();
// EndCodeSnippet
 

// BeginLatex
// 
// Next, the landmark containers that hold the landmark image and tracker 
// coordinates are instantiated:
//
// EndLatex

// BeginCodeSnippet
  LandmarkPointContainerType  imagePointContainer;
  LandmarkPointContainerType  trackerPointContainer;
// EndCodeSnippet


  LandmarkImagePointType      imagePoint;
  LandmarkTrackerPointType    trackerPoint;

// BeginLatex
// 
// Then, error event callback objects are instantiated and added to the observer
// list of the registration component, as follows:
//
// EndLatex

// BeginCodeSnippet
  Landmark3DRegistrationInvalidRequestCallback::Pointer 
                  lrcb = Landmark3DRegistrationInvalidRequestCallback::New();
    
  typedef igstk::InvalidRequestErrorEvent  InvalidRequestEvent;

  landmarkRegister->AddObserver( InvalidRequestEvent(), lrcb );

  Landmark3DRegistrationErrorCallback::Pointer ecb = 
                  Landmark3DRegistrationErrorCallback::New();
  typedef igstk::Landmark3DRegistration::TransformComputationFailureEvent 
                                                     ComputationFailureEvent;
  landmarkRegister->AddObserver( ComputationFailureEvent(), ecb );

// EndCodeSnippet

// BeginLatex
// 
// A logger can then be connected to the registration component for 
// debugging purpose, as follows:
//
// EndLatex


// BeginCodeSnippet 
  LoggerType::Pointer   logger = LoggerType::New();
  LogOutputType::Pointer logOutput = LogOutputType::New();
  logOutput->SetStream( std::cout );
  logger->AddLogOutput( logOutput );
  logger->SetPriorityLevel( LoggerType::DEBUG );
  landmarkRegister->SetLogger( logger );
// EndCodeSnippet
   

// BeginLatex
//
// Next, landmark points are added to the image and tracker containers.  The
// state machine of this registration component is designed so that the image
// and tracker coordinates that correspond to each landmark are added
// consecutively. This scheme prevents the mismatch in landmark correspondence
// that could occur when all landmarks image coordinates are recorded first and
// followed by the tracker coordinates.  This design choice is consistent with
// the ``safety by design'' philosophy of IGSTK. The commands are as follows:
//
//EndLatex 

// BeginCodeSnippet
  // Add 1st landmark
  imagePoint[0] = tab[0];
  imagePoint[1] = tab[1];
  imagePoint[2] = tab[2];
  imagePointContainer.push_back(imagePoint);
  landmarkRegister->RequestAddImageLandmarkPoint(imagePoint);

  trackerPoint[0] = tab[3];
  trackerPoint[1] = tab[4];
  trackerPoint[2] = tab[5];
  trackerPointContainer.push_back(trackerPoint);
  landmarkRegister->RequestAddTrackerLandmarkPoint(trackerPoint);

  // Add 2nd landmark
  imagePoint[0] = tab[6];
  imagePoint[1] = tab[7];
  imagePoint[2] = tab[8];
  imagePointContainer.push_back(imagePoint);
  landmarkRegister->RequestAddImageLandmarkPoint(imagePoint);
    
  trackerPoint[0] = tab[9];
  trackerPoint[1] = tab[10];
  trackerPoint[2] = tab[11];
  trackerPointContainer.push_back(trackerPoint);
  landmarkRegister->RequestAddTrackerLandmarkPoint(trackerPoint);

  // Add 3d landmark
  imagePoint[0] = tab[12];
  imagePoint[1] = tab[13];
  imagePoint[2] = tab[14];
  imagePointContainer.push_back(imagePoint);
  landmarkRegister->RequestAddImageLandmarkPoint(imagePoint);

  trackerPoint[0] = tab[15];
  trackerPoint[1] = tab[16];
  trackerPoint[2] = tab[17];
  trackerPointContainer.push_back(trackerPoint);
  landmarkRegister->RequestAddTrackerLandmarkPoint(trackerPoint);

  // EndCodeSnippet

  // BeginLatex
  // 
  // More landmarks can be added for the transform computation.  
  // 
  // EndLatex

  // Add 4th landmark
  imagePoint[0] = tab[18];
  imagePoint[1] = tab[19];
  imagePoint[2] = tab[20];
  imagePointContainer.push_back(imagePoint);
  landmarkRegister->RequestAddImageLandmarkPoint(imagePoint);

  trackerPoint[0] = tab[21];
  trackerPoint[1] = tab[22];
  trackerPoint[2] = tab[23];
  trackerPointContainer.push_back(trackerPoint);
  landmarkRegister->RequestAddTrackerLandmarkPoint(trackerPoint);

   // Add 5th landmark
  imagePoint[0] = tab[24];
  imagePoint[1] = tab[25];
  imagePoint[2] = tab[26];
  imagePointContainer.push_back(imagePoint);
  landmarkRegister->RequestAddImageLandmarkPoint(imagePoint);

  trackerPoint[0] = tab[27];
  trackerPoint[1] = tab[28];
  trackerPoint[2] = tab[29];
  trackerPointContainer.push_back(trackerPoint);
  landmarkRegister->RequestAddTrackerLandmarkPoint(trackerPoint);

  // BeginLatex
  // 
  // After all landmark coordinates are added, the transform computation is 
  // requested as follows:
  // 
  // EndLatex

  // Calculate transform

  // BeginCodeSnippet
  landmarkRegister->RequestComputeTransform();
  // EndCodeSnippet
     
  typedef itk::VersorRigid3DTransform<double>        VersorRigid3DTransformType;
  typedef VersorRigid3DTransformType::ParametersType ParametersType;

  TransformType      transform;
  ParametersType     parameters(6);

  // BeginLatex
  // 
  // To access the transform parameters, a GetTransform callback is instantiated
  // to observe the transform event, as follows: 
  // 
  // EndLatex

  // BeginCodeSnippet
  Landmark3DRegistrationGetTransformCallback::Pointer lrtcb =
    Landmark3DRegistrationGetTransformCallback::New();

  landmarkRegister->AddObserver( 
    igstk::CoordinateSystemTransformToEvent(), lrtcb );
  //EndCodeSnippet


  // BeginLatex
  //
  // To request that the registration component throw an event loaded with 
  // transform parameters, a \code{RequestGetTransform} function is invoked as 
  // follows:
  // 
  // EndLatex

  // BeginCodeSnippet
  landmarkRegister->RequestGetTransformFromTrackerToImage();
  transform = lrtcb->GetTransform();
  std::cout << "Transform " << transform << std::cout;
  // EndCodeSnippet


if(lrtcb->GetEventReceived()) 
{
  transform = lrtcb->GetTransform();
  vtkMatrix4x4 * t = vtkMatrix4x4::New();;
  transform.ExportTransform( * t );

  for ( int i = 0; i < 3; i++ )
  {
   for ( int j = 0; j < 3; j++ )
    {
      pReturn[4*i+j]  = t->GetElement(i,j);
    }
  }

   t->Delete();

}

    

}
}

 

////////////////////////////////////////////////////////////////////////////////////////////

//c# - UnsafeNativeMethods.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace WrapperLandmark
{

    internal static class UnsafeNativeMethods
    {
        const string dllLocation = "LandmarkIGSTK.dll";

        [DllImport(dllLocation)]
        public static extern void Rejestracja(double[] dane,IntPtr pReturn);

    }
   
}

 

////////////////////////////////////////////////////////////////////////////////////////////

// c#

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WrapperLandmark
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Run();
        }

        public static void Run()
        {
            double[] dane = new double[30];

            #region Dane
            dane[0] = 25.0;
            dane[1] = 1.0;
            dane[2] = 15.0;
            dane[3] = 29.8;
            dane[4] = -5.3;
            dane[5] = 25.0;
            dane[6] = 15.0;
            dane[7] = 21.0;
            dane[8] = 17.0;
            dane[9] = 35.0;
            dane[10] = 16.5;
            dane[11] = 27.0;
            dane[12] = 14.0;
            dane[13] = 25.0;
            dane[14] = 11.0;
            dane[15] = 36.8;
            dane[16] = 20.0;
            dane[17] = 21.0;
            dane[18] = 10.0;
            dane[19] = 11.0;
            dane[20] = 8.0;
            dane[21] = 24.7;
            dane[22] = 12.0;
            dane[23] = 18.0;
            dane[24] = 26.0;
            dane[25] = 2.0;
            dane[26] = 16.0;
            dane[27] = 30.5;
            dane[28] = -6.6;
            dane[29] = 26.0;
            #endregion Dane

           // UnsafeNativeMethods.Rejestracja(dane);
            double[] wynik = new double[16];
            IntPtr pWynik = Marshal.AllocHGlobal(16 * 8);
            UnsafeNativeMethods.Rejestracja(dane, pWynik);
            Marshal.Copy(pWynik, wynik, 0, 16);
            string wynikShow = string.Empty;

            for (int i = 0; i < 16; i++)
            {
                wynikShow = wynikShow + i.ToString() + "  " + wynik[i].ToString() + "\n";

            }

            MessageBox.Show(wynikShow);
            Marshal.FreeHGlobal(pWynik);

        }

    }
    }


1

Wygląda na to, że plik dll jest w innym katalogu, niż plik exe z projektu c#.

0

nie właśnie mam w folderze debug projektu w c# ..
dodałam tam tą dll-kę... ?

0

Hej ;)

noo własnie mam tą dll-ke w katalogu tym samym co debug z c# ...

i build succesed natomiast wywala sie przy debugowaniu ...

Tu output:

 
'WrapperLandmark.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'WrapperLandmark.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\mscorlib.resources\2.0.0.0_pl_b77a5c561934e089\mscorlib.resources.dll'
'WrapperLandmark.exe' (Managed): Loaded 'C:\Wrapper17.10-3\WrapperLandmark\bin\Debug\WrapperLandmark.exe', Symbols loaded.
'WrapperLandmark.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'WrapperLandmark.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'WrapperLandmark.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'WrapperLandmark.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'WrapperLandmark.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'WrapperLandmark.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
A first chance exception of type 'System.DllNotFoundException' occurred in WrapperLandmark.exe

A jak sprobowalam na projekcie console api z c# ... noo dosc ciezko .. nawet na moim kompie nie idzie ;//

Nie wiem czy to czasem nie jest problem z typem IntPtr ... ?

IntPtr pWynik = Marshal.AllocHGlobal(16 * 8);
UnsafeNativeMethods.Rejestracja(dane, pWynik);
 
0

A jak u mnie na kompie odpalam tą dll-ke to wszystko smiga good ;)

i przechodzi .. i oblicza jak nalezy ..

Tu moj output :

'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'
'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'
'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'
'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll'
'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'
'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'
'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\mscorlib.resources\2.0.0.0_pl_b77a5c561934e089\mscorlib.resources.dll'
'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Wrapper17.10-3\WrapperConsole\bin\Debug\WrapperConsole.vshost.exe'
'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll'
'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089\System.Xml.Linq.dll'
'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Data.DataSetExtensions\3.5.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'
'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll'
'WrapperConsole.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll'
The thread 0x17d0 has exited with code 0 (0x0).
The thread 0x9ac has exited with code 0 (0x0).
The thread 0x4f8 has exited with code 0 (0x0).
The thread 0x10d8 has exited with code 0 (0x0).
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\mscorlib.resources\2.0.0.0_pl_b77a5c561934e089\mscorlib.resources.dll'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Wrapper17.10-3\WrapperLandmark\bin\Debug\WrapperLandmark.vshost.exe'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089\System.Xml.Linq.dll'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Data.DataSetExtensions\3.5.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Deployment\2.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll'
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll'
The thread 0x15e0 has exited with code 0 (0x0).
The program '[5252] WrapperConsole.vshost.exe: Managed' has exited with code 0 (0x0).
The thread 0x10d4 has exited with code 0 (0x0).
'WrapperLandmark.vshost.exe' (Managed): Loaded 'C:\Wrapper17.10-3\WrapperLandmark\bin\Debug\WrapperLandmark.exe', Symbols loaded.
24607975290.513474  :    (DEBUG) igstk::Landmark3DRegistration::RequestAddImageLandmarkPoint called...
24607975290.513603  :    (DEBUG) State transition is being made : Landmark3DRegistration  PointerID 05BDFD28 IdleState(1)  with ImageLandmarkInput(10) ---> ImageLandmark1AddedState(2).
24607975290.513672  :    (DEBUG) igstk::Landmark3DRegistration::AddImageLandmarkPointProcessing called...
24607975290.513733  :    (DEBUG) igstk::Landmark3DRegistration::RequestAddTrackerLandmarkPoint called...
24607975290.513824  :    (DEBUG) State transition is being made : Landmark3DRegistration  PointerID 05BDFD28 ImageLandmark1AddedState(2)  with TrackerLandmarkInput(11) ---> TrackerLandmark1AddedState(3).
24607975290.513893  :    (DEBUG) igstk::Landmark3DRegistration::AddTrackerLandmarkPointProcessing called...
24607975290.513958  :    (DEBUG) igstk::Landmark3DRegistration::RequestAddImageLandmarkPoint called...
24607975290.514053  :    (DEBUG) State transition is being made : Landmark3DRegistration  PointerID 05BDFD28 TrackerLandmark1AddedState(3)  with ImageLandmarkInput(10) ---> ImageLandmark2AddedState(4).
24607975290.514137  :    (DEBUG) igstk::Landmark3DRegistration::AddImageLandmarkPointProcessing called...
24607975290.514202  :    (DEBUG) igstk::Landmark3DRegistration::RequestAddTrackerLandmarkPoint called...
24607975290.514294  :    (DEBUG) State transition is being made : Landmark3DRegistration  PointerID 05BDFD28 ImageLandmark2AddedState(4)  with TrackerLandmarkInput(11) ---> TrackerLandmark2AddedState(5).
24607975290.514359  :    (DEBUG) igstk::Landmark3DRegistration::AddTrackerLandmarkPointProcessing called...
24607975290.514423  :    (DEBUG) igstk::Landmark3DRegistration::RequestAddImageLandmarkPoint called...
24607975290.514515  :    (DEBUG) State transition is being made : Landmark3DRegistration  PointerID 05BDFD28 TrackerLandmark2AddedState(5)  with ImageLandmarkInput(10) ---> ImageLandmark3AddedState(6).
24607975290.51458  :    (DEBUG) igstk::Landmark3DRegistration::AddImageLandmarkPointProcessing called...
24607975290.514645  :    (DEBUG) igstk::Landmark3DRegistration::RequestAddTrackerLandmarkPoint called...
24607975290.514736  :    (DEBUG) State transition is being made : Landmark3DRegistration  PointerID 05BDFD28 ImageLandmark3AddedState(6)  with TrackerLandmarkInput(11) ---> TrackerLandmark3AddedState(7).
24607975290.514801  :    (DEBUG) igstk::Landmark3DRegistration::AddTrackerLandmarkPointProcessing called...
24607975290.514866  :    (DEBUG) igstk::Landmark3DRegistration::RequestAddImageLandmarkPoint called...
24607975290.514961  :    (DEBUG) State transition is being made : Landmark3DRegistration  PointerID 05BDFD28 TrackerLandmark3AddedState(7)  with ImageLandmarkInput(10) ---> ImageLandmark3AddedState(6).
24607975290.515022  :    (DEBUG) igstk::Landmark3DRegistration::AddImageLandmarkPointProcessing called...
24607975290.515087  :    (DEBUG) igstk::Landmark3DRegistration::RequestAddTrackerLandmarkPoint called...
24607975290.515182  :    (DEBUG) State transition is being made : Landmark3DRegistration  PointerID 05BDFD28 ImageLandmark3AddedState(6)  with TrackerLandmarkInput(11) ---> TrackerLandmark3AddedState(7).
24607975290.515247  :    (DEBUG) igstk::Landmark3DRegistration::AddTrackerLandmarkPointProcessing called...
24607975290.515312  :    (DEBUG) igstk::Landmark3DRegistration::RequestAddImageLandmarkPoint called...
24607975290.515404  :    (DEBUG) State transition is being made : Landmark3DRegistration  PointerID 05BDFD28 TrackerLandmark3AddedState(7)  with ImageLandmarkInput(10) ---> ImageLandmark3AddedState(6).
24607975290.515469  :    (DEBUG) igstk::Landmark3DRegistration::AddImageLandmarkPointProcessing called...
24607975290.51553  :    (DEBUG) igstk::Landmark3DRegistration::RequestAddTrackerLandmarkPoint called...
24607975290.515625  :    (DEBUG) State transition is being made : Landmark3DRegistration  PointerID 05BDFD28 ImageLandmark3AddedState(6)  with TrackerLandmarkInput(11) ---> TrackerLandmark3AddedState(7).
24607975290.51569  :    (DEBUG) igstk::Landmark3DRegistration::AddTrackerLandmarkPointProcessing called...
24607975291.130787  :    (DEBUG) igstk::Landmark3DRegistration::RequestComputeTransform called...
24607975291.130985  :    (DEBUG) State transition is being made : Landmark3DRegistration  PointerID 05BDFD28 TrackerLandmark3AddedState(7)  with ComputeTransformInput(12) ---> AttemptingToComputeTransformState(8).
24607975291.131107  :    (DEBUG) igstk::Landmark3DRegistration::ComputeTransformProcessing called...
24607975291.131367  :    (DEBUG) igstk::Landmark3DRegistration::ComputeRMSError called..
24607975291.131466  :    (DEBUG) ComputationSuccessInput getting pushed24607975291.131641  :    (DEBUG) State transition is being made : Landmark3DRegistration  PointerID 05BDFD28 AttemptingToComputeTransformState(8)  with TransformComputationSuccessInput(18) ---> TransformComputedState(9).
24607975291.131767  :    (DEBUG) igstk::Landmark3DRegistration::ReportSuccessInTransformComputationProcessing called...
24607975291.131958  :    (DEBUG) igstk::Landmark3DRegistration::RequestGetTransformFromTrackerToImage called...
24607975291.13213  :    (DEBUG) State transition is being made : Landmark3DRegistration  PointerID 05BDFD28 TransformComputedState(9)  with GetTransformFromTrackerToImageInput(13) ---> TransformComputedState(9).
24607975291.132248  :    (DEBUG) igstk::Landmark3DRegistration::                      GetTransformFromTrackerToImageProcessing called...
 TransformEvent is thrown
Transform Transform (0601E3F8)
  RTTI typeinfo:   class igstk::Transform
  TimeStamp (0601E400)
    RTTI typeinfo:    class igstk::TimeStamp
    Start Time      = 24607975291132.309
    Expiration Time = 1.7976931348623157e+308
  [-0.95629681626022012, -14.106299975633698, -9.9176309387568526]
  [ -0.0021089430769123947, 0.0001336418508793431, 0.34805956781166209, 0.93747003778985549 ]
  0.60753474054696643
5710CACC
 
1

zamiast

double[] wynik = new double[16];
IntPtr pWynik = Marshal.AllocHGlobal(16 * 8);
UnsafeNativeMethods.Rejestracja(dane, pWynik);
Marshal.Copy(pWynik, wynik, 0, 16);
...
Marshal.FreeHGlobal(pWynik);

można dać

double* wynik = stackalloc double[16];
UnsafeNativeMethods.Rejestracja(dane, wynik);

nie trzeba Marshali, nie trzeba pamiętać o zwalnianiu: tablica jest na stosie, jest niszczona gdy wyjdzie z zasięgu.

0

Noo to zmieniłam ..
Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WrapperLandmark
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Run();
        }

        public static void Run()
        {
            double[] dane = new double[30];

            #region Dane
            dane[0] = 25.0;
            dane[1] = 1.0;
            dane[2] = 15.0;
            dane[3] = 29.8;
            dane[4] = -5.3;
            dane[5] = 25.0;
            dane[6] = 15.0;
            dane[7] = 21.0;
            dane[8] = 17.0;
            dane[9] = 35.0;
            dane[10] = 16.5;
            dane[11] = 27.0;
            dane[12] = 14.0;
            dane[13] = 25.0;
            dane[14] = 11.0;
            dane[15] = 36.8;
            dane[16] = 20.0;
            dane[17] = 21.0;
            dane[18] = 10.0;
            dane[19] = 11.0;
            dane[20] = 8.0;
            dane[21] = 24.7;
            dane[22] = 12.0;
            dane[23] = 18.0;
            dane[24] = 26.0;
            dane[25] = 2.0;
            dane[26] = 16.0;
            dane[27] = 30.5;
            dane[28] = -6.6;
            dane[29] = 26.0;
            #endregion Dane

           // UnsafeNativeMethods.Rejestracja(dane);
            //double[] wynik = new double[16];
            //IntPtr pWynik = Marshal.AllocHGlobal(16 * 8);
            //UnsafeNativeMethods.Rejestracja(dane, pWynik);
            //Marshal.Copy(pWynik, wynik, 0, 16);
            double* wynik = stackalloc double[16];
            UnsafeNativeMethods.Rejestracja(dane, wynik);
            string wynikShow = string.Empty;

            for (int i = 0; i < 16; i++)
            {
                wynikShow = wynikShow + i.ToString() + "  " + wynik[i].ToString() + "\n";

            }

           //  Marshal.FreeHGlobal(pWynik);

        }

    }
    }

 

Ale wywala mi jeszcze teraz error z ..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;


namespace WrapperLandmark
{

    internal static class UnsafeNativeMethods
    {
        const string dllLocation = "LandmarkIGSTK.dll";

        [DllImport(dllLocation)]
       public static extern void Rejestracja(double[] dane,double* pReturn); // tu było IntPtr pReturn   ????????

    }
   
}

 
1

jaki błąd ci wyskakuje?

brakuje słowa unsafe.

0

Noo wyskakuje mi blad na tej linii ...:

 public static extern void Rejestracja(double[] dane,  double* pReturn); // Error	1	Pointers and fixed size buffers may only be used in an unsafe context	// C:\Wrapper17.10-3\WrapperLandmark\UnsafeNativeMethods.cs	

 

A gdzie dokładnie wstawić te unsafe ? ??

1

Jak już wspomniał @Azarien: brakuje słowa unsafe.

0

Jak daje unsafa to wywala mi nadal 2 bledy ..;/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;


namespace WrapperLandmark
{

    internal static class UnsafeNativeMethods
    {
        const string dllLocation = "LandmarkIGSTK.dll";

        [DllImport(dllLocation)]
        public static extern void Rejestracja(double[] dane, unsafe double *pReturn);  // ??

    }
   
}
 

Error 1 Type expected \UnsafeNativeMethods.cs
Error 2 ; expected \UnsafeNativeMethods.cs

1

Skąd pomysł, że wstawienie jakiegoś słowa w losowe miejsce rozwiąże problem? :|

Tak trudno skorzystać z dokumentacji?
http://msdn.microsoft.com/en-us/library/chfa2zb8%28v=VS.100%29.aspx
http://msdn.microsoft.com/en-us/library/t2yzs44b.aspx

1

najlepiej tutaj

 internal static unsafe class UnsafeNativeMethods

albo przy każdej metodzie osobno.

0

hej :)

Noo właśnie pozmieniałam, wszedzie dodalam unsafe i dalej mi nie idzie ..
build success ale przy kompilacji - debug zglasza wyjatek nie mozna zaladowac ...dll , nie można zaladowac okreslonego modulu ..
(screen)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WrapperLandmark
{
   unsafe public partial class Form1 : Form
    {
       unsafe public Form1()
        {
            InitializeComponent();
            Run();
        }

     unsafe public static void Run()
        {
            double[] dane = new double[30];

            #region Dane
            dane[0] = 25.0;
            dane[1] = 1.0;
            dane[2] = 15.0;
            dane[3] = 29.8;
            dane[4] = -5.3;
            dane[5] = 25.0;
            dane[6] = 15.0;
            dane[7] = 21.0;
            dane[8] = 17.0;
            dane[9] = 35.0;
            dane[10] = 16.5;
            dane[11] = 27.0;
            dane[12] = 14.0;
            dane[13] = 25.0;
            dane[14] = 11.0;
            dane[15] = 36.8;
            dane[16] = 20.0;
            dane[17] = 21.0;
            dane[18] = 10.0;
            dane[19] = 11.0;
            dane[20] = 8.0;
            dane[21] = 24.7;
            dane[22] = 12.0;
            dane[23] = 18.0;
            dane[24] = 26.0;
            dane[25] = 2.0;
            dane[26] = 16.0;
            dane[27] = 30.5;
            dane[28] = -6.6;
            dane[29] = 26.0;
            #endregion Dane

            double* wynik = stackalloc double[16];
            UnsafeNativeMethods.Rejestracja(dane, wynik);

           // UnsafeNativeMethods.Rejestracja(dane);
          //  double[] wynik = new double[16];
          // IntPtr pWynik = Marshal.AllocHGlobal(16 * 8);
            
          //  UnsafeNativeMethods.Rejestracja(dane, pWynik);
          // Marshal.Copy(pWynik, wynik, 0, 16);
          //  string wynikShow = string.Empty;

          //  for (int i = 0; i < 16; i++)
          //  {
          //      wynikShow = wynikShow + i.ToString() + "  " + wynik[i].ToString() + "\n";

          //  }

          //  MessageBox.Show(wynikShow);
          ////  Marshal.FreeHGlobal(pWynik[]);

        }

    }
    }


 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace WrapperLandmark
{

   unsafe internal static class UnsafeNativeMethods
    {
        const string dllLocation = "LandmarkIGSTK.dll";

        [DllImport(dllLocation)]
        unsafe public static extern void Rejestracja(double[] dane, double* pReturn);

    }
   
}

Dziwne boo u mnie na kompie gdzie generowalm dll - ke dziala ale jak testuje na innym kompie to niestety.. ;//

1

No jak ty żeś dodał tę bibliotekę jako plik źródłowy do projektu... Ustaw jej chociaż kopiowanie do katalogu z binarką albo ręcznie ją tam wstaw.

0

Nooo właśnie mam to w katalogu bin / debug projektu c# ;)

1

Importy tej biblioteki mówią, że potrzebuje ona jeszcze pliku "vtkcommon.dll".

0

Ok ;)
noo nareszcie uruchomiło sie ;))))
dołączylam jeszcze inne dll-ki, i wreszcie wszystko dziala ...!!

Dzieki Wielkie Wszystkim za pomoc ;)
Thanks

1 użytkowników online, w tym zalogowanych: 0, gości: 1