Jump to content
  • Advertisement
Sign in to follow this  
paic

Tom Miller's render loop for C# .... in managed C++ ?

This topic is 4460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm using managed C++ with winforms, and I came accross this blog article http://blogs.msdn.com/tmiller/archive/2005/05/05/415008.aspx But it's in C#, and I don't really know how to make it work in managed C++. The main problem are those lines : [System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously [DllImport("User32.dll", CharSet=CharSet.Auto)] I'm not used to those [...] stuff, so I don't know how to translate them into managed C++ (it doesn't work as is) Thx for any help ^^

Share this post


Link to post
Share on other sites
Advertisement
I haven't worked much with managed C++, but I do know that attribute syntax is the same. However, you need to add the word "Attribute" to the end of attributes if it's not already there (C# allows you to omit this). Thus, your first line becomes [System::Security::SuppressUnmanagedCodeSecurityAttribute()].

hope that helps,

Share this post


Link to post
Share on other sites
the way i'd go about this is to make use of c++/cli 's "it just works" (IJW) feature and #include windows.h and then just call PeekMessage() (PeekMessage msdn entry).
this prevents you from compiling /clr:pure, though. So if /clr:pure is required then you need to go the c#-style PInvoke route.

Share this post


Link to post
Share on other sites
Ok, thx both of you.

The solution is :

using namespace System::Runtime::InteropServices;
[DllImport("User32.dll", CharSet=CharSet::Auto)]
extern "C" WINUSERAPI BOOL WINAPI PeekMessageW(__out LPMSG lpMsg, __in_opt HWND hWnd, __in UINT wMsgFilterMin, __in UINT wMsgFilterMax, __in UINT wRemoveMsg);


The SuppressUnmanagedCodeSecurityAttribute was just here to speed up the loop, by unabling all the runtime security checks for the PeekMessage (and unmanaged codes) I might be wrong though ^^ Anyway, it works without it.

using namespace System::Runtime::InteropServices;
That's what caused my problem : the DllImport attribute was in this namespace, and since I didn't use it, DllImport was generating an error (the documentation is really badly written for that part ... I found that line while searching for PInvoke )

Share this post


Link to post
Share on other sites
cool that you got it to work. just be aware of the slightly bigger overhead of the PInvoke mechanism compared to calling the function directly using c++/cli IJW. this might be a good place to profile if PeekMessage() is called a lot, which i suspect. Nothing that needs to be done right now, though. If the time has come, judge based on the numbers. it might make a slight difference in this case.

cheers,
simon

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!