I'm new to this group and somewhat new to directshow programming. I've
been searching for a solution to this problem but I haven't found
anything - I think this problem just comes from my lack of experience
with windows programming.
Here's the deal:
I wrote a C++ MFC dll that I am calling from a VB6 application. The
point of the dll is to display a targa or bitmap still file (.tga or
..bmp) on a video output card. The VB program invokes a method in the
Dll that starts direct show, and builds a graph. Then another method
is invoked to that basically calls addsourcefilter where the source
file is the .tga or .bmp file that I am displaying and then does
"connectdirect" and runs the graph. This all works. The file is shown
on the video output successfully. Here is the problem. Once
addsourcefilter grabs hold of the .tga or .bmp file it never lets go
until I quit the VB app and the dll. If I stop AND kill the graph,
windows still sees the file as in use (I can test this by trying to
change the filename in windows - I get an error message saying the file
is in use.
(this is especially difficult in while debugging in VB6 because I have
to quit the IDE in order for windows to not see the file as in use any
more). Since the point of my application is to read an updated file
with the same name - this is causing me all sorts of problems because
the app (photoshop) that is writing the file can't overwrite it while
it is in this "in use" condition. Anyone have any thoughts? Again as I
said I think this is just due to my inexperience with this. My code
(from the dll)is bellow: (thianks in advance for your help!)
//This the method that does the displaying
bool _stdcall displaynamedstillfile(BSTR bstrfilepath)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
HRESULT hr;
// BSTR bstrfilepath = filename.AllocSysString();
if (getgraphmode() == 0){
return false;
}
if (sInputFileFilter != NULL)
{
if (disconnectgraph() == false){
return false;
}
}
//add file to the graph
//this is where the file becomes locked
// in windows as you might expect
hr = sGraph->AddSourceFilter(bstrfilepath, bstrfilepath,
&sInputFileFilter);
if(FAILED(hr))
{
return false;
}
sFileOut = FindPin(sInputFileFilter, PINDIR_OUTPUT, NULL);
if(sFileOut == NULL || sDecklinkIn == NULL)
{
SAFE_RELEASE(sFileOut);
return false;
}
//hr = sGraph->Connect(sFileOut, sDecklinkIn);
hr = sGraph->ConnectDirect(sFileOut, sDecklinkIn, NULL);
if(FAILED(hr))
{
SAFE_RELEASE(sFileOut);
return false;
}
hr = sControl->Run();
if(FAILED(hr))
{
SAFE_RELEASE(sFileOut);
return false;
}
Sleep(3);
hr = sControl->Stop();
return true;
}
//the following method does release the
//video output card but the file is still locked
// disconnect the file from the graph
bool _stdcall disconnectgraph(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
HRESULT hr;
if (getgraphmode() == 0){
return false;
}
if (sInputFileFilter != NULL)
{
hr = sGraph->Disconnect(sDecklinkIn);
if(FAILED(hr))
{
return false;
}
hr = sGraph->RemoveFilter(sInputFileFilter);
if(FAILED(hr))
{
return false;
}
SAFE_RELEASE(sInputFileFilter);
}
fileIsConnected = false;
return true;
}
// kill the whole graph
bool _stdcall releasegraph(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
SAFE_RELEASE(sGraph);
SAFE_RELEASE(sControl);
SAFE_RELEASE(sEvent);
SAFE_RELEASE(sMS);
SAFE_RELEASE(sMP);
SAFE_RELEASE(sKeyer);
SAFE_RELEASE(sBV);
SAFE_RELEASE(sBA);
SAFE_RELEASE(sDeckVidRender);
SAFE_RELEASE(sInputFileFilter);
SAFE_RELEASE(sFileOut);
SAFE_RELEASE(sDecklinkIn);
currentKeyerMode = 0;
fileIsConnected = false;
graphIsBuilt = false;
return true;
}
//safe release is
// #define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
|