GetClassName err on a specific app (Lync)

107 views Asked by At

I have a list of window handles, and for each, need to assess whether it refers to MS Excel, or not. I wrote a small "isExcel" function for this purpose.

private bool isExcel(IntPtr wHdl){
        bool f = false;
        StringBuilder lpClassName = new StringBuilder();
        GetClassName(wHdl, lpClassName, 100);
        f = ((lpClassName.ToString() == "MS-SDIb") || (lpClassName.ToString() == "XLMAIN"));
        return f;
   }

This works perfectly.... except in some cases. MS Lync and MS SQL Server Management Studio 2012

When a window handle associated with these applications hits the above procedure, it does not just fail, but crashes my app. The failing line and err as thus :

GetClassName(wHdl, lpClassName, 100);

"vshost32.exe has stopped working"

And then my application closes.

I can obviously work around this issues, and detour around the isExcel procedure for these specific application's handle; but I would rather solve issues then work around them.

Any insight to this issue, why it occurs and how to handle it .... would be greatly appreciated.

Thanks

1

There are 1 answers

0
user7445488 On

I have similar problem. I fix it by use another StringBuilder constructor: StringBuilder lpClassName = new StringBuilder("",256);