C++ DLL에서 생성한 Instance를 Parameter로 Return 받고자 할때
1.C++ DLL에서 void** pInstance형으로 전달 받기
Ex) int LoadDICOMImage( void ** hImage) { *hImage = (void*)new DicomImage(); }
2.C#에서 해당 DLL Function 선언시 ref IntPtr로 설정
Ex) [DllImport(“DCMTKInterface.dll”)] public static extern int LoadDICOMImage( ref IntPtr hDicomImage)
3.C# Main에서 해당 함수 호출시 IntPtr 전달 및 ref 설정
Ex) IntPtr hDicomImage = new IntPtr(); DCMTKInterface.LoadDICOMImage( ref hDicomImage)
C++ DLL에 long과 같이 일반자료형 call by reference로 return 받기
1.C++ DLL에서 long*형으로 전달 받기
Ex) int GetImageBufferLength(void* hDicomImage, long* nBufferSize)
2.C#에서 해당 DLL Function 선언시 ref long로 설정
Ex) [DllImport(“DCMTKInterface.dll”)] public static extern int GetImageBufferLength( ref long nBufferSize)
3.C# Main에서 해당 함수 호출시 long 전달 및 ref 설정
Ex) long nBufferSize = 0; DCMTKInterface.GetImageBufferLength(hDicomImage, ref nBufferSize);
C++ DLL에 byte[]같이 배열을 전달하여 값 삽입후 return 받기
1.C++ DLL에서 byte*형으로 전달 받기, Array size도 같이 전달
Ex) int GetImageBuffer(void* hDicomImage, byte* pBufferData, long nBufferSize)
2.C#에서 해당 DLL Function 선언시 byte[]로 설정
Ex) [DllImport(“DCMTKInterface.dll”)] public static extern int GetImageBuffer (IntPtr hDicomImage, byte[] pBufferData, long nBufferSize);
3.C# Main에서 해당 함수 호출시 Memory 할당 후 전달
Ex) byte[] pBuffer = new byte[nBufferSize]; DCMTKInterface. GetImageBuffer (hDicomImage, pBuffer, nBufferSize );