1

让我知道如何在 c# 代码中使用这个“vbObjectError” ://这是我的 VB 代码

Public Enum CryptoErrors
    ErrorAquiringContext = vbObjectError + 1056
    ErrorCreatingHash = vbObjectError + 1057
    ErrorCreatingHashData = vbObjectError + 1058
    ErrorDerivingKey = vbObjectError + 1059
    ErrorEncryptingData = vbObjectError + 1060
    ErrorDecryptingData = vbObjectError + 1061
    ErrorInvalidHexString = vbObjectError + 1062
    ErrorMissingParameter = vbObjectError + 1063
    ErrorBadEncryptionType = vbObjectError + 1064
End Enum
4

1 回答 1

2

You could translate it literally as:

public enum CryptoErrors
{   
     ErrorAcquiringContext = Microsoft.VisualBasic.Constants.vbObjectError + 1056,
     ...
}

in which case you need a reference to Microsoft.VisualBasic.dll.

If you don't want to take a dependency on Microsoft.VisualBasic.dll, you could define your own C# constant instead:

public const int VBObjectError = -2147221504;

But I'd question why you'd need it in a C# application. Constants offset from vbObjectError normally correspond to an HRESULT and are used in a VB Err.Raise statement.

In C# you'd just throw an exception.

于 2012-05-18T09:29:53.397 回答