Croll
Croll

Reputation: 3791

Which module implements CreateWindowW on Windows?

I just came across issue in my application where i need to get static address of CreateWindowW function. Just like this:

&ShowWindow;

However, when doing the same trick with CreateWindowW, i get compiler error Identifier "CreateWindowW" is undefined (it's a macro). I actually cannot find where this function is defined (which DLL) and even pinvoke.net does not mention this.

On some website there is a mention it is user32.dll, but GetProcAddress for my function inside it returns null pointer. I am lost, which module on Windows is linked for this function?

If i try to connect debugger and trace call to this function, Visual Studio makes "Step over" it so i cannot understand where the call goes to..

My build is UNICODE. WinUser.h text i can see:

#define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
#define CreateWindowW(lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExW(0L, lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
#ifdef UNICODE
#define CreateWindow  CreateWindowW
#else
#define CreateWindow  CreateWindowA
#endif // !UNICODE

Upvotes: 1

Views: 2155

Answers (2)

Violet Giraffe
Violet Giraffe

Reputation: 33579

If you open the CreateWindow documentation on MSDN and scroll down, you will see that it is implemented as a wrapper around CreateWindowEx. And if you open the CreateWindowEx doc and scroll down, you'll see this:

image

So it's implemented in User32.dll.

Upvotes: 4

Cheers and hth. - Alf
Cheers and hth. - Alf

Reputation: 145279

CreateWindowExW is exported by user32.dll. You can just check the documentation. Or you can check the exports via e.g. Microsoft's dumpbin tool.

> dumpbin /exports c:\windows\system32\user32.dll | find /i "CreateWindow"

       1618   6D 0000A230 CreateWindowExA
       1619   6E 000107B8 CreateWindowExW
       1620   6F 00041530 CreateWindowStationA
       1621   70 000014D0 CreateWindowStationW

CreateWindowW is a thin wrapper implemented as a macro, according to its documentation:

CreateWindow is implemented as a call to the CreateWindowEx function, as shown below.

#define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)

#define CreateWindowW(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExW(0L, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)

#ifdef UNICODE
#define CreateWindow  CreateWindowW
#else
#define CreateWindow  CreateWindowA
#endif

You can also check that by e.g. “Go to definition” in Visual Studio.

Upvotes: 6

Related Questions