Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

vNistelrooy

Someone explain this to me please.

This topic is 5295 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why does this:
DWORD CallFunction(DWORD func,size_t sz,const void* args)
{
    DWORD vreturn;
    __asm
    {
        mov   ecx, sz       // get size of buffer

        mov   esi, args     // get buffer

        sub   esp, ecx      // allocate stack space

        mov   edi, esp      // start of destination stack frame

        shr   ecx, 2        // make it dwords

        rep   movsd         // copy params to real stack

        call  [func]        // call the function

        mov   vreturn,  eax // save the return value

        add   esp, sz       // restore the stack pointer

    }
    return vreturn;
}

.......
.......

	struct
	{
		int n;
		char* str;
		char* ti;
		int ty;
	} t;
	t.str=new char[8];
	sprintf(t.str,"123t456");
	t.ti=new char[8];
	sprintf(t.ti,"title23");
	t.n=0;
	t.ty=MB_OK;
	CallFunction((DWORD)MessageBox,24,&t);
tells me that "the value of esp wasn''t correctly saved across a function call.... blablabla..."? MessageBox is declared as _cdecl, so it should be ok right?
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites
Advertisement
Oh I got, sz is 16bytes not 24bytes of course and MessageBox is _stdcall so there is no nedd to add esp, sz, mystery solved move along.



"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"



[edited by - CPPMaster Poppet on March 24, 2004 7:18:46 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by fredizzimo
Why does this thread appear in the lounge instead of the general programming forum?


Good question.

[Moved to: General Programming]

Share this post


Link to post
Share on other sites
quote:
Original post by fredizzimo
Why does this thread appear in the lounge instead of the general programming forum?


Because I''m too lazy to delete 3 and type 21.



"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!