Alexander
2008-07-01 13:52:01 UTC
I am trying to implement text/html MIME filter. The problem is what filtering
algorithm is complex and I don't want to do filtering directly in ReportData
function. So I implemented the algorithm described below(using C++):
func IInternetProtocolSink::report_data {
if must_be_filtered {
create_thread(filter_thread);
return s_ok;
} else return sink->report_data();
}
func filter_thread {
CoInitializeEx(0, COINIT_MULTITHREADED);
do prot->read() until all is read;
filter_read_data();
sink->report_data();
sink->report_result();
}
When reportData return S_OK, IE remains active, displaying "loading"
progress in status string. But "report_data" being called from filter thread
results in only one "read" call. IE does not wake up, freezing in "loading
forever" state.
I tried another scheme:
func filter_thread {
CoInitializeEx(0, COINIT_MULTITHREADED);
do prot->read() until all is read;
filter_read_data();
PROTOCOLDATA pd;
pd.grfFlags = PD_FORCE_SWITCH;
pd.dwState = 1234;
pd.pData = 0;
pd.cbData = 0;
HRESULT hr;
hr = sink->Switch(&pd);
}
func IInternetProtocol::continue {
if from filter thread {
sink->report_data();
sink->report_result();
}
}
But IInternetProtocolSink::Switch returns E_FAIL!
Where is my fault? What I am doing wrong? Direct solution without a thread
works fine, but IE UI freezes(don't respond to mouse events) until
ReportData returns and it is unacceptable for me.
thanks.
algorithm is complex and I don't want to do filtering directly in ReportData
function. So I implemented the algorithm described below(using C++):
func IInternetProtocolSink::report_data {
if must_be_filtered {
create_thread(filter_thread);
return s_ok;
} else return sink->report_data();
}
func filter_thread {
CoInitializeEx(0, COINIT_MULTITHREADED);
do prot->read() until all is read;
filter_read_data();
sink->report_data();
sink->report_result();
}
When reportData return S_OK, IE remains active, displaying "loading"
progress in status string. But "report_data" being called from filter thread
results in only one "read" call. IE does not wake up, freezing in "loading
forever" state.
I tried another scheme:
func filter_thread {
CoInitializeEx(0, COINIT_MULTITHREADED);
do prot->read() until all is read;
filter_read_data();
PROTOCOLDATA pd;
pd.grfFlags = PD_FORCE_SWITCH;
pd.dwState = 1234;
pd.pData = 0;
pd.cbData = 0;
HRESULT hr;
hr = sink->Switch(&pd);
}
func IInternetProtocol::continue {
if from filter thread {
sink->report_data();
sink->report_result();
}
}
But IInternetProtocolSink::Switch returns E_FAIL!
Where is my fault? What I am doing wrong? Direct solution without a thread
works fine, but IE UI freezes(don't respond to mouse events) until
ReportData returns and it is unacceptable for me.
thanks.