Click here to Skip to main content
15,791,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I writted code in c++ environmental as below:
CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(MCDTYPE1), NULL);
MCDTYPE1* pDest = (MCDTYPE1*)MapViewOfFile(hFileMapDest, FILE_MAP_WRITE, 0, 0, 0);

MCDTYPE1 is struct type
set some values to MCDTYPE1 struct member.
pDest = &MCDTYPE1;


but how to get struct value in c#.

What I have tried:

C#
MCDTYPE1 result = (MCDTYPE1 )Marshal.PtrToStructure(mapView, typeof(UIStruct));

it failed to get values of MCDTYPE1.
Posted
Updated 19-Nov-16 2:52am

1 solution

I am needing to make a couple of assumptions here:
1. MCDTYPE1 has been declared in C#, decorated with a StructLayoutAttribute(LayoutKind.Sequential).
2. You've somehow retrieved the pointer to pDest in MapView

I've found (if you're using .NET4.6), the simplest solution is to use the Generic form if PtrToStructure
C#
MCDTYPE1 result = Marshal.PtrToStructure<mcdtype1>(mapView)</mcdtype1>

Otherwise, what is your UIStruct? Should not that be typeof(MCDTYPE1)?
 
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