Click here to Skip to main content
15,949,686 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: string append with \ symbol Pin
Thilek24-Mar-09 3:14
Thilek24-Mar-09 3:14 
QuestionWriting a callback function? Pin
Maxwell Chen23-Mar-09 22:56
Maxwell Chen23-Mar-09 22:56 
AnswerRe: Writing a callback function? Pin
Eytukan23-Mar-09 23:06
Eytukan23-Mar-09 23:06 
GeneralRe: Writing a callback function? Pin
Maxwell Chen23-Mar-09 23:10
Maxwell Chen23-Mar-09 23:10 
GeneralRe: Writing a callback function? Pin
Eytukan23-Mar-09 23:17
Eytukan23-Mar-09 23:17 
AnswerRe: Writing a callback function? Pin
CPallini23-Mar-09 23:09
mveCPallini23-Mar-09 23:09 
GeneralRe: Writing a callback function? Pin
Maxwell Chen23-Mar-09 23:10
Maxwell Chen23-Mar-09 23:10 
AnswerRe: Writing a callback function? Pin
Iain Clarke, Warrior Programmer23-Mar-09 23:13
Iain Clarke, Warrior Programmer23-Mar-09 23:13 
I've been looking at callback stuff of my own, and if you your code to:

typedef void (*fC)(int* p);

bool Test(int n, fC p)
{
	int* pN = new int;
	*pN = 3;
	(p)(pN);    // ---- access violation 0xc0000005.
	delete pN;

	return true;
}

void fc(int* p)
{
	*p;
}


void main()
{
	Test(3, (fC)fc);
}


Then it works just fine...

But your code doesn't look bad to me. Just more indirection than you need. fC is already a type of "pointer to a function", so why make things work with "pointer to a pointer to a function"?

In the interests of science, I added these two lines to main:
fC p0 = fc;
fC *p1 = &fc;


And on the second line I get: "error C2440: 'initializing' : cannot convert from 'void (__cdecl *)(int *)' to 'void (__cdecl ** )(int *)'".

This leads me to suggest that you're seeing the same behaviour as when you try to get a pointer to an array - you get the first element of the array back. This is probably a C thing that's biting you. And then you manually cast it in your original main and things blow up later...

That's my theory, anyway!

Iain.

In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!

GeneralRe: Writing a callback function? Pin
Maxwell Chen23-Mar-09 23:21
Maxwell Chen23-Mar-09 23:21 
GeneralRe: Writing a callback function? Pin
CPallini23-Mar-09 23:23
mveCPallini23-Mar-09 23:23 
QuestionEmail Notification for Outlook Express 6 Pin
ganesh.dp23-Mar-09 22:50
ganesh.dp23-Mar-09 22:50 
AnswerRe: Email Notification for Outlook Express 6 Pin
Iain Clarke, Warrior Programmer23-Mar-09 22:58
Iain Clarke, Warrior Programmer23-Mar-09 22:58 
GeneralRe: Email Notification for Outlook Express 6 Pin
ganesh.dp23-Mar-09 23:09
ganesh.dp23-Mar-09 23:09 
QuestionHow to get IP address using getadpetrinfo function using c/c++ Pin
optical12323-Mar-09 22:39
optical12323-Mar-09 22:39 
AnswerRe: How to get IP address using getadpetrinfo function using c/c++ Pin
CPallini23-Mar-09 23:00
mveCPallini23-Mar-09 23:00 
QuestionRe: How to get IP address using getadpetrinfo function using c/c++ Pin
David Crow24-Mar-09 2:57
David Crow24-Mar-09 2:57 
QuestionDevice Driver Pin
brucewayn23-Mar-09 22:08
brucewayn23-Mar-09 22:08 
AnswerRe: Device Driver Pin
CPallini23-Mar-09 22:36
mveCPallini23-Mar-09 22:36 
AnswerRe: Device Driver Pin
Maxwell Chen23-Mar-09 23:00
Maxwell Chen23-Mar-09 23:00 
GeneralRe: Device Driver Pin
brucewayn24-Mar-09 1:08
brucewayn24-Mar-09 1:08 
AnswerRe: Device Driver Pin
«_Superman_»23-Mar-09 23:36
professional«_Superman_»23-Mar-09 23:36 
AnswerRe: Device Driver Pin
David Crow24-Mar-09 3:04
David Crow24-Mar-09 3:04 
QuestionUrlDownloadtofile Pin
p_196023-Mar-09 21:45
p_196023-Mar-09 21:45 
AnswerRe: UrlDownloadtofile Pin
Sarath C23-Mar-09 22:20
Sarath C23-Mar-09 22:20 
GeneralRe: UrlDownloadtofile Pin
p_196023-Mar-09 22:45
p_196023-Mar-09 22:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.