Re: Stay resident dll
"JRGlide" <JRGlide@discussions.microsoft.com> wrote in message
news:75C5F17D-92D6-465A-97DE-50B741907E58@microsoft.com...
I currently have a MATLAB mex function that allows the user to view &
manipulate 3D point cloud data directly from MATLAB. A mex function is
nothing more than a standard dll with a specific MATLAB entry point. The
viewer was written in MFC using OpenGL.
My problem is that since it is a dll the user must close the viewer before
returning to MATLAB. In other words, the user calls the viewer from
MATLAB,
looks at the data, closes the viewer and then returns to MATLAB.
I would like to find a way to keep the viewer up permanently so that it
works independently from MATLAB so they can both be run at once. What I
envision is that MATLAB would call another mex function (or dll) with the
data for display. This function would check to see if the viewer is
active
and activate it if necessary. It would then pass the data to the viewer
using some sort of handshake and then return to MATLAB without the viewer
disappearing at it does now. If the user changed the data it would make
the
same call and the dll would update the data in the viewer.
My question is that I???m not sure how to go about doing this:
1. I suspect that to do this, the viewer would need to be a regular
executable with some sort of interface and not a dll, but maybe I assume
wrong.
The viewer would need to be a exe program if it is expected to continue
running after Matlab closes, or after Matlab unloads the mex.
2. It would first have to know if the viewer is loaded or not and the
load
it.
Named mutex and named events can be used for interprocess state indications.
The exe uses CreateMutex, the mex uses WaitForSingleObject (with a 0
timeout) to determine if the mutex currently exists.
3. I???m not sure what the handshake would be between the mex function and
the viewer. The data could potentially be hundreds of megs in size. Is
there a way I can do that through shared memory or some sort of global
memory
pool? I???m trying to keep from writing the data to disk and read it back
again. Having said that, if I have to limit the data size to say, less
than
50 meg, I can live with that.
Shared memory (even to 100s of MB) is practical. See CreateFileMapping and
MapViewOfFile. The mex would have to copy the data into the shared region,
then notify the exe there is a new data set. The notify could take many
forms, including SetEvent/WaitForSingleObject, or PostMessage to an HWND
that the exe places into the shared memory.
4. As far as closing the viewer, I guess that would be up to the user
after
they are finished, just like any other application.
Thank you for your help.
--
Scott McPhillips [VC++ MVP]