Exception on exit() when using C# event source with c++ sink -


i have com object, implemented in c# .dll, named comclass sources events. then, have c++ object, simplesink, sinks events sent comclass. event source/sink mechanism works great. but, when crt calls exit(), i'm getting memory access exception thrown following code in exe_common.inl

    //     // main has returned; exit somehow...     //      if (!__scrt_is_managed_app())         exit(main_result); // exception thrown. 

the text of exception message follows.

exception thrown @ 0x00000004 in cpp.exe: 0xc0000005: access violation executing location 0x00000004.

i understand attempting access junk memory location, i'm unsure what. researched issue , came across this, microsoft.

https://msdn.microsoft.com/en-us/library/ms235234.aspx

once common language runtime (clr) enters shutdown mode, native functions have limited access clr services. when attempting call release on com object compiled /clr, clr transitions native code , transitions managed code service iunknown::release call (which defined in managed code). clr prevents call managed code since in shutdown mode.

i'm not sure if applicable c++ /clr compiled com objects, or clr compiled com objects. may cold lead, speak. understand disable exception , 'probably' go business, makes me feel oily. so, question is, how can prevent exception when program shuts down?

here is.

int main() {     coinitialize(null);      // explicit scope smart pointer destructs @ correct time     {         icomclassptr source;         hresult createinstance = source.createinstance(__uuidof(comclass));          sinksimple sink;          hresult advise = sink.dispeventadvise(source);          try         {             source->fireevent();         }         catch (const _com_error& ex)         {             std::cout << "error: " << ex.description();         }          hresult unadvise = sink.dispeventunadvise(source);     }          couninitialize();     std::this_thread::sleep_for(std::chrono::milliseconds(100));     return 0; } 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -