Boris wrote:

matlab.Exec(execute.ClearArgs() << L"x=0:.03:1.5; figure;

plot(x,sin(x))");

causing program to crash

Looking at sysvari.h, I see ClearArgs() returns an AutoCmd, and AutoCmd does

have an << operator for wchar_t* input. However, looking at variant.cpp,

I see that it just passes the value to a Variant (specifically, to Variant::PutElement()),

and Variant interprets a wchar_t* value as a COM BSTR, which this is not.

You would have to use the WideString class to address that:

```
matlab.Exec(execute.ClearArgs() << WideString("x=0:.03:1.5; figure; plot(x,sin(x))").c_bstr());
```

matlab.Exec(execute.ClearArgs() << String("x=0:.03:1.5; figure; plot(x,sin(x)))");

does not compile due to ambiguity in << operator

as I mentioned

You did not mention an ambiguity error earlier.

AutoCmd does not have an << operator for String input. It has one for Variant

(which can be constructed from a String), and one for AnsiString (which can

also be constructed from a String). So the compiler does not know which

one to contructor. So you have to be more explicit:

```
matlab.Exec(execute.ClearArgs() << Variant(String("x=0:.03:1.5; figure; plot(x,sin(x)))")));
```

Or:

```
matlab.Exec(execute.ClearArgs() << AnsiString("x=0:.03:1.5; figure; plot(x,sin(x)))"));
```

matlab.Exec(execute.ClearArgs() << "x=0:.03:1.5; figure;

plot(x,sin(x))");

is causing program to crash

AutoCmd does not have an << operator for char* input. So the compiler has

to be doing an inplicit conversion to either Variant or AnsiString. I'm

leaning towards Variant, because Variant has been known to have problems

with char* values. So best to convert to WideString or AnsiString instead,

as shown above.

Matlab.OleProcedure(L"PutWorkspaceData", L"bbb", L"base", a);

executes fine, but does not do anything

Internally, OleProcedure() assigns the 2nd+ parameters to a TAutoArgs array.

Depending on the order of includes between utilcls.h and System.hpp, TAutoArgs

holds either TVariantT<VARIANT> or System::Variant values. Both accept wchar_t*

input, but both expect wchar_t* to be BSTR. So WideString to the rescue

again:

```
Matlab.OleProcedure(L"PutWorkspaceData", WideString("bbb"), WideString("base"),
a);
```

Matlab.OleProcedure( String("PutWorkspaceData"), String("bbb"),

String("base"), a);

'Bad Variable type'

That is odd, because TVariantT and Variant both support String input.

--

Remy Lebeau (TeamB)

Connect with Us