Click here to Skip to main content
15,895,799 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Windows 7 compatible code in VC++ MFC Pin
Hans Dietrich28-Apr-11 4:10
mentorHans Dietrich28-Apr-11 4:10 
AnswerRe: Windows 7 compatible code in VC++ MFC Pin
Albert Holguin28-Apr-11 8:41
professionalAlbert Holguin28-Apr-11 8:41 
AnswerRe: Windows 7 compatible code in VC++ MFC Pin
Andrew Phillips30-Apr-11 6:16
Andrew Phillips30-Apr-11 6:16 
QuestionIs PnP Device ID unique Pin
champ2328-Apr-11 2:42
champ2328-Apr-11 2:42 
AnswerRe: Is PnP Device ID unique Pin
Hans Dietrich28-Apr-11 4:12
mentorHans Dietrich28-Apr-11 4:12 
QuestionBitmap in List control Pin
Anu_Bala28-Apr-11 0:28
Anu_Bala28-Apr-11 0:28 
QuestionRe: Bitmap in List control Pin
David Crow28-Apr-11 3:16
David Crow28-Apr-11 3:16 
QuestionC++ program and my __asm Pin
francesco.s27-Apr-11 23:51
francesco.s27-Apr-11 23:51 
Hi everybody,

I hope you guys don't mind if I ask you a question about assembly in the C/C++ section. I used to love this forum since when I've received help to fix a bug in the program I developed for my thesis.

I have a win32 console application written in C++ and a function which invokes the assembler inline (__asm). I need to use assembly in this function for technical reason.

I would like to write the assembler code that calls the API WinExec and then ExitProcess. I have tried to do that in 3 different ways but no one worked. Result, my machine crash.

1) db is not allow in Visual C++ within __asm, so the following solution has to be replaced with the #2.

jmp short GetCommand
CommandReturn:
pop ebx

xor eax,eax
push eax
push ebx
mov ebx,0x7c8615b5 ;place address of WinExec into ebx
call ebx

xor eax,eax
push eax
mov ebx, 0x7c81ca82 ;place address of ExitProcess into ebx
call ebx

GetCommand:
call CommandReturn
db "calc.exe"
db 0x00

2) This can be compiled and run but it makes the machine crash. It seems the address of WinExec it's wrong and the system get lost. So I have tried the #3. (below only the WinExec)

mov ebp,esp
push 0x20657865 ; I have also tried with 20657865H, Is there any difference?
push 0x2e646d63
lea eax,dword ptr ss:[ebp-8]
push eax
mov eax,0x7c86114d
call eax

3) In the code below I define a pointer to const char c which point to the string that i want to pass as a parameter to the Exec call. I also use the name of the API function instead of the address. Result the code has been compiled but the machine crash.


const char* c = "calc.exe";

int foo()
{
_asm{
push c
xor eax,eax
push eax
call WinExec
xor eax,eax
push eax
call ExitProcess
}
}


That's all. I hope this make sense. Cool | :cool:

Thanks,
FS
AnswerRe: C++ program and my __asm Pin
Richard MacCutchan28-Apr-11 1:27
mveRichard MacCutchan28-Apr-11 1:27 
AnswerRe: C++ program and my __asm Pin
Hans Dietrich28-Apr-11 7:12
mentorHans Dietrich28-Apr-11 7:12 
AnswerRe: C++ program and my __asm Pin
Andrew Phillips30-Apr-11 4:49
Andrew Phillips30-Apr-11 4:49 
QuestionHow to use the mysql in the child thread ? Pin
wangningyu27-Apr-11 21:42
wangningyu27-Apr-11 21:42 
AnswerRe: How to use the mysql in the child thread ? Pin
_AnsHUMAN_ 27-Apr-11 23:58
_AnsHUMAN_ 27-Apr-11 23:58 
QuestionHow do i get a InterlockedCompare ? Pin
cl_gamer27-Apr-11 15:52
cl_gamer27-Apr-11 15:52 
AnswerRe: How do i get a InterlockedCompare ? Pin
Luc Pattyn27-Apr-11 17:08
sitebuilderLuc Pattyn27-Apr-11 17:08 
QuestionHow to set EM_SETCUEBANNER in a Edit Control Pin
vishalgpt27-Apr-11 9:13
vishalgpt27-Apr-11 9:13 
AnswerRe: How to set EM_SETCUEBANNER in a Edit Control Pin
krmed27-Apr-11 9:47
krmed27-Apr-11 9:47 
GeneralRe: How to set EM_SETCUEBANNER in a Edit Control Pin
vishalgpt27-Apr-11 17:05
vishalgpt27-Apr-11 17:05 
AnswerRe: How to set EM_SETCUEBANNER in a Edit Control Pin
«_Superman_»28-Apr-11 0:08
professional«_Superman_»28-Apr-11 0:08 
GeneralRe: How to set EM_SETCUEBANNER in a Edit Control Pin
krmed28-Apr-11 3:36
krmed28-Apr-11 3:36 
QuestionSleep in Button Click Pin
varunpandeyengg27-Apr-11 0:20
varunpandeyengg27-Apr-11 0:20 
AnswerRe: Sleep in Button Click Pin
_AnsHUMAN_ 27-Apr-11 0:42
_AnsHUMAN_ 27-Apr-11 0:42 
GeneralRe: Sleep in Button Click Pin
varunpandeyengg27-Apr-11 1:19
varunpandeyengg27-Apr-11 1:19 
GeneralRe: Sleep in Button Click Pin
_AnsHUMAN_ 27-Apr-11 1:50
_AnsHUMAN_ 27-Apr-11 1:50 
GeneralRe: Sleep in Button Click Pin
varunpandeyengg27-Apr-11 1:56
varunpandeyengg27-Apr-11 1:56 

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.