Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: starting engopen

Subject: starting engopen

From: Thomas

Date: 23 Nov, 2007 16:46:44

Message: 1 of 5

Folks,
I need some inspiration. On my private machine (Windows XP,
MS Visual C++ Express) the following code works fine:

#include <stdio.h>
#include "engine.h"
int main()
{
Engine *ep;
if (!(ep = engOpen("\0"))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}
engClose(ep);
return EXIT_SUCCESS;
}

On my machine at work MATLAB doesn't start. At both
machines I have the same MATLAB version (7.5). At work I am
using Windows, too. MATLAB is an environment variable and
can start from any path. I have used "matlab \regserver".
Here's the path of MATLAB on my machine

C:\Program Files\MATLAB\R2007b\bin

and here's my exe file generated by Visual C++ (it
compiles, so no problems with the embedding of the header
or the linking)...

C:\Documents and Settings\t.mysurname\winEngine\release

Maybe there is some more explicit way to start MATLAB. Or
shall I use a *.bat file?
It also doesn't seem to work if MATLAB is already open...
Any ideas?
Thomas

Subject: Re: starting engopen

From: Thomas

Date: 23 Nov, 2007 17:24:56

Message: 2 of 5

Ok, I have done some further research and here's what's
going on:


I see that Matlab boots up
when engOpen("\0") is executed, but then Matlab immediately
quits
before execution passes to the next line. I have tried
calling both
"matlab /regserver" and "matlab /Automation" from the
Windows command
line; both call up Matlab, but then Matlab still quits when
engOpen
is called.

I have no leads to determine the cause of the problem.

Any suggestions?

Thank you,
Thomas

compare with
http://www.code-hosting.com/Matlab/1552688-engOpen---
returns-NULL-after-upgrade-to-R14-SP3-on-XP

Subject: Re: starting engopen

From: James Tursa

Date: 23 Nov, 2007 20:31:54

Message: 3 of 5

On Fri, 23 Nov 2007 17:24:56 +0000 (UTC), "Thomas "
<thomas.schmelzer.nospam@gmail.com> wrote:

>Ok, I have done some further research and here's what's
>going on:
>
>
>I see that Matlab boots up
>when engOpen("\0") is executed, but then Matlab immediately
>quits
>before execution passes to the next line. I have tried
>calling both
>"matlab /regserver" and "matlab /Automation" from the
>Windows command
>line; both call up Matlab, but then Matlab still quits when
>engOpen
>is called.
>
>I have no leads to determine the cause of the problem.
>
>Any suggestions?
>
>Thank you,
>Thomas
>
>compare with
>http://www.code-hosting.com/Matlab/1552688-engOpen---
>returns-NULL-after-upgrade-to-R14-SP3-on-XP

Here is the MATLAB doc on this:

    External Interfaces Reference
    engOpen (C)

    Start MATLAB engine session
    C Syntax

    #include "engine.h"
    Engine *engOpen(const char *startcmd);

    Arguments

    startcmd
    
    String to start MATLAB process. On Windows, the startcmd string
must be NULL.


So here is what I use to open the engine on Windows XP:

ep = engOpen( NULL );

i.e., I am passing the NULL pointer to engOpen. You are not passing
the NULL pointer to engOpen, you are passing a valid string, namely

"\0"

This is a string with a valid memory address containing two
characters, the null character and another null character terminator.
Not the same thing as I am doing or what MATLAB doc says.

And remember the engine opens pointed to the default startup directory
for MATLAB, which may not be the same directory as your c program. If
you need help fixing that part let me know.

James Tursa

Subject: Re: starting engopen

From: Thomas

Date: 24 Nov, 2007 11:15:30

Message: 4 of 5

James Tursa <aclassyguywithaknotac@hotmail.com> wrote in
message <cjdek3lmoblqs33mibkf45l9bud8sil65v@4ax.com>...

James,
changing from "\0" to NULL doesn't change the behaviour in
my case. I have also tried strings like "matlab" or
strings like "startMatlab" where startMatlab.bat is a file
that can start Matlab and is located in the same folder as
the *.exe file of my program.

I think the problem is better described in my second
posting where I describe that MATLAB starts but closes
after a second. I wish I would know what's going on...

Can you please help me on that issue:
> And remember the engine opens pointed to the default
startup directory
> for MATLAB, which may not be the same directory as your
c program. If
> you need help fixing that part let me know.
>

I have read the MATLAB documenation and I have wasted
several hours with this problem.

Best,
Thomas


Subject: Re: starting engopen

From: sfreeman

Date: 03 Feb, 2008 17:21:01

Message: 5 of 5

>
> Can you please help me on that issue:
> > And remember the engine opens pointed to the default
> startup directory
> > for MATLAB, which may not be the same directory as your
> c program. If
> > you need help fixing that part let me know.
> >


with C-Code in Windows this works (needs afaik windows.h):

char dir[MAX_PATH];
GetCurrentDirectory(MAX_PATH,dir); /* get pwd*/
... (insert engOpen with your error handling here) ...
engEvalString(ep, strcat("cd ",dir)); /*change to directory
first*/
... (rest usage of engine) ...

it is not vanilla, but it works :o)
Mathworks could include a few more hints with c in the
example section, I think...

Regards,

Rainer

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
engopen sfreeman 03 Feb, 2008 12:25:07
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics