Interface with C#, Visual Studio 2010 Express

5 visualizzazioni (ultimi 30 giorni)
William
William il 25 Mag 2012
Hello,
I am trying to send data to MATLAB through C# and am getting the " No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))." exception. Full code and error posted below.
As shown, I add a reference (in my COM tab the only reference I find is "Matlab Application (Version 7.0) Type Library") and compile the project.
Basically upon running the code instantiates an MLAppClass object. This works fine, I see a Matlab Command window open up. But if I try to send data to the object, i.e. using even a basic ml.Execute("1+2"); or even ml.Quit(); and I get the error.
There was a post suggesting a registry key was wrong, but it didn't seem to help. I am running Matlab 7.0 and Visual Studio 2010.
Any suggestions? Thanks.
namespace cSharpCallsMATLAB
{
public class Form1 : System.Windows.Forms.Form
{
private MLApp.MLAppClass ml;
public Form1()
{
InitializeComponent();
ml = new MLApp.MLAppClass();
}
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void onButtonClick(object sender, System.EventArgs e)
{
resultBox.AppendText(ml.Execute("1+2") );
}
}
}
The exception is:
Unable to cast COM object of type 'System.__ComObject' to interface type 'MLApp.MLApp'.
This operation failed because the QueryInterface call on the COM component for the interface with IID '{669CEC93-6E22-11CF-A4D6-00A024583C19}' failed due to the following error:
No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Risposte (1)

Walter Roberson
Walter Roberson il 25 Mag 2012
You might have to (once) start up matlab from cmd and start it up with the /regserver flag, in order to register the automation server.
  1 Commento
William
William il 25 Mag 2012
Appreciate the quick response but unfortunately this is not the problem. I ran
C:\Program Files\MATLAB71\bin\win32>MATLAB.exe /regserver
and got the same result.
I found the other post where someone had the same problem, a responder said the GUID was messed up and needed to be changed, I cannot find much more about it:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/99105
Anyone else trying Matlab 7.0 with Visual Studio, or anyone familiar with newer versions of Matlab working?

Accedi per commentare.

Categorie

Scopri di più su MATLAB Compiler SDK in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by