Greetings.
I have a job that needs to process 16-bit images so that they can be displayed normally in ASP.NET webForm.
The professor gave me a C++ file, which is a code written by the professor’s prospective doctoral student.
Because I don’t have enough experience with C++ and C#, I tried for a week and still no results.
The file content given by the professor includes .pdb, .lib, .ilk, .exp, .dll
In the .h file, it can see the code, And I know that C# needs to read the code from the .dll.
This is the code in C++ .h file.
struct CImage_DLL
{
int m_nW, m_nH;
short* pshImageData;
CImage_DLL() : m_nW(0), m_nH(0), pshImageData(nullptr){}
};
extern "C" MoveFullImageByFirstImage_API CImage_DLL* Open16BitGrayImage(
const char* strSrcImageFilePath);
What I have tried:
And this is the code in C#
public Form1()
{
InitializeComponent();
}
[DllImport("D:\\image_16bit_code\\MoveFullImageByFirstImage.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr Open16BitGrayImage(string imgFile);
private void button7_Click(object sender, EventArgs e)
{
string imgUrl = "D:\\image_16bit_code\\Image Mapping\\MRI-PDI_Axial-Z\\MRI-PDI_Axial-Z_0110.png";
CImage_DLL _DLL = (CImage_DLL)Marshal.PtrToStructure(Open16BitGrayImage(imgUrl), typeof(CImage_DLL));
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct CImage_DLL
{
[MarshalAs(UnmanagedType.SysInt)]
public int m_nW, m_nH;
[MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_I2)]
public IntPtr[] pshImageData;
};
I tried many different variables and many people’s different methods. Configuration build has tried to use x86 and x64.
The error code always appears (Exception from HRESULT: 0x8007000B)
When the image path is correct, all I can think of is the problem with the definition of the variable of an array in the structure. The value in the array will be one-dimensional, and the size is an array of image length * width, The value is 16bit.
Any help? I have no idea what I need to do to read the value I need?