What the fsck am I doing wrong here

  • Thread starter Thread starter Scott Manson
  • Start date Start date
S

Scott Manson

StringBuilder bldr=new StringBuilder();
int res=GetClassName(0x00240110,bldr,255);
Debug.WriteLine(bldr.ToString());
if(bldr.ToString()=="AfxFrameOrView42s")
Debug.Write("Things SHOULD work");
hWnd=FindWindow(bldr.ToString(),"");
if(hWnd==(IntPtr) 0)
{
Debug.WriteLine(" but they obviously dont!");
}
// The following is just in case I fscked a parameter
hWnd=FindWindow(bldr.ToString(),null);
if(hWnd==(IntPtr) 0)
{
Debug.WriteLine("Things SHOULD WORK but they obviously dont!");
}
 
Scott Manson said:
StringBuilder bldr=new StringBuilder();
int res=GetClassName(0x00240110,bldr,255);
Debug.WriteLine(bldr.ToString());
if(bldr.ToString()=="AfxFrameOrView42s")
Debug.Write("Things SHOULD work");
hWnd=FindWindow(bldr.ToString(),"");
if(hWnd==(IntPtr) 0)
{
Debug.WriteLine(" but they obviously dont!");
}
// The following is just in case I fscked a parameter
hWnd=FindWindow(bldr.ToString(),null);
if(hWnd==(IntPtr) 0)
{
Debug.WriteLine("Things SHOULD WORK but they obviously dont!");
}

It would help if you'd tell us what your code is trying to do, what
FindWindow does, etc.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
Hi Scott,

In addition to what Jon said I will try to guess what you are doing.

I think that you are trying to use GetClassName function from win API , if
that is so, bldr is an out parameter, meaning that you need to create a
buffer where the function will place the name of the class, you are not
doing that, that may be the problem, change the stringbuilder to a char[] of
255 ( the third arg contain the size of the array ) and see what happen

This is the definition of GetClassName function , maybe somebody can give
you the correct way to P/Invoke it.

int GetClassName(
HWND hWnd, // handle to window
LPTSTR lpClassName, // class name
int nMaxCount // size of class name buffer
);Parameters
hWnd
[in] Handle to the window and, indirectly, the class to which the window
belongs.
lpClassName
[out] Pointer to the buffer that is to receive the class name string.
nMaxCount
[in] Specifies the length, in TCHARs, of the buffer pointed to by the
lpClassName parameter. The class name string is truncated if it is longer
than the buffer.
Return Values

Hope this help,
 
Back
Top