|
It's probably more that it's compiled with run-time checks on (/RTC1 flag) - the compiler can put in extra code when compiling to help find problems like overwriting bits of the stack or heap you shouldn't do. This requires stack/heap to be initialised to known values, which it does (it actually sets them to 0xcccccccc). These values are probably recognisable as invalid by DoModal (or IsWindow, or something), so it just rejects them. In Release, the HWND isn't initialised at all, so may contain a value that *could* be a valid HWND, causing the crash?
|
|
|
|
|
Hi All,
I want to use MSHTML as a parser from a Console Application.
hr = Location.CoCreateInstance(CLSID_HTMLLocation);
is returning 'COM Error: 0x80040154 (Win32: 340)'
Any ideas? The Document creation returns S_OK .
Jeff
#define _WIN32_IE 0x0550 // IHTMLDocument2
#define _WIN32_DCOM // CoInitializeEx(...)
#pragma warning( disable: 4146 )
#pragma warning( disable: 4192 )
# import "mshtml.tlb"
#pragma warning( default: 4146 )
#pragma warning( default: 4192 )
#include <windows.h>
#include <atlbase.h>
#include <mshtml.h>
#include <assert.h>
#include <iostream>
int main(int argc, char* argv[])
{
HRESULT hr = S_OK;
CComPtr< MSHTML::IHTMLDocument2 > Document = NULL;
CComPtr< MSHTML::IHTMLLocation > Location = NULL;
hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
if( FAILED( hr ) ) { goto COMPLETE; }
hr = Document.CoCreateInstance(CLSID_HTMLDocument);
if( FAILED( hr ) ) { goto COMPLETE; }
<BR>
hr = Location.CoCreateInstance(CLSID_HTMLLocation);
if( FAILED( hr ) ) { goto COMPLETE; }
COMPLETE:
Document.Release();
Location.Release();
CoUninitialize( );
if( S_OK != hr )
{
std::wcout << L"COM Error: " << std::hex << L"0x" <<hr;
std::wcout << L" (Win32: " << std::dec << HRESULT_CODE( hr );
std::wcout << L")" << std::endl;
}
return HRESULT_CODE( hr );
}
|
|
|
|
|
I suspect you don't need to CoCreateInstance a location object - the HTML document will pass back a pointer to it's own location object.
As to why the CoCreateInstance call is failing - I've no idea...
|
|
|
|
|
Hi Sohail,
Still fighting it... I'm working from Lightweight HTML Parsing Using MSHTML [^]. The new program is below, but same error occurs on IMarkupServices:
COM Error:
pDocument->QueryInterface( IMarkupServices )
0x80004002 (Win32: 16386)
I tried to unregister, and then register mshtml.dll. Unregister failed with 0x80004002 or 0x80004005. Registration succeeded.
I'm using Visual Studio 6.0, EE on Windows 2000. At this point, I rolled back the March 2006 SDK because of LINK 1103 error (corrupt library) to October 2002. I'm downloading February 2003 SDK now (last supported version for VC++ 6.0). I verified the IE SDK was installed.
I'm going to start to grep the Registry.
Jeff
#define _WIN32_IE 0x0500 // IMarkupServices
#define _WIN32_DCOM // CoInitializeEx(...)
#import "mshtml.tlb"
#include <windows.h>
#include <atlbase.h>
#include <mshtml.h>
#include <mshtmlc.h>
#include <assert.h>
#include <iostream>
int main(int argc, char* argv[])
{
HRESULT hr = S_OK;
CComBSTR error;
try
{
CComPtr< MSHTML::IHTMLDocument2 > pDocument = NULL;
CComPtr< IPersistStreamInit > pStream = NULL;
CComPtr< MSHTML::IMarkupServices > pServices = NULL;
CComPtr< MSHTML::IMarkupContainer > pContainer = NULL;
CComBSTR title = L"", charset=L"";
hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
if( FAILED( hr ) ) {
error = L"CoInitializeEx";
throw error;
}
hr = pDocument.CoCreateInstance( CLSID_HTMLDocument );
if( FAILED( hr ) ) {
error = L"pDocument";
throw error;
}
hr = pDocument->get_title( &title );
if( FAILED( hr ) )
{
error = L"pDocument->get_title";
throw error;
}
std::wcout << L"Title: ";
std::wcout << (wchar_t*)title << std::endl;
hr = pDocument->get_charset( &charset );
if( FAILED( hr ) )
{
error = L"pDocument->get_charset";
throw error;
}
std::wcout << L"Character Set: ";
std::wcout << (wchar_t*)charset << std::endl;
hr = pDocument->QueryInterface( IID_IPersistStreamInit,
reinterpret_cast<void**>( &pStream ) );
if( FAILED( hr ) ) {
error = L"pDocument.QueryInterface( IPersistStreamInit )";
throw error;
}
pStream->InitNew();
hr = pDocument->QueryInterface( IID_IMarkupServices,
reinterpret_cast<void**>( &pServices ) );
if( FAILED( hr ) ) {
error = L"pDocument->QueryInterface( IMarkupServices )";
throw error;
}
}
catch( CComBSTR& e )
{
std::wcout << std::endl;
std::wcout << L"COM Error: " << std::endl << L" ";
std::wcout << (wchar_t*)e << std::endl ;
std::wcout << std::hex << L" 0x" <<hr;
std::wcout << L" (Win32: " << std::dec << HRESULT_CODE( hr );
std::wcout << L")" << std::endl;
}
CoUninitialize( );
return HRESULT_CODE( hr );
}
|
|
|
|
|
No registry entries for:
'IMarkupServices' or '3050f4a0-98b5-11cf-bb82-00aa00bdce0b' (string literal searches, not case sensitive)
I'll try the October 2003 SDK when I finish getting it down.
Jeff
|
|
|
|
|
Hi Stuart,
I haven't tried the IHTMLLocation Interface yet, but the IMarkupServices was resolved by replacing the call to CoInitializeEx() with CoInitialize().
Jeff
|
|
|
|
|
hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
|
|
|
|
|
HRESULT 0x80040154 corresponds to Class Not Registered
I don't know anything about CLSID_HTMLLocation so I think the error could be either because of missing class registration information or the class is noncreatable directly. In case of noncreatable class, you will have to invoke a method or proerty of some other object which returns you the intance of this class.
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Hi Sohail,
Still fighting it... I'm working from Lightweight HTML Parsing Using MSHTML [^]. The new program is below, but same error occurs on IMarkupServices:
COM Error:
pDocument->QueryInterface( IMarkupServices )
0x80004002 (Win32: 16386)
I tried to unregister, and then register mshtml.dll. Unregister failed with 0x80004002 or 0x80004005. Registration succeeded.
I'm using Visual Studio 6.0, EE on Windows 2000. At this point, I rolled back the March 2006 SDK because of LINK 1103 error (corrupt library) to October 2002. I'm downloading February 2003 SDK now (last supported version for VC++ 6.0). I verified the IE SDK was installed.
I'm going to start to grep the Registry.
Jeff
#define _WIN32_IE 0x0500 // IMarkupServices
#define _WIN32_DCOM // CoInitializeEx(...)
#import "mshtml.tlb"
#include <windows.h>
#include <atlbase.h>
#include <mshtml.h>
#include <mshtmlc.h>
#include <assert.h>
#include <iostream>
int main(int argc, char* argv[])
{
HRESULT hr = S_OK;
CComBSTR error;
try
{
CComPtr< MSHTML::IHTMLDocument2 > pDocument = NULL;
CComPtr< IPersistStreamInit > pStream = NULL;
CComPtr< MSHTML::IMarkupServices > pServices = NULL;
CComPtr< MSHTML::IMarkupContainer > pContainer = NULL;
CComBSTR title = L"", charset=L"";
hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
if( FAILED( hr ) ) {
error = L"CoInitializeEx";
throw error;
}
hr = pDocument.CoCreateInstance( CLSID_HTMLDocument );
if( FAILED( hr ) ) {
error = L"pDocument";
throw error;
}
hr = pDocument->get_title( &title );
if( FAILED( hr ) )
{
error = L"pDocument->get_title";
throw error;
}
std::wcout << L"Title: ";
std::wcout << (wchar_t*)title << std::endl;
hr = pDocument->get_charset( &charset );
if( FAILED( hr ) )
{
error = L"pDocument->get_charset";
throw error;
}
std::wcout << L"Character Set: ";
std::wcout << (wchar_t*)charset << std::endl;
hr = pDocument->QueryInterface( IID_IPersistStreamInit,
reinterpret_cast<void**>( &pStream ) );
if( FAILED( hr ) ) {
error = L"pDocument.QueryInterface( IPersistStreamInit )";
throw error;
}
pStream->InitNew();
hr = pDocument->QueryInterface( IID_IMarkupServices,
reinterpret_cast<void**>( &pServices ) );
if( FAILED( hr ) ) {
error = L"pDocument->QueryInterface( IMarkupServices )";
throw error;
}
}
catch( CComBSTR& e )
{
std::wcout << std::endl;
std::wcout << L"COM Error: " << std::endl << L" ";
std::wcout << (wchar_t*)e << std::endl ;
std::wcout << std::hex << L" 0x" <<hr;
std::wcout << L" (Win32: " << std::dec << HRESULT_CODE( hr );
std::wcout << L")" << std::endl;
}
CoUninitialize( );
return HRESULT_CODE( hr );
}
|
|
|
|
|
|
From MSDN (The following in BOLD is what i told in my earlier post, there is certain way you should follow to get access to some interfaces. The following is an example) -
IMarkupServices
Having understood the fundamental concepts of Markup Services, you now are ready to take a closer look at Markup Services interfaces. The best place to start is the IMarkupServices interface. This interface is the starting point for all the MarkupServices, such as IMarkupContainer and IMarkupPointer. The IMarkupServices interface also contains all the methods for performing actual manipulations of elements of the document.
You can perform a QueryInterface operation on a document object for IID_IMarkupServices to obtain IMarkupServices.
On MSDN, read in Overview and Tutorial about IMarkupServices
I hope this helps.
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Thanks Sohail,
I _think_ Windows 2000 (with VC++ 6.0) is missing the Registry entries. I have tried the following SDK:
- March 2006 (Lirary Corrupt - Rollback per Fix)
- 1998 or 1999 (VC++ 6.0/MSDN CD)
- October 2002
- February 2003
I am fresh, so I am going to pursue it now.
Jeff
|
|
|
|
|
Hi Sohail,
Thanks. The problem was resolved with the following:
hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
Sohail Kadiwala wrote: On MSDN, read in Overview and Tutorial about IMarkupServices
Been there, done that. I still don't have a 'big picture' due to the following:
- Micosoft's inability to implement a descent Search Engine
- Microsoft's MSDN is 'fractured' - it does not present a big picture
Jeff
|
|
|
|
|
Cool. But if I am not wrong, Coinitialize(NULL) internally calls CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
So If it would have been COINIT_MULTITHREADED, I would think that this solved your problem. Just for curiosity, did you do any other changes?
Yes, Agreed, MSDN search engine is not very good. I always do a Google search with "MSDN" keyword added extra to my search keywords
For many things, MSDN doesn't have enough information. At times, I have experienced that the API or interface or method descriptions and details are not enough
Finally, I am glad that your problem is solved. But I am now interested to read more on the interfaces you are using. I may read about it in MSDN in my spare time.
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Hi Sohail,
Sohail Kadiwala wrote: Coinitialize(NULL) internally calls CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
Correct. However, F11 did not step into the code, so I was being lazy and did not go out on the web and research it... I found it interesting COINIT_MULTITHREADED did not fail immediately (for example, at the first attempt to grab a MSHTML interface).
Sohail Kadiwala wrote: But I am now interested to read more on the interfaces you are using.
I have 3 Samples together now. They are part or a larger project. However, I plan to write an article on HTML Parsing from a Console Application (a few are out there already, but the articles are bare bones and very little is explained).
If you'd like, you can have the source code now. I'd need an email address. Thanks for the comments - lot's of 5's added People who respond should be rewarded.
Jeff
|
|
|
|
|
Thanks for the 5's. People here long for 5's
Well, I would like to have the source code and go through it. But if you are in midst of writing an article, then I would wait. Just notify me when you publish your article.
For any further contacts, my email id is - sohail.kadiwala@gmail.com
Take care.
Happy Holidays
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
No registry entries for:
'IMarkupServices' or '3050f4a0-98b5-11cf-bb82-00aa00bdce0b' (string literal searches, not case sensitive)
I'll try the October 2003 SDK when I finish getting it down.
Jeff
|
|
|
|
|
Hi Sohail,
I haven't tried the IHTMLLocation Interface yet, but the IMarkupServices was resolved by replacing the call to CoInitializeEx() with CoInitialize().
Jeff
|
|
|
|
|
I haven't tried the IHTMLLocation Interface yet, but the IMarkupServices was resolved by replacing the call to CoInitializeEx() with CoInitialize().
Jeff
|
|
|
|
|
hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
|
|
|
|
|
I have an Automation server created in MFC. I have some classes which are creatable by TypeId. Now in one of this class, I want to provide a way to fire events. This is and EXE server and not ActiveX control. I know how to add events in an ActiveX control. Can someone guide me on providing Automation/COM events from a class in MFC.
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Hi All,
This should be the last question on Context Menus...
IContextMenu2 handles the WM_DRAWITEM, which I am trying to use to place an icon (16x116 or 3x13 bitmap) on the Menu. I can't seem to get it to work (fully patched Windows 2000, VC++ 6.0 EE).
Any ideas?
Jeff
|
|
|
|
|
Hi All,
I've used Michael Dunn's article[^] to create two Context Menu handlers. They are housed in separate DLLs. They are basically carbon copies of one another (and the sample which Michael provides) except names. Each uses the same insertion code:
InsertMenu( hmenu, uMenuIndex, MF_BYPOSITION, uidFirstCmd, _T("Menu Item Name") );
However, the items are not placed one after the other ('stacked') as I would expect. As a matter of fact, Windows (at times) places a separator bar between them:
Open with WinZip
Print
----------------
Menu Item 1
----------------
Scan for Viruses
Open With...
Menu Item 2
Winzip
----------------
...
Any ideas to get these fellows to stick together?
Jeff
----------------
|
|
|
|
|
You have no control over what other extensions will do with the menu, nor in what order Explorer will call them. You might be able to influence the order by making your two extensions' ContextMenuHandlers keys have similar names (FooExtension1 and FooExtension2 , for example) but no guarantees.
|
|
|
|
|
Hi Mike,
> nor in what order Explorer will call them
That is more or less my (ignorant) feeling.
> influence the order by making your two extensions'
> ContextMenuHandlers keys have similar names
I tried adding an space (' ') to the names - they get indented on the menu, but not grouped together.
Jeff
|
|
|
|