开发者

Error "E_UNEXPECTED(0x8000FFFF)" when using CDec/CInt/IsNumeric

I have encountered a strange problem, which I could solve but don't understand why it did occur.

I have build a DLL with COM enabled. In this DLL I have classes that did use the functions CInt, CDec and IsNumeric. If I test these classes from a .NET application then it works ok. But when I called/run these classes f开发者_JS百科rom a Win32 application (with COM) then I did get an "E_UNEXPECTED(0x8000FFFF)" error.

After some debugging I found out that the problem would go away if I: - replaced IsNumeric with Integer.TryParse or Decimal.TryParse - replaced CInt with Integer.Parse - replaced CDec with Decimal.Parse

Can anyone explain this? Again, I could solve it by doing this but I would like to know why.


Just a guess.

I think that this is somehow related to the fact that all legacy functions like CInt, CDec, etc are defined in Microsoft.VisualBasic.dll assembly, which appears not to be playing well with COM.


That's pretty strange. Sounds to me like the arguments passed by the unmanaged code caused an exception in the VB.NET code. Your unmanaged code cannot detect managed exceptions. It should be visible in the debug output in the Output window, you should see a first-chance exception with exception code 0xe0434f4e.

Your changes are not a true replacement for CInt/CDec, they'll only handle string arguments. But stranger yet is that CInt() doesn't have trouble with strings, it shouldn't throw.

You are playing fast and loose with argument types though, treating strings as numbers is always trouble. Make sure you declare the argument type. Putting Option Strict On at the top of your source code is a good way to operate the two-by-four.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜