Error 61 when using printf from Plugin

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.

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

1 Like

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.

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.

I am also looking for some help for the same case. I want to print a text to interpretation window from the DLL. Its not like hiding hide everything and print without end users knowledge. Its for to protecting the end users code from misuse by others.

It is clearly written in the manual why Error 61.
The function performs a check for matching arguments and format.
Like the OP, if you are going to pass 20 floating values, the format string should obviously have 20 format specifiers.

I have a test function made with one argument and one format string. But still that also showing error. Error is Error 27. Invalid number of arguments passed from Call function (printf) from plugin DLL

My test code is

AmiVar MyFunction(int NumArgs, AmiVar* ArgsTable)
{
	AmiVar result = gSite.AllocArrayResult();
	AmiVar args[2];
	args[0].type = VAR_STRING;
	args[0].string = "Test function %g";
	args[1].type = VAR_FLOAT;
	args[1].val = 10.53;
	gSite.CallFunction("printf", 2, args);

	return result;
}


FunctionTag gFunctionTable[] =
{
	"TestFun",{ MyFunction, 0, 0, 0, 0, NULL }
};


int gFunctionTableSize = sizeof(gFunctionTable) / sizeof(FunctionTag);

Any help on this will be very much appreciated.

Re-read previous response. The answer is already there. Use sprintf() from C runtime library. The string will be displayed in interpretation automatically if your function just returns string.

function Whatever()
{
 return "This will show in interpretation";
}

Whatever();

And again, the plugins ARE NOT for hiding the AFL code. Hiding AFL is a bad idea.
Black boxes are bad. Selling black boxes is worse. Using black boxes is the worst. People should never ever trade the system that they don't understand.

5 reasons why you should NOT write DLLs

3 Likes