Re: Same code problem
- From: Robby <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 22 Jan 2009 17:26:01 -0800
Hello everyone,
Can someone confirm to me that there officially is a compiler issue here. I
finaly got the function pointer code to compile in my compiler.... I did some
changes that can probably identify that there is an offcial problem with the
PIC compiler I am using. (Nothing new for everyone in this community I
guess:-) ) I will let you guys decide based on the following discrepencies.
Okay here is the full compilable code for the PIC compiler:
=================================krn.h
typedef long *LRESULT;
typedef long WPARAM;
typedef long LPARAM;
typedef struct tagWnd *pWND;
typedef struct tagHwnd
{ pWND handle;
} HWND;
typedef LRESULT (*WNDPROC)(HWND, long, WPARAM, LPARAM);
typedef struct tagWnd{
WNDPROC lpfnWndProc;
int style;
long backGround;
long titleMsg;
long extra;
} WND;
typedef struct tagRwp{
HWND hwnd;
int showWinEnable;
} RWP;
typedef struct tagMsg{
HWND hwnd;
long msg;
WPARAM wParam;
LPARAM lParam;
long time;
} KM_MSG, *pKM_MSG;
RWP rwp[3] = {0,0,0,0,0,0};
void ULC_KERNEL_dispatch_message(KM_MSG *K);
=====================================krn.c
#include <stdlio.h> // CCS LIBRARY STANDARD LIBRARY
#include <KERNEL.h> // KERNEL HEADER FILE!
LRESULT KWP(HWND x, long m, WPARAM w, LPARAM l);
LRESULT callerFunction(WNDPROC vWNDPROC, HWND h, long m, WPARAM w, LPARAM l);
void main()
{
KM_MSG u; // Create an KM_MSG object
pKM_MSG msg = &u; // Assign the address of a KM_MSG
WND wnd; // Create a WND object
// DEFINE A WINDOW!
wnd.lpfnWndProc = KWP; // Assign a function
wnd.style = 0; // Assign other stuff...
(rwp[0].hwnd).handle = &wnd; // Assign the address of a wnd object
msg->hwnd = rwp[0].hwnd; // Assign a hwnd to another hwnd
ULC_KERNEL_dispatch_message(msg); // Pass a pointer to a msg object
}
void ULC_KERNEL_dispatch_message(KM_MSG *msg)
{
LRESULT zzz;
HWND h;
WND * pwnd;
WNDPROC x;
h = msg->hwnd;
pwnd = h.handle;
x = pwnd->lpfnWndProc;
zzz = callerFunction(x, msg->hwnd, msg->msg, msg->wParam, msg->lParam);
}
LRESULT callerFunction(WNDPROC vWNDPROC, HWND h, long m, WPARAM w, LPARAM l)
{ return (*vWNDPROC) (h, m, w, l);
}
LRESULT KWP(HWND x, long m, WPARAM w, LPARAM l)
{//... other code ...
return 0;
}
============================================
The above compiles without errors or warnings!
However, if I do the following variations for the
ULC_KERNEL_dispatch_message() function, the program does not compile and
shows the error at the callerFunction line:
Variation#1
===========================================
void ULC_KERNEL_dispatch_message(KM_MSG *msg)
{
LRESULT zzz;
zzz = callerFunction(((msg->hwnd).handle)->lpfnWndProc, msg->hwnd, msg->msg,
msg->wParam, msg->lParam);
}
Variation#2
===========================================
void ULC_KERNEL_dispatch_message(KM_MSG *msg)
{
LRESULT zzz;
HWND h;
WND * pwnd;
h = msg->hwnd;
pwnd = h.handle;
zzz = callerFunction(pwnd->lpfnWndProc, msg->hwnd, msg->msg, msg->wParam,
msg->lParam);
}
=======================================
Why would I get errors when I try to dereference the function's name by
doing:
((msg->hwnd).handle)->lpfnWndProc
or doing:
(pwnd->lpfnWndProc)
and why would it compile without errors when I try to derefrence the
function's name by doing it the way with the x?
zzz = callerFunction(x, msg->hwnd, msg->msg, msg->wParam, msg->lParam);
Is this normal behaviour???????
Any comment is appreciated!
--
Best regards
Roberto
"Ben Voigt [C++ MVP]" wrote:
.You are right in that you can not use "void *handle" to point to a
function. You can forward declare pointers in a typedef, like this:
typedef node * pnode;
struct node {
pnode next;
int a,b,c;
};
=============================================
Now, I don't know how to make the link between what they are
suggesting and the typedefs that I have at the top of my header... ?
Here is what I tried:
typedef HWND * vHWND;
typedef struct tagHwnd{
//void *handle;
vHWND handle;
} HWND;
Notice the difference between his example, where you are forward using the
struct by its tag name, and your example, where you are forward using the
struct by its typedef name.
Try:
typedef struct tagWnd* pWND;
typedef struct tagHwnd { pWND handle; } HWND;
typedef struct tagWnd { ...... } WND;
- Follow-Ups:
- Re: Same code problem
- From: Giovanni Dicanio
- Re: Same code problem
- References:
- Same code problem
- From: Robby
- Re: Same code problem
- From: Ben Voigt [C++ MVP]
- Same code problem
- Prev by Date: Re: Same code problem
- Next by Date: Re: ? Using #'s in a Pre-proc Macro (Directives in Directives)
- Previous by thread: Re: Same code problem
- Next by thread: Re: Same code problem
- Index(es):
Relevant Pages
|
Loading