   Tom Miller's render loop for C# .... in managed C++ ?
  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.aspxBut 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 ^^   
  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,   ;  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. ;  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 )   ;  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   