Dan Ling
Dan Ling

Reputation: 2984

Does utilizing the Windows User Interface API risk incompatibility between different versions of Windows?

I am working on a C# Excel VSTO add-in that utilizes the user32.dll to do some black magic with the excel UI. I am not very experienced in using Win32, and I am wondering:

Do I need to worry about ensuring that the application works on all versions of Windows from XP and after? Or is it reasonable to assume that my Win32 calls will work consistently in all these versions?

Edit: here are the calls I am using:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static public extern IntPtr FindWindowEx(IntPtr hWnd, IntPtr hChild, string strClassName, string strName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static public extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static public extern bool IsWindowEnabled(IntPtr hWnd);

Upvotes: 2

Views: 135

Answers (1)

0xC0000022L
0xC0000022L

Reputation: 21319

Okay, the calls you are using are not going to go away just like that, they're here to stay. However, especially FindWindowEx has a very specific functionality, so it is very possible that you are trying to find a child window in the Excel GUI whose name and/or window class can change any time (including via minor updates) at the discretion of Microsoft.

So to answer your question: no need to worry about the API functions you are using, but yes you will have to code defensively in order to make sure your code doesn't misbehave on Excel versions that don't fulfill the expectations (about the presence of particular child windows) in your code.

Upvotes: 5

Related Questions