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 7927561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:22:16+00:00 2026-06-03T19:22:16+00:00

My C# program has a very strange behavior. I’m using four ”hacky” pinvoke methods

  • 0

My C# program has a very strange behavior. I’m using four ”hacky” pinvoke methods in this program: GlobalKeyHooking, HotKey Registering, SetForegroundWindow/GetForegroundWindow, and SendKeys.Send/SendWait.

Here is where there is a behavior I don’t understand. I’m stealing the Ctrl+V in a program where the standard cut/copy&paste routine is replaced by an autocomplete list in a listbox that appears and disappears. On some computer with Windows 7, my programs works like a charm, on an other 50% of computers with Windows 7 (and sadly no VS2010 to debug it), a very weird loop appears —inside— a method. Since the Ctrl and the V themselves are hooked, I already prevented the method to be infinitely triggered. That’s ok. But another loop appears inside the method.

Briefly: myDebugValue increases until it reaches 23-24-25! So something is trying to execute a function a lot of times before deciding to stop.

Does anyone has already seen a similar undesired loop? Even though there is no try/catch block, it’s bouncing inside the function.

Can some P/Invokes function crash on some Windows 7 and not on other?

Are P/Invokes having their own invisible low-level assembler error handlers try/catch, stronger than my C# program execution?

Visually, when it’s doing it, I see my program UI quickly flashing a lot of times, 25 times, I guess.

    private bool getOutOfHere = false;

    private int myDebugValue = 0;

    private void globalKeyHooking_KeyUp(object sender, KeyEventArgs e)
    {
        if (getOutOfHere) return;
        myDebugValue = 0;
        if (e.KeyCode == Keys.LControlKey) 
        {
            getOutOfHere = true;
            SendKeys.SendWait("^v");
            getOutOfHere = false;
            myDebugValue++; 
        }                
    }

I tried to compile with 2.0, 3.0 and 4.0, and on the same 4 computers, in all cases, it still the same rate: 50% crashes, 50% works.

[Edit]

I really think that SendKeys.Send acts differently on different computers with Windows 7.

  • 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-06-03T19:22:20+00:00Added an answer on June 3, 2026 at 7:22 pm

    Didn’t want to answer my own question, but there is always a first time.
    I decided to use a method similar to InputSimulator to achieve my goal and to avoid using SendKeys. Now, everything works perfectly on all machines.

    I saw that InputSimulator is compatible with all my machines using Windows 7 and is using SendInput instead of SendMessage or SendKeys, so I used SendInput in my app.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a program with native C++ and the WinAPI. This program has
I am experiencing some very strange behavior with Blend: Since weeks i am working
I am getting a weird exception when I exit the program. This has started
I'm currently writing a socket program in C++ and I've stumbled across very strange
I'm encountering a very strange problem using g++ 4.1.2. I have a very basic
I run a very simple, single-threaded java program. When I check the threads using
I just discovered a very strange behavior with Type.GetInterface and nested Types. The following
developers! I have very strange problem. My project has DLL writen in C++ and
I'm building a program that has a very basic premise. For X amount of
My program has run a long time. I began to run it yesterday. Now

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.