Click here to Skip to main content
16,007,687 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Copying and executing code of a function Pin
Code-o-mat22-Apr-11 9:04
Code-o-mat22-Apr-11 9:04 
GeneralRe: Copying and executing code of a function Pin
Bashilein22-Apr-11 22:06
Bashilein22-Apr-11 22:06 
GeneralRe: Copying and executing code of a function Pin
barneyman23-Apr-11 2:22
barneyman23-Apr-11 2:22 
GeneralRe: Copying and executing code of a function Pin
Bashilein24-Apr-11 2:25
Bashilein24-Apr-11 2:25 
GeneralRe: Copying and executing code of a function Pin
David198724-Apr-11 8:01
David198724-Apr-11 8:01 
GeneralRe: Copying and executing code of a function Pin
Code-o-mat23-Apr-11 7:37
Code-o-mat23-Apr-11 7:37 
GeneralRe: Copying and executing code of a function Pin
barneyman23-Apr-11 23:12
barneyman23-Apr-11 23:12 
GeneralRe: Copying and executing code of a function Pin
Code-o-mat24-Apr-11 5:26
Code-o-mat24-Apr-11 5:26 
I wonder if this could work and how reliable it would be:
#include "stdafx.h"
#include "windows.h"
#include "conio.h"

//If this method is called with pSize set to non-null, it should returns its near its full size in it
long ThisIsAFunction(unsigned long *pSize, int other_parameters)
{
  if (pSize != NULL) goto ThisIsTheEnd;
  
  //---- Actual program code ----
  return other_parameters + 1;

ThisIsTheEnd:
  unsigned long EndAddress;

  __asm {
    push eax
    mov eax, ThisIsTheEnd
    mov EndAddress, eax
    pop eax
  }
  *pSize = (EndAddress - (unsigned long)(unsigned long long)ThisIsAFunction);
  return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
  unsigned long Size;
  ThisIsAFunction(&Size, 0);

  printf("Start of function: %p\nLength: %d bytes\n", ThisIsAFunction, Size);
  getch();

	return 0;
}
Also, i wonder if compile-time optimization(s) could ruin it, if it works at all.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<

GeneralRe: Copying and executing code of a function Pin
Bashilein24-Apr-11 6:57
Bashilein24-Apr-11 6:57 
GeneralRe: Copying and executing code of a function Pin
Code-o-mat24-Apr-11 7:11
Code-o-mat24-Apr-11 7:11 
GeneralRe: Copying and executing code of a function Pin
Bashilein25-Apr-11 22:21
Bashilein25-Apr-11 22:21 
GeneralRe: Copying and executing code of a function Pin
Code-o-mat26-Apr-11 7:39
Code-o-mat26-Apr-11 7:39 
QuestionReferring CChildFrame variable Pin
Anu_Bala21-Apr-11 22:46
Anu_Bala21-Apr-11 22:46 
QuestionExtended Keys in WM_KEYDOWN and WM_KEYUP ? Pin
nitin321-Apr-11 22:25
nitin321-Apr-11 22:25 
AnswerRe: Extended Keys in WM_KEYDOWN and WM_KEYUP ? Pin
Hans Dietrich21-Apr-11 23:12
mentorHans Dietrich21-Apr-11 23:12 
GeneralRe: Extended Keys in WM_KEYDOWN and WM_KEYUP ? Pin
nitin321-Apr-11 23:30
nitin321-Apr-11 23:30 
Questionis there any variable change event to notify in MFC Pin
manoharbalu21-Apr-11 22:18
manoharbalu21-Apr-11 22:18 
AnswerRe: is there any variable change event to notify in MFC Pin
Richard MacCutchan21-Apr-11 22:53
mveRichard MacCutchan21-Apr-11 22:53 
AnswerRe: is there any variable change event to notify in MFC Pin
Hans Dietrich21-Apr-11 23:14
mentorHans Dietrich21-Apr-11 23:14 
AnswerRe: is there any variable change event to notify in MFC Pin
Albert Holguin22-Apr-11 8:36
professionalAlbert Holguin22-Apr-11 8:36 
QuestionIncremental search method for CEditview or CRicheditView Pin
ganesh.dp21-Apr-11 20:58
ganesh.dp21-Apr-11 20:58 
AnswerRe: Incremental search method for CEditview or CRicheditView Pin
Mattias G21-Apr-11 22:05
Mattias G21-Apr-11 22:05 
Questionhow to detect a variable change in MFC Pin
manoharbalu21-Apr-11 18:55
manoharbalu21-Apr-11 18:55 
AnswerRe: how to detect a variable change in MFC Pin
«_Superman_»21-Apr-11 20:19
professional«_Superman_»21-Apr-11 20:19 
GeneralRe: how to detect a variable change in MFC Pin
manoharbalu21-Apr-11 21:05
manoharbalu21-Apr-11 21:05 

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.