v2.32
 
How to use Renga as a local server

Overview

Since Renga API is built upon the COM technology, ways to access its functionality are not limited to writing plugins that run within Renga's process. Standalone applications can interoperate with Renga (running it as a local COM server), pretty much like a plugin does, except for a few differences discussed below.

Managing instances of the Application interface

  • To get an Application instance in a local client application, the dwClsContext argument in the call to CoCreateInstance() should be compatible with CLSCTX_LOCAL_SERVER;
  • Unlike a plugin, a local client application can only get a single Application instance per Renga process. Subsequent requests will launch new Renga instances.

Managing the lifetime of the Renga process

  • The Renga process that was launched by COM upon request of a local client doesn't quit automatically when the last reference to the Application instance is released.
  • It is possible to terminate Renga manually via IApplication::Quit(), which is equivalent to manually quitting the usual way.

Visibility of Renga's user interface

When launched by COM, Renga starts in invisible mode. To make its GUI visible (and accesible) for the user, an explicit call to IApplication::SetVisible() is required.

Local client example

C++

CoInitialize(nullptr);
auto renga = Renga::CreateApplication(CLSCTX_LOCAL_SERVER);
renga->PutVisible(VARIANT_TRUE);
renga->OpenProject(bstr_t(argv[1]));
... // use Renga someway
renga->CloseProject(VARIANT_TRUE);
// Quit explicitly:
renga->Quit();
CoUninitialize();

The other way is to use RAII:

CoInitialize(nullptr);
{
auto renga = Renga::CreateApplication(CLSCTX_LOCAL_SERVER);
renga->CloseProject(VARIANT_TRUE);
renga->OpenProject(bstr_t(argv[1]));
... // use Renga someway
renga->CloseProject(VARIANT_TRUE);
}
CoUninitialize();

C#

var renga = new Renga.Application(); // Same as plugin. .NET COM interop layer manages the difference itself.
renga.Visible = true;
renga.OpenProject(args[0]);
... // use Renga someway
renga.CloseProject(true);
// Quit explicitly:
renga.Quit();
// ...or release the COM reference manually:
System.Runtime.InteropServices.Marshal.ReleaseComObject(renga);

See also

Related samples

  • OpenSaveCloseProject
  • ExportIfcDwgDxf