Error 61 when using printf from Plugin


#1

Hi there.

Something must be wrong with this piece of code, as I get error 61.

AmiVar vars[21];
for (int i = 1; i < 21; i++) {
	vars[i].type = VAR_FLOAT; vars[i].val = EMPTY_VAL;
};
vars[0].type = VAR_STRING;
vars[0].string = (char *)gSite.Alloc(100);
strcpy(vars[0].string, "Testing printf %0.0f");
vars[1].val = 3;

AmiVar result = gSite.CallFunction("printf", 21, vars);

I initialize all 21 vars with VAR_FLOAT and EMPTY_VAL, put my format string in var[0] and my float value in var[1].

If I pass a format string with no '%' and only use vars[0] it still fails with error 61.

I have checked the vars array in the debugger and values seems to be as expected prior til calling CallFunction.

I hope somebody can see what is wrong.

Thanks in advance,

Freddy.


#2

Instead of going to such lengths to use CallFunction why don't you just use C runtime built-in function printf()/sprintf()

Really in C/C++ these functions are built-in.

AmiVar result;
result.type = VAR_STRING;
result.string = (char *) gSite.Alloc( 100 );

sprintf( result.string, "Testing printf %0.0f", 3.0 );

It is way shorter and straightforward. See: www.google.com/search?q=sprintf


#3

Hi Tomasz.

Thank you for your response.

I want the plugin function to print to the interpretation window. Any idea on how to accomplish that? Or do you suggest to just return the string to AFL and print from there?

Thanks,

Freddy.


#4

The goal of plugin interface is not to create black boxes that hide everything and the plugin should not directly write to interpretation window without end users knowledge.