Jump to page: 1 2
Thread overview
Window procedure declaration
Mar 23, 2005
V
Mar 23, 2005
John C
Mar 23, 2005
Chris Sauls
Mar 23, 2005
John Reimer
Mar 23, 2005
Chris Sauls
Mar 23, 2005
V
Mar 23, 2005
John Reimer
Jan 07, 2009
Stewart Gordon
Jan 07, 2009
Stewart Gordon
Mar 23, 2005
Regan Heath
Mar 23, 2005
John Reimer
Mar 24, 2005
Regan Heath
March 23, 2005
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
March 23, 2005
"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


March 23, 2005
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
March 23, 2005
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

March 23, 2005
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
March 23, 2005
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?
March 23, 2005
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
March 23, 2005
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
March 23, 2005
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!
March 24, 2005
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
« First   ‹ Prev
1 2