www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Symbol Undefined _EnumWindows 12

reply "AntonSotov" <nepuvive rainmail.biz> writes:
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?
Jan 23 2014
next sibling parent reply "Daniel Murphy" <yebbliesnospam gmail.com> writes:
"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;
Jan 23 2014
parent "AntonSotov" <nepuvive rainmail.biz> writes:
all thank you very much! realized my mistake.
Jan 24 2014
prev sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
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".
Jan 23 2014
parent Jacob Carlborg <doob me.com> writes:
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: -- /Jacob Carlborg
Jan 23 2014