Yur*_*kov 1 c# wpf dll arithmeticexception
我有用C#编写的代码和用C编写的DLL.我试图从DLL调用函数.例如,C中DLL的头文件:
// ---------------------------------------------------------------------------
#ifndef Perspectiva_DLLUnitH
#define Perspectiva_DLLUnitH
// ---------------------------------------------------------------------------
#define DLL_EXPORT __export __stdcall
// ---------------------------------------------------------------------------
#ifdef __cplusplus
extern "C"
{
#endif
UCHAR DLL_EXPORT Init(ULONG TerminalID, CHAR *AzsNo, ULONG *Len);
...
#ifdef __cplusplus
}
#endif
// ---------------------------------------------------------------------------
#endif
Run Code Online (Sandbox Code Playgroud)
这就是我在C#中使用这个DLL的方式:
static class Pers
{
[DllImport("Perspectiva_DLL.dll", CallingConvention = CallingConvention.StdCall)]
public static extern byte Init(uint TerminalID, string AzsNo, out uint Len);
...
}
...
uint Len = Convert.ToUInt32(AzsNo.Text.Length);
Pers.Init(Convert.ToUInt32(TerminalID.Text), AzsNo.Text, out Len);
Run Code Online (Sandbox Code Playgroud)
函数Init正常工作并返回结果.但是在调用之后,如果我尝试使用界面执行任何操作,例如,更改选项卡,或者只是单击文本框,我会得到一个例外:ArithmeticException.
我无法理解代码中的错误.
例外细节:
System.ArithmeticException was unhandled
HResult=-2147024362
Message=???????????? ??? ?????? ???????? ? ?????????????? ????????.
Source=WindowsBase
StackTrace:
? System.Windows.Size..ctor(Double width, Double height)
? System.Windows.Documents.AdornerLayer.InvalidateAdorner(AdornerInfo adornerInfo)
? System.Windows.Documents.AdornerLayer.UpdateElementAdorners(UIElement element)
? System.Windows.Documents.AdornerLayer.UpdateAdorner(UIElement element)
? System.Windows.Documents.AdornerLayer.Add(Adorner adorner, Int32 zOrder)
? System.Windows.Documents.CaretElement.EnsureAttachedToView()
? System.Windows.Documents.CaretElement.Update(Boolean visible, Rect caretRectangle, Brush caretBrush, Double opacity, Boolean italic, CaretScrollMethod scrollMethod, Double scrollToOriginPosition)
? System.Windows.Documents.TextSelection.UpdateCaretStateWorker(Object o)
? System.Windows.Documents.TextSelection.UpdateCaretState(CaretScrollMethod caretScrollMethod)
? System.Windows.Documents.TextSelection.EnsureCaret(Boolean isBlinkEnabled, Boolean isSelectionActive, CaretScrollMethod scrollMethod)
? System.Windows.Documents.TextSelection.System.Windows.Documents.ITextSelection.UpdateCaretAndHighlight()
? System.Windows.Documents.TextEditor.OnGotKeyboardFocus(Object sender, KeyboardFocusChangedEventArgs e)
? System.Windows.Controls.Primitives.TextBoxBase.OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
? System.Windows.UIElement.OnGotKeyboardFocusThunk(Object sender, KeyboardFocusChangedEventArgs e)
? System.Windows.Input.KeyboardFocusChangedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
? System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
? System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
? System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
? System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
? System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
? System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
? System.Windows.Input.InputManager.ProcessStagingArea()
? System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
? System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject focus, Int32 timestamp)
? System.Windows.Input.KeyboardDevice.TryChangeFocus(DependencyObject newFocus, IKeyboardInputProvider keyboardInputProvider, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
? System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
? System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
? System.Windows.UIElement.Focus()
? System.Windows.Documents.TextEditorMouse.MoveFocusToUiScope(TextEditor This)
? System.Windows.Documents.TextEditorMouse.OnMouseDown(Object sender, MouseButtonEventArgs e)
? System.Windows.Controls.Primitives.TextBoxBase.OnMouseDown(MouseButtonEventArgs e)
? System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e)
? System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
? System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
? System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
? System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
? System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
? System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
? System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
? System.Windows.Input.InputManager.ProcessStagingArea()
? System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
? System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
? System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
? System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
? System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
? MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
? MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
? System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
? MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
? System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
? MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
? MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
? System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
? System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
? System.Windows.Threading.Dispatcher.Run()
? System.Windows.Application.RunDispatcher(Object ignore)
? System.Windows.Application.RunInternal(Window window)
? System.Windows.Application.Run(Window window)
? System.Windows.Application.Run()
? Perspectiva_test.App.Main() ? d:\???\test_codes\Perspectiva_test\Perspectiva_test\obj\Debug\App.g.cs:?????? 0
? System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
? System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
? Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
? System.Threading.ThreadHelper.ThreadStart_Context(Object state)
? System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
? System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
? System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
? System.Threading.ThreadHelper.ThreadStart()
InnerException:
Run Code Online (Sandbox Code Playgroud)
如果C dll的运行时系统更改FPU标志,通常会发生这种情况.您需要在调用类似于此的函数后重置这些:
[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
extern static uint _controlfp(uint newcw,uint mask);
const uint _MCW_EM=0x0008001f;
const uint _EM_INVALID=0x00000010;
public static void FixFPU() {
{
_controlfp(_MCW_EM, _EM_INVALID);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1134 次 |
| 最近记录: |