Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6881127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:04:05+00:00 2026-05-27T05:04:05+00:00

I use C++ library in WPF. It’s SDK for Magnetic Stripe Reader/Writer. When I

  • 0

I use C++ library in WPF. It’s SDK for Magnetic Stripe Reader/Writer. When I call one of it’s methods in WPF, I receive StackOverFlowException after 10 seconds. Method called from button click event.

[DllImport("MSR_API.dll")]
static extern bool MSR_InitComm(string portname, UInt32 baud);

This method connects to Magnetic Stripe Reader device. First I tested this method on Windows Forms application, and everything was great. But when I started to write WPF app with this library, I receive StackOverFlowException everytime. What could be the reason of this “feature”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:04:05+00:00Added an answer on May 27, 2026 at 5:04 am

    Getting the [DllImport] declaration wrong is a standard cause. The CallingConvention property is very important. Getting it wrong causes the stack to get imbalanced, ultimately causing SO if you call it often enough. There’s an MDA for that, make sure you didn’t turn off PinvokeStackImbalance. Using Debug + Windows + Registers is another way to diagnose it, the ESP register value must be the same before and after the call.

    CallingConvention.Cdecl is often required for C or C++ code unless that code was explicitly written with the __stdcall keyword.


    Okay, the Embarcadero link suggests another reason for the exception. Borland libraries traditionally enabled FPU exceptions. That’s grossly incompatible with .NET code. Especially WPF because it heavily uses doubles for control sizes and positions. An FPU stack overflow is a bit odd, you more typically have trouble with NaN values.

    If you don’t have the source code of the library then you don’t have many attractive options to fix the problem. One thing you can try is to throw and catch an exception after the first call to the library. The .NET exception handling plumbing resets the FPU control word. Like this:

    bool ok = MSR_InitComm("COM1", 9600);
    try {
        throw new Exception("Fpu reset intended");
    }
    catch (Exception) {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After the suggestion to use a library for my ajax needs I am going
I would like to use the same project (class library) in Silverlight and WPF.
I am trying to use the Dynamic Data Display library for WPF in my
I have a WPF application and I use external library for generating documents. This
Edit: Rewritting question I use the Project Management Library from http://dlhsoft.com/Home.aspx in my WPF
I have a C# WPF application that use several library assemblies. I was wondring
I use SharpSvn library from CollabNET. I would like to set revision author while
We use Enterprise Library 3.0 to access Oracle DB (microsoft oracle client). What happens
I want to use libgadu (library of instant messaging protocol) under Visual Studio 2008.
How can I use Enterprise Library to do a Data Access Layer in c#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.