The C + + notation is:
LRESULT cpicturequerydlg::onquerypicnty (WPARAM WP, LPARAM LP)
{
EnableWindow (TRUE);
BYTE *pbymsg = (byte*) LP;
Get the current page number
M_dwcurcount = *reinterpret_cast<dword*> (pbymsg);
Get the total quantity
M_dwtotalcount = *reinterpret_cast<dword*> (pbymsg + sizeof (DWORD));
Get the query result pointer
tnvr_pic_grabtask* ptresultquery = reinterpret_cast<tnvr_pic_grabtask*> (pbymsg + sizeof (DWORD));
memset (m_atgrtask, 0, sizeof (tnvr_pic_grabtask) * nvr_maxnum_recordquery);
memcpy (M_atgrtask, ptresultquery, M_dwcurcount * sizeof (tnvr_pic_grabtask));
}
You've got IntPtr. You can use type casting to get something in IntPtr:
?
123 |
(要获取的类型)Marshal.PtrToStructure(ptr, typeof (要获取的类型)); //这样就转换到你c#可以操作的数据类型然后来读取内容, //我不知道这个在你那里能否适用,因为PtrToStructure并不是所有情况都适用,如果用这个方法的话具体可以看看MSDN |
The main thing is to get the length of the type, and if the length gets inaccurate, the data read will be problematic.
(Structuretype) Marshal.PtrToStructure ((INTPTR) ((UINT) (pbymsg + sizeof (UINT) * 2 + i * marshal.sizeof (typeof (Structuretype))), typeof ( Structuretype));
?
123456789101112131415161718192021222324252627 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace OpenCover.Framework.Communication
{
public interface IMarshalWrapper
{
T PtrToStructure<T>(IntPtr pinnedMemory);
void StructureToPtr<T>(T structure, IntPtr pinnedMemory,
bool fDeleteOld);
}
public class MarshalWrapper : IMarshalWrapper
{
public T PtrToStructure<T>(IntPtr pinnedMemory)
{
return (T)Marshal.PtrToStructure(pinnedMemory,
typeof
(T));
}
public void StructureToPtr<T>(T structure, IntPtr pinnedMemory,
bool fDeleteOld)
{
Marshal.StructureToPtr(structure, pinnedMemory, fDeleteOld);
}
}
}
|
C # reads the data from the IntPtr