www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Window procedure declaration

reply V <v pathlink.com> writes:
I can't seem to assign my WNDCLASSA structures wndproc field the same 
way I did in C.

<code>
WNDCLASSA wcex;
wcex.style		= 0;
wcex.lpfnWndProc	= cast(WNDPROC) wndProc;
</code>

Compiler errors:

App.d(40): function app.wndProc (HANDLE,uint,uint,int) does not match 
argument types ()
App.d(40): Error: expected 4 arguments, not 0


Also how do I declare the procedure?  This causes errors:

<code>
LRESULT CALLBACK wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM 
lParam)
</code>

app.d(62): semicolon expected, not 'wndProc'
app.d(62): found 'hWnd' when expecting ')'
app.d(62): semicolon expected, not 'message'
app.d(62): no identifier for declarator message
app.d(62): semicolon expected, not 'wParam'
app.d(62): no identifier for declarator wParam
app.d(62): semicolon expected, not 'lParam'
app.d(62): no identifier for declarator lParam
app.d(62): semicolon expected, not ')'
app.d(62): Declaration expected, not ')'
app.d(70): Declaration expected, not 'case'
app.d(77): Declaration expected, not 'case'
app.d(81): Declaration expected, not 'case'
app.d(91): Declaration expected, not 'default'
app.d(93): unrecognized declaration
Mar 22 2005
next sibling parent "John C" <johnch_atms hotmail.com> writes:
"V" <v pathlink.com> wrote in message 
news:d1r499$1jh3$1 digitaldaemon.com...
I can't seem to assign my WNDCLASSA structures wndproc field the same way I 
did in C.

 <code>
 WNDCLASSA wcex;
 wcex.style = 0;
 wcex.lpfnWndProc = cast(WNDPROC) wndProc;
 </code>

Use the address of the function instead. wcex.lpfnWndProc = &wndProc;
 Compiler errors:

 App.d(40): function app.wndProc (HANDLE,uint,uint,int) does not match 
 argument types ()
 App.d(40): Error: expected 4 arguments, not 0


 Also how do I declare the procedure?  This causes errors:

 <code>
 LRESULT CALLBACK wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM 
 lParam)
 </code>

 app.d(62): semicolon expected, not 'wndProc'
 app.d(62): found 'hWnd' when expecting ')'
 app.d(62): semicolon expected, not 'message'
 app.d(62): no identifier for declarator message
 app.d(62): semicolon expected, not 'wParam'
 app.d(62): no identifier for declarator wParam
 app.d(62): semicolon expected, not 'lParam'
 app.d(62): no identifier for declarator lParam
 app.d(62): semicolon expected, not ')'
 app.d(62): Declaration expected, not ')'
 app.d(70): Declaration expected, not 'case'
 app.d(77): Declaration expected, not 'case'
 app.d(81): Declaration expected, not 'case'
 app.d(91): Declaration expected, not 'default'
 app.d(93): unrecognized declaration 

Mar 23 2005
prev sibling next sibling parent reply Chris Sauls <ibisbasenji gmail.com> writes:
V wrote:
 Also how do I declare the procedure?  This causes errors:
 
 <code>
 LRESULT CALLBACK wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM 
 lParam)
 </code>

You need to use D's extern attribute. I believe this is the correct way: # extern(Win32) # LRESULT wndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { # // ... # } -- Chris Sauls
Mar 23 2005
parent reply John Reimer <brk_6502 yahoo.com> writes:
Chris Sauls wrote:
 V wrote:
 
 Also how do I declare the procedure?  This causes errors:

 <code>
 LRESULT CALLBACK wndProc(HWND hWnd, UINT message, WPARAM wParam, 
 LPARAM lParam)
 </code>

You need to use D's extern attribute. I believe this is the correct way: # extern(Win32) # LRESULT wndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { # // ... # } -- Chris Sauls

Actually this should be "extern(Windows)", but the idea was correct. His problem seems to have arisen from an absence of both the "&" operator and the extern(Windows). -JJR
Mar 23 2005
parent reply Chris Sauls <ibisbasenji gmail.com> writes:
John Reimer wrote:
 Actually this should be "extern(Windows)", but the idea was correct.

I realized that about... three seconds ago. :) Alas. Also would be helpful to check out these two pages from the specs: http://www.digitalmars.com/d/windows.html http://www.digitalmars.com/d/dll.html -- Chris Sauls
Mar 23 2005
parent reply V <v pathlink.com> writes:
Chris Sauls wrote:
 John Reimer wrote:
 
 Actually this should be "extern(Windows)", but the idea was correct.

I realized that about... three seconds ago. :) Alas. Also would be helpful to check out these two pages from the specs: http://www.digitalmars.com/d/windows.html http://www.digitalmars.com/d/dll.html -- Chris Sauls

Thank you all for the help :D I've noticed that some functions are missing from std.c.windows.windows like BOOL DestroyWindow(HWND hWnd) and BOOL UnregisterClassA(LPCSTR lpClassName, HINSTANCE hInstance) and some of the defines like WS_EX_CLIENTEDGE. Are any of these going to be added or do I have to define each function as an extern?
Mar 23 2005
parent reply John Reimer <brk_6502 yahoo.com> writes:
V wrote:
 Chris Sauls wrote:
 
 John Reimer wrote:

 Actually this should be "extern(Windows)", but the idea was correct.

I realized that about... three seconds ago. :) Alas. Also would be helpful to check out these two pages from the specs: http://www.digitalmars.com/d/windows.html http://www.digitalmars.com/d/dll.html -- Chris Sauls

Thank you all for the help :D I've noticed that some functions are missing from std.c.windows.windows like BOOL DestroyWindow(HWND hWnd) and BOOL UnregisterClassA(LPCSTR lpClassName, HINSTANCE hInstance) and some of the defines like WS_EX_CLIENTEDGE. Are any of these going to be added or do I have to define each function as an extern?

There are many win32 functions missing from std.c.windows.windows. Check www.dsource.org/projects/core32 for a more complete D win32 import. -JJR
Mar 23 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
John Reimer wrote:
<snip>
 There are many win32 functions missing from std.c.windows.windows. Check 
 www.dsource.org/projects/core32 for a more complete D win32 import.

That one's old and, by the looks of it, no longer maintained. You want this one: http://www.dsource.org/projects/bindings/wiki/WindowsApi Stewart.
Jan 06 2009
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Stewart Gordon wrote:
 John Reimer wrote:
 <snip>
 There are many win32 functions missing from std.c.windows.windows. 
 Check www.dsource.org/projects/core32 for a more complete D win32 import.

That one's old and, by the looks of it, no longer maintained. You want this one: http://www.dsource.org/projects/bindings/wiki/WindowsApi

Silly me, should've realised I was replying to an old thread. I guess it's one of the natural consequences of switching newsreaders. Stewart.
Jan 06 2009
prev sibling parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Tue, 22 Mar 2005 22:51:06 -0800, V <v pathlink.com> wrote:
 I can't seem to assign my WNDCLASSA structures wndproc field the same  
 way I did in C.

 <code>
 WNDCLASSA wcex;
 wcex.style		= 0;
 wcex.lpfnWndProc	= cast(WNDPROC) wndProc;
 </code>

 Compiler errors:

 App.d(40): function app.wndProc (HANDLE,uint,uint,int) does not match  
 argument types ()
 App.d(40): Error: expected 4 arguments, not 0

Try: wcex.lpfnWndProc = cast(WNDPROC)&wndProc;
 Also how do I declare the procedure?  This causes errors:

 <code>
 LRESULT CALLBACK wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM  
 lParam)
 </code>

 app.d(62): semicolon expected, not 'wndProc'
 app.d(62): found 'hWnd' when expecting ')'
 app.d(62): semicolon expected, not 'message'
 app.d(62): no identifier for declarator message
 app.d(62): semicolon expected, not 'wParam'
 app.d(62): no identifier for declarator wParam
 app.d(62): semicolon expected, not 'lParam'
 app.d(62): no identifier for declarator lParam
 app.d(62): semicolon expected, not ')'
 app.d(62): Declaration expected, not ')'
 app.d(70): Declaration expected, not 'case'
 app.d(77): Declaration expected, not 'case'
 app.d(81): Declaration expected, not 'case'
 app.d(91): Declaration expected, not 'default'
 app.d(93): unrecognized declaration

Remove "CALLBACK". Add extern(C) eg. extern (C) LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { } CALLBACK is typically a define for __stdcall which is replaced in D with extern (C), see: http://www.digitalmars.com/d/interface.html Regan
Mar 23 2005
parent reply John Reimer <brk_6502 yahoo.com> writes:
Regan Heath wrote:

 
 Remove "CALLBACK". Add extern(C) eg.
 
 extern (C) LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, 
 LPARAM  lParam)
 {
 }
 
 CALLBACK is typically a define for __stdcall which is replaced in D 
 with  extern (C), see:
 
 http://www.digitalmars.com/d/interface.html
 
 Regan

Oops. Good point, Regan. I missed the CALLBACK. Don't need that there!
Mar 23 2005
parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Wed, 23 Mar 2005 15:08:00 -0800, John Reimer <brk_6502 yahoo.com> wrote:
 Regan Heath wrote:

  Remove "CALLBACK". Add extern(C) eg.
  extern (C) LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam,  
 LPARAM  lParam)
 {
 }
  CALLBACK is typically a define for __stdcall which is replaced in D  
 with  extern (C), see:
  http://www.digitalmars.com/d/interface.html
  Regan

Oops. Good point, Regan. I missed the CALLBACK. Don't need that there!

Is it extern (C) or extern (Windows) though? I'm not sure. Regan
Mar 23 2005
parent "Carlos Santander B." <csantander619 gmail.com> writes:
Regan Heath wrote:
 On Wed, 23 Mar 2005 15:08:00 -0800, John Reimer <brk_6502 yahoo.com> wrote:
 
 Regan Heath wrote:

  Remove "CALLBACK". Add extern(C) eg.
  extern (C) LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam,  
 LPARAM  lParam)
 {
 }
  CALLBACK is typically a define for __stdcall which is replaced in D  
 with  extern (C), see:
  http://www.digitalmars.com/d/interface.html
  Regan

Oops. Good point, Regan. I missed the CALLBACK. Don't need that there!

Is it extern (C) or extern (Windows) though? I'm not sure. Regan

Windows _______________________ Carlos Santander Bernal
Mar 23 2005