|
Can i type cast a function ?{{NO}}
say i have a function as
void Fun(int);
I have a function pointer
void(*p_fun)(int,int);
Can i type cast the p_fun to point to fun .
I know logically this is a big error but is it possible syntactically.
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
p_fun has been declared that it is a pointer to a funtion with 2 params, so AFIK its not going to work.
-Prakash
|
|
|
|
|
The sample code below illustrates how to use function pointers to call functions that take different parameters than those with which the pointer was declared. The function is cast to the type of the function pointer during the first assignment, then the function pointer is cast to the type of the function to be called. Using typedefs generally makes it easier than casting the pointer directly.
#include <stdio.h>
typedef int (*myintchartype) (char *, char *);
typedef void (*myvoidtype) (void);
typedef int (*myintvoidtype) (void);
int func1(char *, char *);
void func2(void);
void main(void)
{
myintvoidtype ptr;
ptr = (myintvoidtype) func1;
((myintchartype) ptr)("one", "two");
ptr = (myintvoidtype) func2;
((myvoidtype) ptr)();
}
int func1(char *a, char *b)
{
return printf("func1 took two parameters: %s and %s\n", a, b);
}
void func2(void)
{
printf("func2 did not take any parameters\n");
}
You can type cast functions.
Love Forgives--Love Gives--Jesus is Love <marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" style="background-color:'#44ccff'">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
u had to declare a function pointer thats 1 param or diff param, can you do the casting without that ?
-Prakash
|
|
|
|
|
hey i'm curious to know your name. if it's a Top-Secret you can just mail me. so that i'll start calling you with your name here.
"But your mind is very complex, very tricky. It makes simple things complicated. -- that's its work. And for centuries it has been trained for only one thing: to make things so complicated that your life becomes impossible."- Osho
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[V]--
|
|
|
|
|
T-1000 wrote: hey i'm curious to know your name.
T-1000 wrote: if it's a Top-Secret you can just mail me
T-1000 wrote: so that i'll start calling you with your name here
Love Forgives--Love Gives--Jesus is Love <marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" style="background-color:'#44ccff'">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
hey i'm curious to know your name. if it's a Top-Secret you can just mail me. so that i'll start calling you with your name here.
"But your mind is very complex, very tricky. It makes simple things complicated. -- that's its work. And for centuries it has been trained for only one thing: to make things so complicated that your life becomes impossible."- Osho
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[V]--
|
|
|
|
|
he he
Love Forgives--Love Gives--Jesus is Love <marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" style="background-color:'#44ccff'">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
so my friends is called "he-he".. okay..okay.. nice name buddy!
"But your mind is very complex, very tricky. It makes simple things complicated. -- that's its work. And for centuries it has been trained for only one thing: to make things so complicated that your life becomes impossible."- Osho
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[V]--
|
|
|
|
|
CIA is after me.
Love Forgives--Love Gives--Jesus is Love <marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" style="background-color:'#44ccff'">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
I dont know what difference do a name make ??
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Anything is possible if you use C style casting. You could, for example, get a void pointer to the function and then cast the void pointer back to p_fun.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
MDI application. How to resize childFrame to fit view, which is determined by grid control. They size of grid control changes. I want ChildFrame change correspondingly.
Thank you in advance.
|
|
|
|
|
ResizeParentToFit
This method allows the size of your view to dictate the size of its frame window. This is recommended only for views in MDI child frame windows. Use ResizeParentToFit in the OnInitialUpdate handler function of your derived view class.
ResizeParentToFit assumes that the size of the view window has been set. If the view window size has not been set when ResizeParentToFit is called, you will get an assertion. To ensure that this does not happen, make the following call before calling ResizeParentToFit:
GetParentFrame()->RecalcLayout();
Love Forgives--Love Gives--Jesus is Love <marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" style="background-color:'#44ccff'">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
I have two edit boxes. By default edit boxes allow copy, cut, paste and delete features. But now i should not allow copy, cut, paste and delete features in edit boxes.
knarasimharao
|
|
|
|
|
Override the WM_CUT, WM_COPY and WM_PASTE handlers.
You can leave the handlers empty.
Love Forgives--Love Gives--Jesus is Love <marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" style="background-color:'#44ccff'">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
I have a static control(derived from CStatic) and rich edit controls and it contains two lines. I want to set the color of the first line to blue and the second line to red. Currently I am using the CDialog::OnCtlColor and using the SetTextColor function to set the color. However it sets the color for the whole static control i.e. both the lines. Can someone help?
knarasimharao
|
|
|
|
|
Just an out line of procedure. customizee as you like
HWND hRichEdit = NULL;
CHARFORMAT* cf = NULL;
hRichEdit = (HWND)GetDlgItem (IDC_RICHEDIT);
CHARRANGE cr;
cr.cpMin = 0; // set strating char position
cr.cpMax = -1;// end char pos
SendMessage(hRichEdit, EM_EXSETSEL, 0, (LPARAM)&cr);
cf = new CHARFORMAT;
cf->cbSize = sizeof(CHARFORMAT);
cf->dwMask = CFM_COLOR |CFM_BOLD|CFM_FACE|CFM_SIZE|CFM_ITALIC;
cf->dwEffects = CFE_BOLD;
cf->crTextColor = RGB(255,0,0);
cf->yHeight = 160;
strcpy ( cf->szFaceName, "Ariel");
SendMessage( (HWND) hRichEdit, SCF_SELECTION, (WPARAM) SCF_ALL, (LPARAM) cf);
All the best
AnilFirst@gmail.com
|
|
|
|
|
anilFirst wrote: CHARFORMAT* cf = NULL;
Won't this work...
CHARFORMAT cf;
Love Forgives--Love Gives--Jesus is Love <marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" style="background-color:'#44ccff'">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
>>Won't this work...
>>CHARFORMAT cf;
It will....Carry on
AnilFirst@gmail.com
|
|
|
|
|
I have a static control(derived from CStatic) and rich edit controls and it contains two lines. I want to set the color of the first line to blue and the second line to red. Currently I am using the CDialog::OnCtlColor and using the SetTextColor function to set the color. However it sets the color for the whole static control i.e. both the lines. Can someone help?
knarasimharao
|
|
|
|
|
Hi
I have created a CButton in the following way.
CButton btnTemp;
UINT uiBtnStyle = BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP;
btnTemp->Create(szButtonName, uiBtnStyle, rectGroups, this, IDC_TEMP);
When I have focus on the button ,enter key press on the button does not trigger the Event for the button.
Someone tell me where I must have gone wrong.
Thanks,
Gayathri.
|
|
|
|
|
hi..
are u sure u have made a object btnTemp and used "->" operator and it ran with out any error.i have amazed?May u have mistaken while writing here.
Check out the declaration and definition for the massege map fuction of that button control.
birajendu
CyberG India
Delhi
India
|
|
|
|
|
Then do Space trigger the event
or
might be the button is not focued
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Hi ,
Pressing Space bar does trigger the event.
The problem is Enter Key does not and the button does have focus.
Thanks,
Gayathri
|
|
|
|