Thread overview
Symbol Undefined _EnumWindows@12
Jan 23, 2014
AntonSotov
Jan 23, 2014
Daniel Murphy
Jan 24, 2014
AntonSotov
Jan 23, 2014
Adam D. Ruppe
Jan 23, 2014
Jacob Carlborg
January 23, 2014
hello.
having trouble importing WinAPI function EnumWindows.
example:

//******************************************
module main;
pragma(lib, "user32");

alias int function (void*, long)  WNDENUMPROC;
extern (Windows) int EnumWindows(WNDENUMPROC, long);
//extern (Windows) void* CreateToolhelp32Snapshot(int, int);

int main(string[] args)
{
   //auto hSnapshot = CreateToolhelp32Snapshot(0x2, 0);
   EnumWindows( &EnumWindowsProc, 0 );
   return 0;
}

int EnumWindowsProc(void* hwnd, long lParam) {
   return 1;
}
/ / ******************************************
have when compiling error:
Symbol Undefined _EnumWindows@12

other WinAPI functions imported successfully.
the reason for the error?
January 23, 2014
"AntonSotov"  wrote in message news:qyxvsktbxokfhwebgwdk@forum.dlang.org...
> extern (Windows) int EnumWindows(WNDENUMPROC, long);

The second argument is LPARAM, which maps to C's long, but D's long maps to C's long long.

To be safe, use these aliases whenever possible by using:

import core.sys.windows.windows; 

January 23, 2014
On Thursday, 23 January 2014 at 17:22:55 UTC, AntonSotov wrote:
> alias int function (void*, long)  WNDENUMPROC;
> extern (Windows) int EnumWindows(WNDENUMPROC, long);

These shouldn't be longs. You could call them LPARAM (import core.sys.windows.windows) or int.

A "long" in C is actually an "int" in D. D's "long" is more like C's "long long".
January 23, 2014
On 2014-01-23 18:27, Adam D. Ruppe wrote:

> These shouldn't be longs. You could call them LPARAM (import
> core.sys.windows.windows) or int.
>
> A "long" in C is actually an "int" in D. D's "long" is more like C's
> "long long".

A "long" in C is actually a D "int" on Windows. On Posix it's a D "int" when compiling for 32bit and a D "long" when compiling for 64bit. This is a simplification that holds for the most common platforms available today. For more details see:

http://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models

-- 
/Jacob Carlborg
January 24, 2014
all thank you very much! realized my mistake.