getting text from an open Ed window

Brad Garton's icon

Hey dev-folk --

I'd like to be able to access text from an open Ed window without having
to close the editor window. I tried this (the "goeditor" message would
trigger):

void rtcmix_goeditor(t_rtcmix *x)
{
    CharsHandle chand;
    TEHandle thand;
    t_ed *edit_window;

    edit_window = x->c_edit;    // from ed_new()
    thand = (*edit_window).e_teh;
    chand = TEGetText(thand);
    post("here da text: %s", (char *)chand);
}

but it crashes on the TEGetText() call. Looking at the t_ed struct, it
seems as if e_teh should be a valid TEHandle.

Also, how can I accomplish this on Windows (if in fact it is
accomplishable...)?