How to Close COM server, Coinitiliaze has not been called

16 次查看(过去 30 天)
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');

回答(2 个)

Gordon W
Gordon W 2018-7-2
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 2014-7-25
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 个评论
Trey Moore
Trey Moore 2014-7-28
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 2014-7-28
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Use COM Objects in MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by