c++ cli - Exception: Cannot marshal 'parameter #X': Pointers cannot reference marshaled structures. Use ByRef instead -


i'm working in vs2010 c++ , have c++/cli call formatmessage() draws strange exception. here block of code below below.

if((m_hglrc = wglcreatecontext(m_hdc)) == null) {     messagebox::show("wglcreatecontext failed");      char* lpbuffer;      formatmessage(         format_message_allocate_buffer|format_message_from_system, // it´s system error         null,                                     // no string formatted needed         ::getlasterror(),                         // hey windows: please explain error!         makelangid(lang_neutral,sublang_default), // in standard language         (lptstr)&lpbuffer,                        // put message here         0,                                        // number of bytes store message         null);      messagebox::show( nullptr, gcnew system::string(lpbuffer), "lastrrror",messageboxbuttons::ok);     //messageboxw(null,(lpctstr)lpbuffer, _t("lastrrror"),mb_ok|mb_iconwarning);          // free buffer.     if(lpbuffer)localfree(lpbuffer);      return 0; } 

i following error @ runtime after messagebox "wglcreatecontext failed" appears.

an unhandled exception of type 'system.runtime.interopservices.marshaldirectiveexception' occurred in spritey.exe   additional information: cannot marshal 'parameter #7': pointers cannot reference marshaled structures.  use byref instead. 

it seems have problem param #7, null in case. param #7 (as far msdn explains) optional , expects valist* inserting format string. i've no use parameter , have therefore input null.

i've seen others who've had problem on forums , online, , theirs have been solved switching version of clr support used \clr:pure regular \clr in project configurations. why make difference?

also has not worked me. can see i'm doing wrong in use of formatmessage()?

thanks in advance,
guy


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -