473,503 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CLI/C++: unmanaged structure to managed code in WinProc

Hi,

I have CLI/C++ code to override WndProc(Message% m) in order to create NC
area. I tried to marshal unmanaged ptr (m.LParam) to managed object by using
Marshal::PtrToStructure like:
if (m.WParam == IntPtr(1))
{
NCCALCSIZE_PARAMS csp;

csp = (NCCALCSIZE_PARAMS)Marshal::PtrToStructure(m.LPara m,
(NCCALCSIZE_PARAMS));
csp.rgrc[0].top += borderWidth;
csp.rgrc[0].bottom -= borderWidth;
csp.rgrc[0].left += borderWidth;
csp.rgrc[0].right -= borderWidth;
Marshal::StructureToPtr(csp, m.LParam, false);
}
I'm having difficult in creating the managed type of the NCCALCSIZE_PARAMS
in order to pass to PtrToStructure as the second parameter. I've tried some
suggestions from the forum unsuccessfully. In C#, it's easily done by
typeof(NCCALCSIZE_PARAMS). Is any easy way to translate this C# yntax to
CLI/C++ equavilent. Or, do I have to do in a hard way -- create a managed
equavilent value structure, copy native pointered NCCALCSIZE_PARAMS data into
the managed structure and then marshal back to native structure ptr after
modifying data in order to pass out WinProc. It's messy. Why doesn't CLI/C++
have an easy syntax as C# in this regard. Anyone has a good idea of it?

Thanks
Jun 3 '07 #1
2 7525
After examing IntPtr, there is no need to use PtrToStructure in CLI/C++. So,
the code should be simply as
NCCALCSIZE_PARAMS* csp = (NCCALCSIZE_PARAMS*)m.LParam.ToPointer();

"cjs" wrote:
Hi,

I have CLI/C++ code to override WndProc(Message% m) in order to create NC
area. I tried to marshal unmanaged ptr (m.LParam) to managed object by using
Marshal::PtrToStructure like:
if (m.WParam == IntPtr(1))
{
NCCALCSIZE_PARAMS csp;

csp = (NCCALCSIZE_PARAMS)Marshal::PtrToStructure(m.LPara m,
(NCCALCSIZE_PARAMS));
csp.rgrc[0].top += borderWidth;
csp.rgrc[0].bottom -= borderWidth;
csp.rgrc[0].left += borderWidth;
csp.rgrc[0].right -= borderWidth;
Marshal::StructureToPtr(csp, m.LParam, false);
}
I'm having difficult in creating the managed type of the NCCALCSIZE_PARAMS
in order to pass to PtrToStructure as the second parameter. I've tried some
suggestions from the forum unsuccessfully. In C#, it's easily done by
typeof(NCCALCSIZE_PARAMS). Is any easy way to translate this C# yntax to
CLI/C++ equavilent. Or, do I have to do in a hard way -- create a managed
equavilent value structure, copy native pointered NCCALCSIZE_PARAMS data into
the managed structure and then marshal back to native structure ptr after
modifying data in order to pass out WinProc. It's messy. Why doesn't CLI/C++
have an easy syntax as C# in this regard. Anyone has a good idea of it?

Thanks
Jun 4 '07 #2

"cjs" <cj*@discussions.microsoft.comwrote in message
news:C0**********************************@microsof t.com...
After examing IntPtr, there is no need to use PtrToStructure in CLI/C++.
So,
the code should be simply as
NCCALCSIZE_PARAMS* csp = (NCCALCSIZE_PARAMS*)m.LParam.ToPointer();
Exactly. You've hit on one of the biggest advantages of C++/CLI -- it
understands native types.

If you ever did need the equivalent of C# typeof(MyClass), it's
MyClass::typeid
>

"cjs" wrote:
>Hi,

I have CLI/C++ code to override WndProc(Message% m) in order to create NC
area. I tried to marshal unmanaged ptr (m.LParam) to managed object by
using
Marshal::PtrToStructure like:
if (m.WParam == IntPtr(1))
{
NCCALCSIZE_PARAMS csp;

csp = (NCCALCSIZE_PARAMS)Marshal::PtrToStructure(m.LPara m,
(NCCALCSIZE_PARAMS));
csp.rgrc[0].top += borderWidth;
csp.rgrc[0].bottom -= borderWidth;
csp.rgrc[0].left += borderWidth;
csp.rgrc[0].right -= borderWidth;
Marshal::StructureToPtr(csp, m.LParam, false);
}
I'm having difficult in creating the managed type of the
NCCALCSIZE_PARAMS
in order to pass to PtrToStructure as the second parameter. I've tried
some
suggestions from the forum unsuccessfully. In C#, it's easily done by
typeof(NCCALCSIZE_PARAMS). Is any easy way to translate this C# yntax to
CLI/C++ equavilent. Or, do I have to do in a hard way -- create a managed
equavilent value structure, copy native pointered NCCALCSIZE_PARAMS data
into
the managed structure and then marshal back to native structure ptr after
modifying data in order to pass out WinProc. It's messy. Why doesn't
CLI/C++
have an easy syntax as C# in this regard. Anyone has a good idea of it?

Thanks

Jun 4 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
741
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
0
1683
by: nygiantswin2005 | last post by:
I would like to know how do I pass a pointer to a struct from managed code to unmanaged code. For example if I create structure like this in managed code. StructLayout( LayoutKind.Sequential,...
2
2023
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking afterwards with ILDASM at what is visible in those assemblies from a...
3
3483
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
4
2415
by: devmentee | last post by:
I want to write a managed wrapper( kind of proxy) which will call into unmanaged C++ code. I've got a general idea and have read some articles on how to do it. But I cannot find any information on...
6
5883
by: Aston Martin | last post by:
Hi All, ********************** My Situation ********************** I am working on project that involves passing a structure to unmanaged code from .Net world (well using C#). Perhaps an example...
16
8757
by: pkoniusz | last post by:
Hello everybody, Been just thinking how actually one could convert the following unmanaged code to the managed C++: struct JustAnExample { char value1; int value2; // etc ....
3
2192
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm trying to specify the requirement from unmanaged DLL component that will be used by a managed application written in C#. The unmanaged DLL is implementing some kind of algorithm for defect...
0
1410
by: tomwolfstein | last post by:
Hi. I am trying to write a wrapper for the standard VC1 decoder, and I need to resolve a "TypeLoadException" The decoder comes an an executable which I've turned into a .dll. This decoder has about...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.