Original Post
saw this article: http://msdn.microsoft.com/msdnmag/issues/02/08/CQA/ Now, im trying to call a win32 api commands but they are failing. I have a c++ dll that opens a window and i can get the handle of the window. I use this handle in c# to try to get the window text but it fails. I'm using swig, which generates wrapper code for my c++ dll which i use in my c# project. so i have a function prototype for example as (genrated by swig): SWIGTYPE_p_HWND GetWindowHandle(); where SWIGTYPE_p_HWND is defined as:
public class SWIGTYPE_p_HWND {
private HandleRef swigCPtr;
internal SWIGTYPE_p_HWND(IntPtr cPtr, bool futureUse) {
swigCPtr = new HandleRef(this, cPtr);
}
protected SWIGTYPE_p_HWND() {
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
internal static HandleRef getCPtr(SWIGTYPE_p_HWND obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
}
so, i call GetWindowText like so:
if (GetWindowText(SWIGTYPE_p_HWND.getCPtr(hwnd).Handle.ToInt32(), Buff, 256) > 0)
{
int nothing = 0;
}
but it fails. I've checked to make sure i can get a valid hwnd from my dll using a c++ test that uses the code, and it works fine. any ideas? Cheers, Fabian