Accessing WIN32 API functions from C++ CLI

0.00 avg. rating (0% score) - 0 votes

First, add the following declaration to stdafx.h:

// TODO: reference additional headers your program requires here
#include “windows.h”

For example, when calling SendMessage, take note of the double colon at the beginning:
::SendMessage((HWND)this->button1->Handle.ToInt32(), WM_LBUTTONDOWN, 0, 0);

The following would not work:
SendMessage((HWND)this->button1->Handle.ToInt32(), WM_LBUTTONDOWN, 0, 0);

and result in the following error:
error C2661: ‘System::Windows::Forms::Control::SendMessage’ : no overloaded function takes 4 arguments

If the error still persists, check Project Properties->Linker->Input->Additional dependencies. Click the button with the dots and turn on the checkbox for “Inherit from parent…”
0.00 avg. rating (0% score) - 0 votes


A tough developer who likes to work on just about anything, from software development to electronics, and share his knowledge with the rest of the world.

One thought on “Accessing WIN32 API functions from C++ CLI

  • September 29, 2013 at 3:33 am

    So what do you do when the same API call is defined in multiple win32api headers….. i.e. NetShareEnum in LMShare.h and SvrAPI.h.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>