Jump to content
  • Advertisement
Sign in to follow this  
supagu

win32 api in c#

This topic is 4816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
(Article, Linkified).

Define "fails", please [grin].



How have you declared GetWindowTextand Buff?
GetWindowText should be declared with the [DllImportAttribute("user32.dll")] attribute, and Buff should be declared as a StringBuilder.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!