Valhalla Legends Forums Archive | C/C++ Programming | Returns ERROR_INVALID_HANDLE, why?

AuthorMessageTime
UserLoser
[code]
BOOL MainDialog::OnNotify(WPARAM wParam, LPARAM lParam)
{
NMHDR NotifyHeader;
TEXTRANGE Range;
ENLINK Link;
char *Url = NULL;

memcpy(&NotifyHeader, (const void*)lParam, sizeof(NotifyHeader));

if((NotifyHeader.hwndFrom == RichEditWindow) && (NotifyHeader.code == EN_LINK)) {
memcpy(&Link, (const void*)lParam, sizeof(Link));
if(Link.msg == WM_LBUTTONUP) {
Url = new char[Link.chrg.cpMax - Link.chrg.cpMin + 1];

Range.chrg = Link.chrg;
Range.lpstrText = Url;

if(SendMessage(RichEditWindow, EM_GETTEXTRANGE, 0, (LPARAM)&Range) != ERROR_SUCCESS) {
Timestamp(RichEditWindow);
InsertFormattedText(RichEditWindow, RED, "Error %u occured while reading Url!\n", GetLastError());
}
if(ShellExecute(RichEditWindow, NULL, Url, NULL, NULL, SW_SHOWNORMAL) != ERROR_SUCCESS) {
Timestamp(RichEditWindow);
InsertFormattedText(RichEditWindow, RED, "Error %u occured while opening Url!\n", GetLastError());
}

delete [] Url;
}
}

return FALSE;
}
[/code]

[s]Both SendMessage and ShellExecute return ERROR_INVALID_HANDLE.  I do not understand why.[/s]

Solution posted below
October 11, 2006, 7:24 PM
Myndfyr
Are you executing this on the correct thread?  You're only supposed to modify windows controls on the thread on which the handle was created.
October 11, 2006, 8:56 PM
UserLoser
[quote author=MyndFyre[vL] link=topic=15856.msg159685#msg159685 date=1160600167]
Are you executing this on the correct thread?  You're only supposed to modify windows controls on the thread on which the handle was created.
[/quote]

Yes..I am not creating any threads at all so I would assume so.  This works correctly, meaning your Internet browser does open with the correct page, I just want to know why those return 6.
October 11, 2006, 9:13 PM
UserLoser
Wow, nevermind.  I didn't read the return value part correctly on MSDN.  For EM_GETTEXTRANGE it returns number of characters, and ShellExecute returns an HINSTANCE > 32 upon success...durr.

Doing Error = SendMessage(...) I see this...there is no errors, thanks anyways
October 11, 2006, 9:18 PM

Search