Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cjs - 03 Jun 2007 08:21 GMT
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.LParam,
(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
cjs - 04 Jun 2007 12:43 GMT
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();

> Hi,
>
[quoted text clipped - 24 lines]
>
> Thanks
Ben Voigt [C++ MVP] - 04 Jun 2007 14:35 GMT
> 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

>> Hi,
>>
[quoted text clipped - 29 lines]
>>
>> Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.