REALconsoleSafe and not

How do I send a sample + plugin privately?

You subclass application class in a plugin?

No, that’s also not the case. perhaps the following may help:

[code]int myMain(REALstringArray argsString)
{
RBInteger nameCount = REALGetArrayUBound(argsString);

char* args[10];
for (RBInteger i = 0; i <= nameCount; i++)
{
    REALstring s;
    REALGetArrayValueString((REALarray)argsString, i, &s);
    
    size_t bytes;
    char* txt = (char*)REALGetStringContents(s, &bytes);
    _printf("%s\


", txt);
char line[_MAX_LINE_LENGTH];
memset(line, 0, _MAX_LINE_LENGTH);
strcpy (line, txt);
args[i]=line;
}

int result = main(nameCount+1, args);

BasData* data = gBasFirst;
return result;

}
[/code]

This is exposed to the caller of the plugin as a shared method of the “Basic” class:

{ (REALproc) myMain, REALnoImplementation, "Run(args() as string) as Integer", REALconsoleSafe },

and used in the Run event of the App class:

call Basic.Run(args)

It is redirected to the actual entry point of borrowed code:

[code]int main(int argc, char* argv) {
int status = 0;

#ifdef MB_CP_VC
_CrtSetBreakAlloc(0);
#endif /* MB_CP_VC */

atexit(_on_exit);

if(setjmp(_mem_failure_point)) {
	_printf("Error: out of memory.\

");

	exit(1);
}

_on_startup();


BasData* data = gBasFirst;
if (!data) {
    exit(1);
}
if(argc >= 2) {
	if(!_process_parameters(data->self, argc, argv))
		argc = 1;
}
if(argc == 1) {
	_show_tip();
	do {
		status = _do_line(data->self);
	} while(_NO_END(status));
}

return 0;

}
[/code]

if this code runs several times, it registers the atexit handler several times.
I think this code needs to be modified, so you remove the atexit call and call _on_exit yourself before the end of the method.
Also you need to check what globals it uses, so you can restore them to start values.

[quote=307599:@Christian Schmitz]if this code runs several times, it registers the atexit handler several times.
[/quote]

I don’t think that this is the case. If the _process_parameters returns true and argc is not equal to 1, the app will end normally, right?

You need to remove the exit call anyway.
Calling exit will terminate the Xojo app.

I’ve wrapped shell tools myself. You need to change code to make sure it always ends with return, no exit, abort or uncaught C++ exceptions.
And you need to reset globals to start values before calling main as the shell tools expect that.

[quote=307606:@Christian Schmitz]You need to remove the exit call anyway.
Calling exit will terminate the Xojo app.

I’ve wrapped shell tools myself. You need to change code to make sure it always ends with return, no exit, abort or uncaught C++ exceptions.
And you need to reset globals to start values before calling main as the shell tools expect that.[/quote]

Ok, but calling manually _on_exit() at the end of main does not make a difference with respect to segmentation fault if REALUnlockObject is called. The _on_exit is called because I am jumping out of the while loop, to make sure that things get cleaned up. I haven’t even tried to call the app to do something interesting. Note that the call to exit is not invoked anyway. “status” gets a value that makes NO_END to become non-zero and we are leaving the interactive session. It then returns to the App.run event.

Also, main is not recognized by the compiler (Xcode) as the actual entry point, given the code is in the plugin. I appreciate your input.

By the way, the globals you mentioned were converted to class members; cleaning up and resetting is done in the destructor of the class. Again, thanks Christian.