How can I compare the value returned from a method with HRESULT? I tried this but it is not working:
FPropStg.DeleteMultiple(1, psProp) == VSConstants.S_OK
The type defintion for DeleteMultiple() is:
HRESULT IPropertyStorage.DeleteMultiple(Ulong, Propspec)
I have written VSConstants.S_OK. Is there a way I can write S_OK directly? I made an attempt to do so but got an error that indicated that S_OK does not exist in the current context.
I also checked HRESULT against the Windows common system-wide codes. But the value I am receiving for HRESULT is not in that list. Note that I have included the namespaces System.Exception and System.Security.Cryptography.StrongNameSignatureInformation.
All that said, I basically have two questions:
S_OK instead of VSConstants.S_OK?S_OK?HRESULT hr = FPropStg.DeleteMultiple(1, psProp);
if (hr == S_OK) // S_OK does not exist in the current context...
{
}
What if you set PreserveSig to false? Something like this:
You declare the function similar to this (I made it up, I don't know the exact signature...but you do)
[DllImport("ole32.dll", EntryPoint = "DeleteMultiple", ExactSpelling = true, PreserveSig = false)]
public static extern void DeleteMultiple(ulong cpspec, PropSpec[] rgpspec);
and call it this way
try
{
FPropStg.DeleteMultiple(1, psProp);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, "Error on DeleteMutiple");
}
Explanation: when PreserveSig is false you can omit the returned HRESULT value, but internally this value is actually checked, so if HRESULT is different from S_OK an exception is thrown.
You can use this enum to define OK, it is from pinvoke:
enum HRESULT : long
{
S_FALSE = 0x0001,
S_OK = 0x0000,
E_INVALIDARG = 0x80070057,
E_OUTOFMEMORY = 0x8007000E
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With