Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making my own Allegro Class so is more easy but I am having problem with ESP, I am getting Access Violation.

ASM
void RBAllegro::AddText( FONT *f, int x, int y, int color, int bg, const char *format)
{
    //textprintf_ex( m_Buffer, f, x, y, color, bg, format );
    __asm
    {
        push format;
        push bg;
        push color;
        push y;
        push x;
        push f;
        push m_Buffer;
        call textprintf_ex;
        add esp, 28;
    }
}
Posted
Updated 9-Jun-10 13:38pm
v2

Firstly, why the hell are you doing this? The compiler will do a getter job with the added advantage that it gets it right.

You haven't provided enough information. What's an "Allegro Class"? What's the calling convention of textprintf_ex (e.g. __stdcall, __cdecl or what)? Since the call looks right for a __cdecl call I'll assume it's __stdcall. In that case try this code:
__asm
{
    push format;
    push bg;
    push color;
    push y;
    push x;
    push f;
    push m_Buffer;
    call textprintf_ex;
}


__stdcall function clean up their own stacks.

On the other hand it may be a member function. In this case you'll need to pass the this pointer. Depending on the calling convention how you go about doing this will vary.

In summary:

    • Drop the assembly code.

    • If you must use assembly code some more information would be nice.

 
Share this answer
 
v4
From the docs:

void textprintf_ex(BITMAP *bmp, const FONT *f, int x, int y, int color, int bg, const char *fmt, ...);

Aren't you missing something? ... hint ...

Why do you use assembler? That's just crazy. You won't be able to optimize a function call.

Edit: ...or maybe not that crazy after all.

This should probably work for you if you don't use any format specifiers in your format string:
__asm
{
    push format;
    push bg;
    push color;
    push y;
    push x;
    push f;
    push m_Buffer;
    call dword ptr[textprintf_ex];
    add esp, 28;
}


When it comes to the varadic arguments you might be better off doing a memcpy from the stack, than trying to push a value at a time. Because in the latter case you will have to parse the format string to know the size of all parameters.

You can use &f as the source start and use an offset to the address of a volatile variable located in your function as a reference to the end of the memory block. You will only have to deal with m_Buffer as you do above.
 
Share this answer
 
v3
Comments
ReymonARG 9-Jun-10 18:40pm    
because I want to pass ... to the stack, but if this don't work, other don't will work.
I also try adding

push NULL; // at the first an adding 32. but don't work.
Look at the va_start, va_args and va_end macros. They're designed explicitly for handling variable parameter lists, including passing them onto other functions taking variable parameter lists.

Now the sermon...

Why, in C++, are you using variable parameter lists when the prevailing model for I/O uses insertion and extraction operators? What's wrong with having:

allegro_text_stream str( f, x, y, color, bg );

str << "The value of n is: " << n;


Have a read of "Standard C++ IOStreams and Locales" by Langer and Kreft, it's got all the gory details you'll need.

Cheers,

Ash
 
Share this answer
 
Comments
Niklas L 13-Jun-10 5:11am    
Of course if there isn't a different API for rendering text than stated above, don't forget to scan the input for format specifiers and replace appropriately. Otherwise you will be in for a nasty surprise when you try to render a man page for printf.
Aescleal 13-Jun-10 5:54am    
I was referring to his wrapper for textprintf_ex - implement that using streams so something like:

str << font << set_start( x, y ) << set_colour( red ) << "The value of n is: " << n << std::flush;

and then in the streambuffer you'd convert that into a call to textprintf_ex. It actually simplifies the call to textprintf_ex as you don't have to worry about the various optional doodads the stream converts it all to a single string to be converted.
Niklas L 13-Jun-10 8:57am    
Yes, but you need to take care of strings containing the % sign.

str << "Use %s to insert strings when using printf";

This will most likely generate an access violation, and certainly not give the output you'd expect using streams, unless you translate % into %% before calling textprintf_ex.
Aescleal 13-Jun-10 14:24pm    
Ah, I get your point. You mean you'd have to escape characters properly. Yep, you would - good point I didn't understand what you meant at first. Thanks for bearing with me!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900