How to Close COM server, Coinitiliaze has not been called

28 views (last 30 days)
I am having a problem closing an actxserver which is forcing me to close Matlab to run my program more than once. I have tried several codes to close the COM server, but I cannot get it to work. Anything I'm missing?
My Code:
h=actxserver('ServerName');
...code...
I have tried putting these at the end of my code:
Quit(h) as well as h.Quit
close(h) as well as h.close
delete(h) as well as h.delete
Error Given:
Error using feval
Server Creation Failed: CoInitialize has not been called.
Error in actxserver (line 87)
h=feval(['COM.' convertedProgID], 'server', machinename, interface);
Error in MMM_V1 (line 160)
h=actxserver('ServerName');

Answers (2)

Gordon W
Gordon W on 2 Jul 2018
In case someone is still in need of a solution, I found it here:
tl;dr: Use release(handle) for any handle that is connected to the COM server.

Image Analyst
Image Analyst on 25 Jul 2014
How about h.exit or h.Exit or h.shutdown? Or clear('h').
You need to get the commands that work with your server. Every program has different methods. I'm only familiar with Excel. Your server is not Excel is it?
  4 Comments
Trey Moore
Trey Moore on 28 Jul 2014
I do not see a server process still running under the name of the server, so I am guessing that the answer is no. That said I am not super familiar with COM.
Image Analyst
Image Analyst on 28 Jul 2014
Have it up and running when you launch. Does the process list grow longer when your server launches? It must be in there. Look at the process list when the server is supposed to be running of course, not after you think you shut it down. When you do go to shut it down, the list should shrink. Try to identify which process gets instantiated and destroyed as you do this. That will be the name of the server and I think it should be the same name you used in your MATLAB application.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!