Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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


--------------------------------------------------------------------------
C# Code
C#
[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
C++
[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测试界面,显示图片用
    a->ImageEnView2->IO->LoadFromBuffer(photo,0,len);  
    a->Show();

}
Posted
Updated 18-Jul-17 20:44pm
Comments
Sergey Alexandrovich Kryukov 24-Jun-14 23:59pm    
Why would you ask such question, not showing the implementation of testShowFormC? What's the use?
—SA

1 solution

This simply makes no sense, at least the code you show. In both C# and C++ pieces, you only import some function from dllTestForm.DLL, but show no implementation. There is no guarantee that it is implemented properly or even exists. More importantly, it's not clear how the bitmap is supposed to be show, as you don't pass to this function anything which could be used to render the image; no graphic content, no handle for some control where the image should be shown. It's quite doubtful that the image can be shown based on the function with such signature.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900