如何在窗口消息过程中使用IntPtr

zhangyaoqi_17 2008-10-27 11:55:12
DLL, Win32 Code
int* rgbptr = NULL;

::SendMessage(_mainHandle, HM_GETSUBPIC, 0, (LPARAM)&rgbptr);

EXE, CLR Code

void Form1::WndProc(Message% m){
switch ( m.Msg )
{
case HM_GETSUBPIC:
{
Bitmap^ bmp = this->form2->GetPictureboxImg();
Rectangle rect = Rectangle(0,0,bmp->Width,bmp->Height);

// Lock the bitmap's bits.
Imaging::BitmapData^ bmpData = bmp->LockBits( rect, 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.
// This code is specific to a bitmap with 24 bits per pixels.
int bytes = bmpData->Stride * bmp->Height;


// 请问,怎么把这段内存赋给DLL里的rgbptr指针??

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

break;
}
...全文
78 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangyaoqi_17 2008-10-27
  • 打赏
  • 举报
回复
就是DLL里怎么取得EXE里图像RGB数组的指针问题
zhangyaoqi_17 2008-10-27
  • 打赏
  • 举报
回复

我自己想了想
struct IMGSTR{
char* mem;
int size;
};
DLL里这样,
IMGSTR img;

::sendMessage(nppData._mainHandle, HM_GETSUBPIC, 0, (LPARAM)&img);

那么EXE里应该是’

(*((IMGSTR *)m.LParam.ToInt32())).mem = (char*)ptr.ToPointer();

(*((IMGSTR *)m.LParam.ToInt32())).size = bytes;

试验一下也可以。不过看起来好复杂,大家有没有更好的办法》?

7,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧