none
How to catch a managed exception in unmanaged code or how to ask if the policy of a managed dll is set? RRS feed

  • Question

  • My Visual Studio 2005 solution consists of a mfc exe without option /clr project and a MixedMode project with option /clr and a strong key . When I first call any code of the MixedMode project the DLL is loaded.

    On the network the MixedMode DLL is only loaded when I have set the correct policies with caspol. If this policiy isn't set I don't get a System.FileLoad Exception. My problem is that I can't catch this managed exception in the unmanaged code.

    Is there a way to catch managed exceptions in unmanaged code?

    If this is not possible is how can I ask in unmanaged code if the MixedMode assembly has the required policy?

    If this isn't even possible is there a chance with command line asking if the policy of that assembly is set. The caspol manual gives me no answer about asking for that?
    Monday, June 16, 2008 9:53 AM

All replies

  • Using __try/__except should work in your unmanaged code.  You'll lose exception information though.  I think you'll get the 0xE0434F4D exception code for any managed exception.
    Hans Passant.
    • Marked as answer by Bruno Yu Wednesday, June 18, 2008 6:04 AM
    • Unmarked as answer by nobugzModerator Wednesday, June 18, 2008 9:34 AM
    Monday, June 16, 2008 11:18 AM
    Moderator
  • No, this doesn't catch the managed exception. Below is the code in the unmanaged mfc Exe. C_ManagedBridge is a class inside the Mixed-Mode DLL.


      __try 
      { 
        C_ManagedBridge::MyStaticMethod(); 
      } 
      __except ( 0 ) 
      { 
      } 


    I have no problem that the program terminates. I just want to give detailed information for the user before it terminates.

    Wednesday, June 18, 2008 9:26 AM