Click here to Skip to main content
15,923,197 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Displaying images on a CDialog Pin
Beer2624-Jul-03 11:12
Beer2624-Jul-03 11:12 
GeneralRe: Displaying images on a CDialog Pin
Tom Archer24-Jul-03 15:00
Tom Archer24-Jul-03 15:00 
GeneralRe: Displaying images on a CDialog Pin
Michael Dunn24-Jul-03 12:39
sitebuilderMichael Dunn24-Jul-03 12:39 
GeneralRe: Displaying images on a CDialog Pin
Tom Archer24-Jul-03 13:17
Tom Archer24-Jul-03 13:17 
GeneralRe: Displaying images on a CDialog Pin
Ryan Binns24-Jul-03 15:11
Ryan Binns24-Jul-03 15:11 
GeneralSet multiple dialog activated status Pin
sdfdsfa24-Jul-03 10:29
sdfdsfa24-Jul-03 10:29 
GeneralRe: Set multiple dialog activated status Pin
Tom Archer24-Jul-03 14:59
Tom Archer24-Jul-03 14:59 
GeneralHGLOBAL question Pin
Beer2624-Jul-03 9:59
Beer2624-Jul-03 9:59 
Hey all,

I had a post on here about a week ago about executing code from memory instead of a PE file.

So far this is what I've done.

have this as the test code compiled
############################################
#include <stdio.h>

int main(int argc, char* argv[])
{
printf("Hello World!\n");
getc(stdin);
return 0;
}

compiled that and stored it as RCDATA resource 130 in my new project
############################################

this is the code I'm trying to execute it with, without writing it back to a file in my MFC dialog app


HRSRC hrInfo = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(130), RT_RCDATA);
HGLOBAL hbytes = LoadResource(AfxGetResourceHandle(), hrInfo);
int (*ptr)(int argc, char *str[]);
ptr = (int (__cdecl *)(int, char *[]))hbytes;
int j = 1; char *strs;
(*ptr)(j, &strs);

CODE DONE
######################################

MODIFIED:

I also tried reallocating it with a FIXED flag, and it also didn't work

############ TRIED THIS TOO

HRSRC hrInfo = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(130), RT_RCDATA);
HGLOBAL hbytes = LoadResource(AfxGetResourceHandle(), hrInfo);
int size = (UINT)SizeofResource(AfxGetResourceHandle(), hrInfo);
HGLOBAL pexec = GlobalReAlloc(hbytes, size, GMEM_FIXED);
int (*ptr)(int argc, char* argv[]);
ptr = (int (__cdecl *)(int, char *[]))pexec;
int j = 1; char *strs;
(*ptr)(j, &strs);

################

OK, the function I cast it to matches that of the main of the test code. BUT, it gives me an access violation. WHY? HGLOBAL DATA is supposed to be executable from memory without any special function right?, Will this work with the HGLOBAL as is, or do I need to explicitly GlobalAlloc it?

I realize that this may be an advanced topic, and I urge some people to refrain from replying as that my last post got a couple of very ignorant responses. Thanks for your understanding.
GeneralRe: HGLOBAL question - ignorant response Pin
AlexO24-Jul-03 10:34
AlexO24-Jul-03 10:34 
GeneralRe: HGLOBAL question Pin
peterchen24-Jul-03 10:38
peterchen24-Jul-03 10:38 
GeneralRe: HGLOBAL question Pin
Beer2624-Jul-03 10:47
Beer2624-Jul-03 10:47 
GeneralRe: HGLOBAL question Pin
peterchen24-Jul-03 10:52
peterchen24-Jul-03 10:52 
GeneralRe: HGLOBAL question Pin
Terry O'Nolley24-Jul-03 10:47
Terry O'Nolley24-Jul-03 10:47 
GeneralRe: HGLOBAL question Pin
Beer2624-Jul-03 10:48
Beer2624-Jul-03 10:48 
GeneralInline function causing unresolved symbols. Pin
73Zeppelin24-Jul-03 8:53
73Zeppelin24-Jul-03 8:53 
GeneralRe: Inline function causing unresolved symbols. Pin
David Crow24-Jul-03 9:04
David Crow24-Jul-03 9:04 
GeneralRe: Inline function causing unresolved symbols. Pin
73Zeppelin24-Jul-03 9:05
73Zeppelin24-Jul-03 9:05 
GeneralRe: Inline function causing unresolved symbols. Pin
David Crow24-Jul-03 9:09
David Crow24-Jul-03 9:09 
GeneralRe: Inline function causing unresolved symbols. Pin
73Zeppelin24-Jul-03 9:19
73Zeppelin24-Jul-03 9:19 
GeneralRe: Inline function causing unresolved symbols. Pin
David Crow24-Jul-03 9:22
David Crow24-Jul-03 9:22 
GeneralRe: Inline function causing unresolved symbols. Pin
73Zeppelin24-Jul-03 9:24
73Zeppelin24-Jul-03 9:24 
GeneralRe: Inline function causing unresolved symbols. Pin
73Zeppelin24-Jul-03 9:07
73Zeppelin24-Jul-03 9:07 
GeneralRe: Inline function causing unresolved symbols. Pin
Tim Smith24-Jul-03 9:09
Tim Smith24-Jul-03 9:09 
GeneralRe: Inline function causing unresolved symbols. Pin
73Zeppelin24-Jul-03 9:13
73Zeppelin24-Jul-03 9:13 
GeneralRe: Inline function causing unresolved symbols. Pin
John M. Drescher24-Jul-03 9:37
John M. Drescher24-Jul-03 9:37 

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.