1 Replies - 2218 Views - Last Post: 24 June 2014 - 08:11 PM Rate Topic: -----

#1 marklr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-July 13

how to pass bitmap data type to c++ dll ?

Posted 24 June 2014 - 08:05 PM

C# Code
[DllImport("dllTestForm.dll", EntryPoint = "showFormC")]
static extern void testShowFormC(byte[] photo,int len);

private void button6_Click(object sender, EventArgs e)
{
		Bitmap bmp = (Bitmap)Image.FromFile(@"d:\1\1.jpg");

		Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
		System.Drawing.Imaging.BitmapData bmpData =
		bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,bmp.PixelFormat);

		// Get the address of the first line.
		IntPtr ptr = bmpData.Scan0;

		// Declare an array to hold the bytes of the bitmap. 
		int bytes  = Math.Abs(bmpData.Stride) * bmp.Height;
		byte[] rgbValues = new byte[bytes];

		 // Copy the RGB values into the array.
		 System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);

		 // Unlock the bits.
		 bmp.UnlockBits(bmpData);

		 testShowFormC(rgbValues, bytes);
}

--------------------------------------------------------------------------
C++ Code
[DllImport("dllTestForm.dll", EntryPoint = "showFormC")]
static extern void testShowFormC(byte[] photo,int len);

void __stdcall showFormC(byte *photo,int len)
{
    ThelloWorld *a=new ThelloWorld(Application); //winForm,display photo
    a->ImageEnView2->IO->LoadFromBuffer(photo,0,len);  
    a->Show();

}



The program has no tip errors ,But there is no any picture display in c++ form,Tested the simple data types, such as int, can be normal delivery,please give me a simple example ,tell me what to do

Is This A Good Question/Topic? 0
  • +

Replies To: how to pass bitmap data type to c++ dll ?

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5949
  • View blog
  • Posts: 20,392
  • Joined: 05-May 12

Re: how to pass bitmap data type to c++ dll ?

Posted 24 June 2014 - 08:11 PM

Did you trace into a->Show() to find out why it is not displaying?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1