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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:39:09+00:00 2026-06-12T14:39:09+00:00

I updated my project from VS2005 (targeting .net 2) to VS2010 (targeting .net4). It

  • 0

I updated my project from VS2005 (targeting .net 2) to VS2010 (targeting .net4). It seems the pInvokeStackImbalance MDA is enabled by default, then I get a bunch of "unbalanced the stack" exceptions. Take this one for example:

[DllImportAttribute("gdi32.dll")]
private static extern IntPtr CreateSolidBrush(BrushStyles enBrushStyle, int crColor);  

It was working in .net 2 but now it throws exception. I changed it to this and it works:

[DllImportAttribute("gdi32.dll", CallingConvention = CallingConvention.ThisCall)]
private static extern IntPtr CreateSolidBrush(BrushStyles enBrushStyle, int crColor);

To my surprise, pinvoke.net lists it as

[DllImport("gdi32.dll")]
static extern IntPtr CreateSolidBrush(uint crColor);

Why my old is not working? It seems the pinvoke.net is wrong but how do I find out which calling conversion is it given a win32 function?

EDIT
My project is using the code from C# Rubber Rectangle to do the XOR drawing. Apparently the code needs a fix to work in .Net 4.

  • 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-12T14:39:11+00:00Added an answer on June 12, 2026 at 2:39 pm

    CreateSolidBrush uses stdcall. Almost all Win32 APIs do so. They never use thiscall. The function is declared as:

    HBRUSH CreateSolidBrush(
      __in  COLORREF crColor
    );
    

    so your mistake is simply that your version has too many parameters. The pinvoke.net declaration that you have found is correct.

    The stdcall convention pushes params right to left which explains how your code worked even with an extra spurious parameter.

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

Sidebar

Related Questions

I've updated a project to VS2010 and MVC2 from VS2008 and MVC1. I'm having
I have created an outlook 2007 add-in project in vs2008, targeting .net 3.5, then
I updated my Phonegap (Cordova) project from 1.9 to 2.0 and am receiving the
I just set about updating a project from Entity Framework 4.3.1 and .NET 4
I try to update a project from SVN (I have a fresh install of
I am getting the following error when trying to update my project from Intellij
I was just reading an update from a friend's project, mentioning the use of
I have a project where I need to update a labels text from inside
I updated a project (SVN). Update failed because a file cannot be opened, althought
I've recently updated my old Lua 5.1 project to the newest version of the

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.