Archive

Archive for April, 2005

Three new sites launched

Categories: Uncategorized

COM interoperability with Matlab 7 in C#

If you try to import Matlab 7.0’s com object into C#, you get this error when you try to call it using early binding.

MLApp.MLAppClass MyMatlab = new MLApp.MLAppClass();
textBox1.Text = MyMatlab.Execute("version");

results in:

An unhandled exception of type ‘System.InvalidCastException’ occurred
in Test version7.exe
 
Additional information: QueryInterface for interface MLApp.DIMLApp
failed. 
 
This is apparently due to a mix up with GUID’s for mlapp.tlb, so, instead of hacking with the registry to correct their GUID, you can alternatively use late binding on the object thus;

Type objFactoryType;
   objFactoryType = Type.GetTypeFromProgID("Matlab.Application");
   object objFactory;
   objFactory = Activator.CreateInstance(objFactoryType);
   object[] args = new object[1];
   args[0]="version";
   object retval;
   retval = objFactoryType.InvokeMember("Execute",BindingFlags.InvokeMethod,null,
           objFactory,args);
   MessageBox.Show(retval.ToString());

Which works fine…

Categories: Uncategorized

Accessing a database with Macomedia Director

Working on a university project which included a need for Macromedia Director to access a database (in my case, MS Access). I downloaded ADOXTRA.X32 from XtraMania.com, copied it into my D:Program FilesMacromediaDirector 8.5Xtras folder, then with a bit of tinkering, I wrote the following Lingo function:

on GetDatabaseField (SQL,Column)
 ADO = xtra("ADOxtra")
 ADO.Init(true)
 gRst = ADO.CreateObject(#Recordset)
 gRst.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Mode=Read;Data Source=" & the  moviePath & "prototype.mdb"
 gRst.cursorLocation=gRst.adUseClient
 gRst.LockType=gRst.adLockReadOnly
 gRst.CursorType=gRst.adOpenStatic
 gRst.Source=SQL
 gRst.Open()
 if gRst.Failed then
  alert gRst.LastError
  halt
 end if
 gRst.MoveFirst()
 retVal = gRst.fields[Column]
 gRst.Close()
 return retVal
end

Which is called with something along the lines as:

on

mouseDown me
  set the
text of member "DynamicText" = GetDatabaseField ("select firstname from people where id = 1 ","firstname")
end

Categories: Uncategorized