Click here to Skip to main content
15,916,432 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Handling shell command line Pin
Allad24-Oct-05 6:51
Allad24-Oct-05 6:51 
GeneralRe: Handling shell command line Pin
David Crow24-Oct-05 7:07
David Crow24-Oct-05 7:07 
GeneralRe: Handling shell command line Pin
Allad26-Oct-05 9:04
Allad26-Oct-05 9:04 
GeneralRe: Handling shell command line Pin
Allad24-Oct-05 6:51
Allad24-Oct-05 6:51 
GeneralRe: Handling shell command line Pin
Allad24-Oct-05 6:51
Allad24-Oct-05 6:51 
Questionpointers to functions Pin
Mohammad A Gdeisat23-Oct-05 10:52
Mohammad A Gdeisat23-Oct-05 10:52 
AnswerRe: pointers to functions Pin
Chris Losinger23-Oct-05 14:53
professionalChris Losinger23-Oct-05 14:53 
GeneralRe: pointers to functions Pin
Mohammad A Gdeisat24-Oct-05 7:09
Mohammad A Gdeisat24-Oct-05 7:09 
Yesterday, when I was playing with Visual C++, I wrote this piece of code:


<br />
#include "iostream.h"<br />
#include "memory.h"<br />
int add(int a, int b)<br />
{<br />
	return a+b;<br />
}<br />
<br />
void main()<br />
{<br />
	typedef int (*func)(int,int);<br />
	func fp;<br />
	fp=add;<br />
<br />
	//allocate memory for the function<br />
	unsigned char *buffer=new unsigned char[100];<br />
	//copy instructions to new location<br />
	memcpy(buffer,fp,97);<br />
<br />
	//make the buffer a pointer to a function<br />
	func fp2;<br />
	fp2=(func)buffer;<br />
<br />
	//cout<<fp(5,6)<<endl;<br />
<br />
	//use the new function to calculate 5+6<br />
	cout<<fp2(5,6)<<endl;<br />
<br />
	//display function data<br />
	cout<<"Function data: \n";<br />
	<br />
	for (int a=0;a<97/4+1;a++)<br />
	{<br />
		cout<<hex<<((int*)buffer)[a]<<endl;<br />
	}<br />
	delete []buffer;<br />
}


I figured out the size of the "function instructions" by trial and error, it was 97 bytes.

After copying function data to a new location in memory and creating a pointer to function that points to the copied function in memory, it just executed normally and smoothly. I was amazed, really!!!

But till now, I have the problem of determining the size of the function data, and everythink will work fine for me....

Can you help me in this??? or anyone else.

Thank you all.....

And ever has it been that love knows not its own depth until the hour of separation
QuestionCombo Box, SetCurSel ( 0 ) Pin
kevincwong23-Oct-05 10:01
kevincwong23-Oct-05 10:01 
AnswerRe: Combo Box, SetCurSel ( 0 ) Pin
Graham Bradshaw23-Oct-05 10:22
Graham Bradshaw23-Oct-05 10:22 
AnswerRe: Combo Box, SetCurSel ( 0 ) Pin
Mohammad A Gdeisat23-Oct-05 10:43
Mohammad A Gdeisat23-Oct-05 10:43 
GeneralRe: Combo Box, SetCurSel ( 0 ) Pin
kevincwong23-Oct-05 21:14
kevincwong23-Oct-05 21:14 
GeneralRe: Combo Box, SetCurSel ( 0 ) Pin
S Douglas24-Oct-05 0:17
professionalS Douglas24-Oct-05 0:17 
GeneralRe: Combo Box, SetCurSel ( 0 ) Pin
kevincwong24-Oct-05 6:07
kevincwong24-Oct-05 6:07 
GeneralRe: Combo Box, SetCurSel ( 0 ) Pin
S Douglas24-Oct-05 12:24
professionalS Douglas24-Oct-05 12:24 
QuestionCListCtrl hook error Pin
Member 230136023-Oct-05 6:45
Member 230136023-Oct-05 6:45 
AnswerRe: CListCtrl hook error Pin
steven_wsy23-Oct-05 23:38
steven_wsy23-Oct-05 23:38 
QuestionCTreeView Form Pin
Gamil Mohamad23-Oct-05 4:21
Gamil Mohamad23-Oct-05 4:21 
AnswerRe: CTreeView Form Pin
Member 230136023-Oct-05 6:51
Member 230136023-Oct-05 6:51 
AnswerRe: CTreeView Form Pin
Mohammad A Gdeisat23-Oct-05 10:46
Mohammad A Gdeisat23-Oct-05 10:46 
Question16 Byte alignment support Pin
Remco Hoogenboezem23-Oct-05 4:15
Remco Hoogenboezem23-Oct-05 4:15 
QuestionCGridCtrl Resizing Columns Pin
markdanielmaltby23-Oct-05 3:00
markdanielmaltby23-Oct-05 3:00 
QuestionProblems with DirectX 8 SDK Pin
dudeua23-Oct-05 1:20
dudeua23-Oct-05 1:20 
AnswerRe: Problems with DirectX 8 SDK Pin
Gary R. Wheeler23-Oct-05 1:47
Gary R. Wheeler23-Oct-05 1:47 
GeneralRe: Problems with DirectX 8 SDK Pin
dudeua23-Oct-05 2:09
dudeua23-Oct-05 2:09 

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.