PizzaWizard
PizzaWizard
CC#
Created by PizzaWizard on 8/15/2024 in #help
Understanding COM interface references for an ASP.NET REST API...
Hi all, I'm new-ish to Windows, so forgive me but my knowledge of COM is pretty amateur. I'm running a simulation application on a backend server that implements the COM interface IDispatch to create an interface called IRemoteControl like so:
interface IRemoteControl : IDispatch
{
HRESULT NewModel();
HRESULT LoadModel(BSTR);
HRESULT SaveModel(BSTR);
HRESULT CloseModel();
HRESULT StartSimulation(BSTR);
HRESULT StopSimulation();
HRESULT ResetSimulation(BSTR);
HRESULT GetValue(BSTR,[out,retval]VARIANT*);
HRESULT SetValue(BSTR,VARIANT);
HRESULT Quit();
};
interface IRemoteControl : IDispatch
{
HRESULT NewModel();
HRESULT LoadModel(BSTR);
HRESULT SaveModel(BSTR);
HRESULT CloseModel();
HRESULT StartSimulation(BSTR);
HRESULT StopSimulation();
HRESULT ResetSimulation(BSTR);
HRESULT GetValue(BSTR,[out,retval]VARIANT*);
HRESULT SetValue(BSTR,VARIANT);
HRESULT Quit();
};
We have a single host machine and expect 4-6 users at a time to be sending messages over an API to start, stop, and reset simulations all running on separate instances of this application on the backend server. I can start the program and manipulate it quite easily in ASP.NET. I import the application's included Type Library DLL as a project dependency, then I can do something like
[HttpPost("remote-control/create")]
public IActionResult CreateRemoteControl(string? updatedPath)
{
RemoteControl remoteControl = new();
return OK();
// Handle other cases, etc.
}
[HttpPost("remote-control/create")]
public IActionResult CreateRemoteControl(string? updatedPath)
{
RemoteControl remoteControl = new();
return OK();
// Handle other cases, etc.
}
Whenever I send subsequent calls over a different route to do something like start/stop/reset the simulation, I'm able to do so on the most recently-spawned application instance. However, when multiple users are connected to this server at the same time, I want to be able to assign each user a specific instance of this application, so that subsequent calls only affect that user's instance (so that a user can't send a "reset" message that resets the most recently spawned process, even if it was spawned by another user). I can find the process ID of a spawned RemoteControl object using string currentProcessID = remoteControl.GetCurrentProcessId().ToString();, but I don't know how to use that to restrict commands to specific COM interfaces.
10 replies