need help with "System.Runtime.InteropServices.SEHException" error
-
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 :~
-
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 :~
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?
-
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?
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]: valuesand once it was passed onto the inline raw_Sign function the values were:
- pSigner: 0xhexvalue
-IDispatch: {...}
-IUnknown: {...}
-Children could not be evaluatedthis 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?
-
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]: valuesand once it was passed onto the inline raw_Sign function the values were:
- pSigner: 0xhexvalue
-IDispatch: {...}
-IUnknown: {...}
-Children could not be evaluatedthis 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?
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.
-
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.
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 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
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.
-
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.
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.