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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:15:08+00:00 2026-06-07T07:15:08+00:00

Here is the code i have: public string selectedProgram; [DllImport(user32.dll, CharSet = CharSet.Auto, ExactSpelling

  • 0

Here is the code i have:

 public string selectedProgram;

    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    public static extern IntPtr GetForegroundWindow();
    [DllImport("user32.dll")]
    private static extern bool GetWindowRect(IntPtr hWnd, Rectangle rect); 

    private void button2_Click(object sender, EventArgs e)
    {
        Process[] process = Process.GetProcesses();
        foreach (var p in process)
        {
            selectedProgram = listView1.SelectedItems.ToString();
            Rectangle bonds = new Rectangle();
            GetWindowRect(Handle, bonds);  
            Bitmap bmp = new Bitmap(bonds.Width, bonds.Height);
            using (var gfx = Graphics.FromImage(bmp))
            {
                gfx.CopyFromScreen(bonds.Location, Point.Empty, bonds.Size);
                pictureBox1.Image = bmp;
                frm2.Show();
                frm2.pictureBox1.Image = pictureBox1.Image;
            }
        }

I am getting an error or some green highlighting on GetWindowRect(Handle, bonds); that says:

A call to PInvoke function 'Screen Shot!WindowsFormsApplication1.Form3::GetWindowRect' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

How do i fix this so i can get a screenshot of the other application’s window?

  • 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-07T07:15:10+00:00Added an answer on June 7, 2026 at 7:15 am

    Looking at pinvoke.net (great reference), the signature GetWindowRect for should be:

    public static extern bool GetWindowRect(HandleRef hwnd, out RECT lpRect);
    

    It might also work to do this, which doesn’t require you to define a custom RECT struct:

    public static extern bool GetWindowRect(IntPtr hwnd, out Rectangle lpRect);
    

    If that doesn’t work, you can define a RECT struct based on this page, and use:

    public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
    

    The pinvoke.net page on RECT shows how to convert between RECT and Rectangle.

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

Sidebar

Related Questions

I have this code here: public static String AddRemoveDays(String date, int days) throws ParseException
I have following code: public static void ProcessStep(Action action) { //do something here if
Here is the code I have : public class Test { string a; int
Here is my code: public static class SerializationUtil { public static string Serialize(object obj)
I have this class called SiteAsyncDownload.cs Here's the code: public class SiteAsyncDownloader { WebClient
I have a class with two constructors (C#). Here is the code snippet: public
Here's the code I have: var commandsBuffer = List[String]() commandsBuffer ::= cmd.exe commandsBuffer ::=
Here is the code I have written for Rectangle class. class Rectangle (l: Double,
enter code here I have a table on SQL server 2005 with bigint primary
Here is the code I have to create an UIAlertView with a textbox. UIAlertView

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.