addsourcefilter locking file in windows

Tech-Archive recommends: Speed Up your PC by fixing your registry



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; } }

.



Relevant Pages

  • Re: .Net packaging/wrapper application?
    ... the simple answer to DLL Hell for Visual Basic apps was simply to place a copy of the needed DLLs in the same directory as your executable. ... The way Windows works is to look in the executable's directory for a needed DLL BEFORE using the registry to find one EVEN IF THE REFERENCED DLL IS REGISTERED ON THE PC RUNNING THE APPLICATION THAT NEED IT. ... Perhaps I'm getting old and but what really bothers me is nobody seems to notice this--maybe the 80s was before they got into programming. ... Looks to me like Jim is looking for the .NET equivalent of compiling with static libraries to produce a single executable. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Redirecting stderr
    ... programming newsgroup. ... There's no DLL support in the Unix version I use, ... If the code uses DLLs on Windows and shared libraries ...
    (comp.lang.c)
  • Re: Base Classes in .exe, derived classes in .dll
    ... >> on Windows you cannot export symbols from an executable. ... E.g. how can I link an DLL importing some symbols by specifying an EXE ... Maybe via email to avoid offending some people here (which do programming ... without an underlying OS)... ...
    (comp.lang.cpp)
  • Re: [SLE] Developing a Real Time Data System
    ... The KBasic License is valid for both operating systems: Windows and Linux. ... Modern BASIC language ... chapters learning about the programming language. ...
    (SuSE)
  • Re: Reverse engineering != piracy (was Re: RosAsm disassembler output vs. IDA Pro)
    ... OOPL or fancy "class" keywords to be programming "OOP"...that stuff is ... Rene...one of your RosAsm newbies has just ... under the BASIC language, typing "?" ... surface that works within Windows...but then all "child" windows can ...
    (alt.lang.asm)