Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. need help with "System.Runtime.InteropServices.SEHException" error

need help with "System.Runtime.InteropServices.SEHException" error

Scheduled Pinned Locked Moved Managed C++/CLI
helpc++cryptographydebuggingperformance
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    UserNameless
    wrote on last edited by
    #1

    hey, i'm new to managed c++, and i need to use managed c++ to perform some tasks. I am using capicom.dll to create an application which will be able to sign, verify, encrypt,etc. only encrypt function requires the use of managed functions (to get file as bytes, convert to base-64 string and then encrypt), whereas the sign function does not require any managed code. even so, I am getting a System.Runtime.InteropServices.SEHException error on the signing function. here is the code which deals with the signing part:

    if(cert->HasPrivateKey())
    {
    signedData->Content = "This is a string";
    signer->PutCertificate(cert);
    _bstr_t text = signedData->Sign(signer,true,CAPICOM_ENCODE_BASE64);
    return text;
    }

    I have traced the code to fail at the Sign(signer,....) part. signer is the certificate being used to sign the data with, signedData and signer variables have been initialized with the __uuidof method, which is also how i've initialized encrypt and verify functions in their code sections. the debugger takes me inside the capicom.tli file and fails. here is the tli code block which fails:

    inline _bstr_t ISignedData::Sign ( struct ISigner * pSigner, VARIANT_BOOL bDetached, enum CAPICOM_ENCODING_TYPE EncodingType ) {
    BSTR _result = 0;
    HRESULT _hr = raw_Sign(pSigner, bDetached, EncodingType, &_result);
    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
    return _bstr_t(_result, false);

    pSigner, bDetached, and EncodingType get their proper values, but the _result variable keeps getting set to <undefined value> any suggestions would be most welcomed on what i might do or what might be going wrong here. the error on debugger output is (at line: raw_Sign(pSigner, bDetached, EncodingType, &_result); ) First-chance exception at 0x7c81eb33 in CAPICOMGUI.exe: Microsoft C++ exception: _com_error at memory location 0x0012d708.. A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in CAPICOMGUI.exe An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in CAPICOMGUI.exe Additional information: External component has thrown an exception. hope i was clear enough :~

    Richard Andrew x64R 1 Reply Last reply
    0
    • U UserNameless

      hey, i'm new to managed c++, and i need to use managed c++ to perform some tasks. I am using capicom.dll to create an application which will be able to sign, verify, encrypt,etc. only encrypt function requires the use of managed functions (to get file as bytes, convert to base-64 string and then encrypt), whereas the sign function does not require any managed code. even so, I am getting a System.Runtime.InteropServices.SEHException error on the signing function. here is the code which deals with the signing part:

      if(cert->HasPrivateKey())
      {
      signedData->Content = "This is a string";
      signer->PutCertificate(cert);
      _bstr_t text = signedData->Sign(signer,true,CAPICOM_ENCODE_BASE64);
      return text;
      }

      I have traced the code to fail at the Sign(signer,....) part. signer is the certificate being used to sign the data with, signedData and signer variables have been initialized with the __uuidof method, which is also how i've initialized encrypt and verify functions in their code sections. the debugger takes me inside the capicom.tli file and fails. here is the tli code block which fails:

      inline _bstr_t ISignedData::Sign ( struct ISigner * pSigner, VARIANT_BOOL bDetached, enum CAPICOM_ENCODING_TYPE EncodingType ) {
      BSTR _result = 0;
      HRESULT _hr = raw_Sign(pSigner, bDetached, EncodingType, &_result);
      if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
      return _bstr_t(_result, false);

      pSigner, bDetached, and EncodingType get their proper values, but the _result variable keeps getting set to <undefined value> any suggestions would be most welcomed on what i might do or what might be going wrong here. the error on debugger output is (at line: raw_Sign(pSigner, bDetached, EncodingType, &_result); ) First-chance exception at 0x7c81eb33 in CAPICOMGUI.exe: Microsoft C++ exception: _com_error at memory location 0x0012d708.. A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in CAPICOMGUI.exe An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in CAPICOMGUI.exe Additional information: External component has thrown an exception. hope i was clear enough :~

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      My best guess is that there's something about the pSigner pointer that it's choking on. You say that the sign function does not call any managed code, but that the other functions do. Is it possible that the pSigner object contains pointers to managed objects that the "raw_Sign" function doesn't understand?

      U 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        My best guess is that there's something about the pSigner pointer that it's choking on. You say that the sign function does not call any managed code, but that the other functions do. Is it possible that the pSigner object contains pointers to managed objects that the "raw_Sign" function doesn't understand?

        U Offline
        U Offline
        UserNameless
        wrote on last edited by
        #3

        thanks for the reply Richard. I assumed it was pSigner as well at first. pSigner is a pointer to a certificate (stored on the computer), certificate variable being initialized as ICertificate2Ptr cert (this initialization also exists in functions such as verify,encrypt, decrypt that are also calling managed variables) I checked what all it was passing on signing and encryption and this is what I noticed: on this line:

        _bstr_t text = signedData->Sign(signer,true,CAPICOM_ENCODE_BASE64);

        signer had the values (on hovering mouse over the variable):

        -signer: 0xhexvalue
        -m_pInterface: 0xhexvalue
        -IDispatch: {...}
        -IUnknown: {...}
        -__vfptr: 0xhexvalue
        [0]: values
        [1]: values
        [2]: values

        and once it was passed onto the inline raw_Sign function the values were:

        - pSigner: 0xhexvalue
        -IDispatch: {...}
        -IUnknown: {...}
        -Children could not be evaluated

        this was also the case on the encrypt function (when running encryption function only, and no other function), yet it worked. all the variables otherwise (in the raw_Sign) were holding thier proper values. Do you think its failing because of the "Children could not be evaluated" part? If so, is there anything I can do to pass values successfully?

        Richard Andrew x64R 1 Reply Last reply
        0
        • U UserNameless

          thanks for the reply Richard. I assumed it was pSigner as well at first. pSigner is a pointer to a certificate (stored on the computer), certificate variable being initialized as ICertificate2Ptr cert (this initialization also exists in functions such as verify,encrypt, decrypt that are also calling managed variables) I checked what all it was passing on signing and encryption and this is what I noticed: on this line:

          _bstr_t text = signedData->Sign(signer,true,CAPICOM_ENCODE_BASE64);

          signer had the values (on hovering mouse over the variable):

          -signer: 0xhexvalue
          -m_pInterface: 0xhexvalue
          -IDispatch: {...}
          -IUnknown: {...}
          -__vfptr: 0xhexvalue
          [0]: values
          [1]: values
          [2]: values

          and once it was passed onto the inline raw_Sign function the values were:

          - pSigner: 0xhexvalue
          -IDispatch: {...}
          -IUnknown: {...}
          -Children could not be evaluated

          this was also the case on the encrypt function (when running encryption function only, and no other function), yet it worked. all the variables otherwise (in the raw_Sign) were holding thier proper values. Do you think its failing because of the "Children could not be evaluated" part? If so, is there anything I can do to pass values successfully?

          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #4

          UserNameless wrote:

          Do you think its failing because of the "Children could not be evaluated" part?

          That's where my suspicions would fall. Unfortunately, COM is not my strength. I'm interested to know why the "children" CAN be evaluated when the debugger is stopped on the outside of the function call, but once we go inside the function, then the children can no longer be evaluated.

          U 1 Reply Last reply
          0
          • Richard Andrew x64R Richard Andrew x64

            UserNameless wrote:

            Do you think its failing because of the "Children could not be evaluated" part?

            That's where my suspicions would fall. Unfortunately, COM is not my strength. I'm interested to know why the "children" CAN be evaluated when the debugger is stopped on the outside of the function call, but once we go inside the function, then the children can no longer be evaluated.

            U Offline
            U Offline
            UserNameless
            wrote on last edited by
            #5

            Richard Andrew x64 wrote:

            That's where my suspicions would fall. Unfortunately, COM is not my strength.

            No worries, appreciated your thoughts on the problem.

            Richard Andrew x64 wrote:

            I'm interested to know why the "children" CAN be evaluated when the debugger is stopped on the outside of the function call, but once we go inside the function, then the children can no longer be evaluated.

            Yes this was as interesting point to me as well. Thanks for the thoughts. I guess it can't be helped as the pointers are defined in the capicom.dll already

            Richard Andrew x64R 1 Reply Last reply
            0
            • U UserNameless

              Richard Andrew x64 wrote:

              That's where my suspicions would fall. Unfortunately, COM is not my strength.

              No worries, appreciated your thoughts on the problem.

              Richard Andrew x64 wrote:

              I'm interested to know why the "children" CAN be evaluated when the debugger is stopped on the outside of the function call, but once we go inside the function, then the children can no longer be evaluated.

              Yes this was as interesting point to me as well. Thanks for the thoughts. I guess it can't be helped as the pointers are defined in the capicom.dll already

              Richard Andrew x64R Offline
              Richard Andrew x64R Offline
              Richard Andrew x64
              wrote on last edited by
              #6

              One last remark, if I may: You might try constructing a test project to call the CAPICOM dll from native code and see if the error still happens. Good luck.

              U 1 Reply Last reply
              0
              • Richard Andrew x64R Richard Andrew x64

                One last remark, if I may: You might try constructing a test project to call the CAPICOM dll from native code and see if the error still happens. Good luck.

                U Offline
                U Offline
                UserNameless
                wrote on last edited by
                #7

                Funny that you should mention it. I did have a backup of a native code which simply signed data, and worked as I wanted/expected it to, it would generate the signed hash as expected. But after I ran this (managed) project a few times (in a separate VS 2008), I went over to test my native application, which surprisingly now, also started giving me this same error. I assume it's a bug of having porting my project from VS 2005 to VS2008.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups