Witam,
Chciałbym pobrać tekst z okna chata. Po przekopaniu netu znalazłem coś takiego w c++
BSTR pDealerText = NULL ;
if (!lstrcmp(classname, TEXT("Internet Explorer_Server")))
{
CoInitialize (NULL);
HINSTANCE hInst = ::LoadLibrary (_T("OLEACC.DLL"));
CComPtr<IHTMLDocument2> spDoc;
LRESULT lRes;
LPFNOBJECTFROMLRESULT pfObjectFromLresult = NULL;
::SendMessageTimeout (hwnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes);
pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, "ObjectFromLresult" );
if (pfObjectFromLresult != NULL)
{
HRESULT hr;
hr = (*pfObjectFromLresult)( lRes, IID_IHTMLDocument2, 0, (void**)&spDoc );
if (SUCCEEDED(hr))
{
CComPtr<IHTMLElement> pHTMLElement;
hr=spDoc->get_body(&pHTMLElement);
pHTMLElement->get_innerText(&chatText);
OutputDebugString(pchatText);
}
Działa bardzo dobrze, wiec żeby utrudnić sobie życie postanowiłem zrobić to samo w c#
[DllImport("user32.dll", EntryPoint = "RegisterWindowMessageA")]
public static extern int RegisterWindowMessage(string lpString);
[DllImport("user32.dll", EntryPoint = "SendMessageTimeoutA")]
public static extern int SendMessageTimeout(IntPtr hwnd, int msg, int wParam, int lParam, int fuFlags, int uTimeout, out int lpdwResult);
public const int SMTO_ABORTIFHUNG = 0x2;
public static Guid IID_IHTMLDocument2 = typeof(IHTMLDocument2).GUID;
[DllImport("OLEACC.dll")]
public static extern int ObjectFromLresult(int lResult, ref Guid riid, int wParam, ref IHTMLDocument2 ppvObject);
Fragment funkcji :
lngMsg = Win32.RegisterWindowMessage("WM_HTML_GETOBJECT");
if (lngMsg != 0)
{
Win32.SendMessageTimeout(hWnd, lngMsg, 0, 0, Win32.SMTO_ABORTIFHUNG, 1000, out lRes);
if (!(bool)(lRes == 0))
{
int hr = Win32.ObjectFromLresult(lRes, ref Win32.IID_IHTMLDocument2, 0, ref document);
if ((bool)(document == null))
{
MessageBox.Show("No IHTMLDocument Found!", "Warning");
}
}
}
return document;
Funkcja zwraca ten dokument ,ale już document.body.innerText dla chata jest pusty.W przypadku okna IE wszystko działa prawidłowo.Nie mam pojęcia dlaczego tak jest.Jakieś sugestie ?