• Welcome to Valhalla Legends Archive.
 

Returns ERROR_INVALID_HANDLE, why?

Started by UserLoser, October 11, 2006, 02:24 PM

Previous topic - Next topic

UserLoser


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


Both SendMessage and ShellExecute return ERROR_INVALID_HANDLE.  I do not understand why.

Solution posted below

MyndFyre

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

UserLoser

Quote from: MyndFyre[vL] on October 11, 2006, 03:56 PM
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.

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.

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