Hide ctfserver popup window when using OutOfProcessAttribute with MCR .NET Data API?
조회 수: 3 (최근 30일)
이전 댓글 표시
I'm working on a .NET 6 application using the newly-released .NET Data API from R2022b to call Matlab functions contained in a ctf archive. I'd like to run Matlab out-of-process, and the OutOfProcessAttribute provided by the Matlab API appears to work beautifully for this purpose, except it pops up an empty command prompt window for each instance of ctfserver.exe that gets launched that lasts until the Matlab process is terminated. Is there a way to run the Matlab runtime out-of-process without displaying this window?
Thanks.
댓글 수: 1
Claudio Alvarez
2023년 5월 2일
I have the same problem but with the C++ Data API ctf archive. When I run the my application using the OUT_OF_PROCESS flag the ctfserver.exe runs in a command window and the app consume 50 MB, and the app runs without any problem. When I use the IN_PROCESS flag the app consum 500 MB and crash. I still can't figure out how to hide the ctfserver.exe window.
답변 (2개)
Claudio Alvarez
2023년 5월 3일
편집: Claudio Alvarez
2023년 5월 3일
This is what I did to remove the ctfserver.exe command window.
I am writing an application in Windows 10 using .NET 6 (the .exe) and MATLAB C++ Data API (the CTF is loaded in a native DLL) and a C++/CLI wrapper (another DLL) to connect the MATLAB DLL to .NET 6. Doing this allows me to work with the MATLAB arrays directly in C++ with zero copy, specially with complex number. Matlab uses std::complex<double>, so it is very convinient.
Now I was able to run matab using the IN_PROCESS flags. I disable every UI elements with the next options
std::vector<std::u16string> options = {u"-noFigureWindows", u"-nosplash", u"-nodesktop", u"-nodisplay"};
auto mode = MATLABApplicationMode::IN_PROCESS;
Since it worked, I stated to remove options until I found you only need the -nodisplay one
std::vector<std::u16string> options = {u"-nodisplay"};
auto mode = MATLABApplicationMode::IN_PROCESS;
So what I do is in debug mode I compile with the OUT_OF_PROCESS flag to avoid the lag when loading all the matlab DLL symbols (it can take forever). In release mode I switch to IN_PROCESS.
My guess is that some display or UI element are not compatible with the manage .NET 6 and it crash.
댓글 수: 0
Shaojun Xiao
2024년 6월 20일
편집: Shaojun Xiao
2024년 6월 20일
The following work around from AK of the MathWorks Support:
[DllImport("kernel32")]
static extern bool AllocConsole();
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_HIDE = 0;
const int SW_SHOW = 5;
//in the initialisation function
if (GetConsoleWindow() == IntPtr.Zero)
{
AllocConsole();
}
var consoleWindowHandle = GetConsoleWindow();
// Hide the console window
if (consoleWindowHandle != IntPtr.Zero)
ShowWindow(consoleWindowHandle, SW_HIDE);
...
var _matlabRuntime = MATLABRuntime.StartMATLAB(ctfPath);
...
// To show the console window again (if needed)
//ShowWindow(consoleWindowHandle, SW_SHOW);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 C Shared Library Integration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!