How to pass flags of GfxSetTextAlign function from AFL Plugin?

I want to call this formula from my CPP plugin -

GfxSetTextAlign(6|24);

I am using this way -

      arg[0].type=VAR_FLOAT;
      arg[0].val=6;
      arg[1].type=VAR_FLOAT;
      arg[1].val=24;  
      gSite.CallFunction( "GfxSetTextAlign",2,arg);

but it is giving error.
My question is how I pass the Flag values? Should it be one string "6|24" or two float values?

@mahesh, the function requires only 1 (one) parameter.

So you should combine (a bitwise OR operation - i.e. 6|24) the different flags directly in your C++ code and pass them as a single parameter.

4 Likes

You should NOT be writing DLLs if you don't know what | operator is and that C has the same operator. So in C/C++ you would just write the same as in AFL, = 6 | 24;

DLLs as any other executable code have high potential of doing damage if user does not know what he/she is doing. Incorrect C code (like messing up pointers) leads to application crashes. Its like playing with fire. Stick with AFL. It protects you from shooting yourself in the foot. DLLs bring no advantages to AFL in 99% of cases. Just the opposite - DLL can run array code slower. They should NOT be used except for multiply-nested loops repeating millions of times.

1 Like

Thank you very much. Your reply really helped me and the error is resolved now . Thank you.

I am using DLL instead of AFL because I am working on a Trade Automation product and don't want to share the AFL code with Clients. Please bear me with my silly questions. Thnak you.

GfxSetTextAlign is NOT required for "trade automation".

You can use trade automation without writing a plugin. You can create your "trade automation" interface in ANY language and expose it as OLE/COM object. This can be accessed from AFL using CreateObject() function. This is recommended way to do things like trade automation (see IBController - automatic trading interface for Interactive Brokers for example is written this way). Separate exe means no impact on AmiBroker performance and no chance to cause any stability issues as exe lives in separate process that is independent.

DLLs on the other hand are loaded in the parent process (AmiBroker) and once your DLL has CPU it can totally crash parent application if is written incorrectly.

6 Likes

Dear @Tomasz,

I think you can write the above post "in your free time of course", in a slightly elaborate way and pin it up at the top of the list.

Most people come here with high hopes of hiding "Business Logic" in a DLL. If they can just do what they want in Java/ VBA/ C#/ Python and any other Language that is supported by COM/OLE, then it'll save time for all responding to them.

Your above post has a lot of logical statements, maybe even fit for a KB article.

2 Likes