News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

ITextSelection

Started by jj2007, January 04, 2024, 09:04:00 AM

Previous topic - Next topic

jj2007

RichEdit control using msftedit.dll on Windows 10:
lea edi, ReTom.mbtUnk ; ptr iunknown
invoke SendMessage, hRichEd, EM_GETOLEINTERFACE, 0, edi ; get IRichEditOle object
CoInvoke pInterface, IUnknown.QueryInterface, addr IID_ITextSelection, addr ReTom.mbtSelect ; get ITextSelection pointer

I always get 80004002h alias E_NOINTERFACE :sad:

Has anybody succeeded to get this interface?

sinsi

Not much from Microsoft about it, this is all I could find that was vaguely useful

Applications typically do not implement the ITextSelection interface. Instead, Microsoft text solutions such as rich edit controls implement ITextSelection as part of their Text Object Model (TOM) implementation.
Applications can retrieve an ITextSelection pointer by calling the ITextDocument.GetSelection method.


http://www.jose.it-berater.org/richedit/text_object_model_interfaces_overview.htm
🍺🍺🍺

HSE

Quote from: jj2007 on January 04, 2024, 09:04:00 AMI always get 80004002h alias E_NOINTERFACE :sad:

Have you same result in 64 bits?
Equations in Assembly: SmplMath

jj2007

Quote from: sinsi on January 04, 2024, 10:12:06 AMApplications can retrieve an ITextSelection pointer by calling the ITextDocument.GetSelection method

That's a very unorthodox method of getting a COM interface, but apparently it works. Sinsi, you are a genius, thanks :thumbsup:  :thumbsup:  :thumbsup:

@HSE: I didn't test it in 64-bit code.

sinsi

That's nothing, try working your way through the Shell interfaces  :dazzled:
🍺🍺🍺

TimoVJL

About Text Object Model

Just check headers:
#ifndef __ITextDocument_INTERFACE_DEFINED__
#define __ITextDocument_INTERFACE_DEFINED__
DEFINE_GUID(IID_ITextDocument,0x8CC497C0,0xA1DF,0x11CE,0x80,0x98,0x00,0xAA,0x00,0x47,0xBE,0x5D);
typedef struct ITextDocumentVtbl {
    /* IUnknown methods */
    HRESULT (STDMETHODCALLTYPE *QueryInterface)(ITextDocument *This,REFIID,void**);
    ULONG (STDMETHODCALLTYPE *AddRef)(ITextDocument *This);
    ULONG (STDMETHODCALLTYPE *Release)(ITextDocument *This);
    /* IDispatch methods */
    HRESULT (STDMETHODCALLTYPE *GetTypeInfoCount)(ITextDocument *This,UINT*);
    HRESULT (STDMETHODCALLTYPE *GetTypeInfo)(ITextDocument *This,UINT,ULONG,void**);
    HRESULT (STDMETHODCALLTYPE *GetIDsOfNames)(ITextDocument *This,GUID*,CHAR**,UINT,ULONG,LONG*);
    HRESULT (STDMETHODCALLTYPE *Invoke)(ITextDocument *This,LONG,GUID*,ULONG,USHORT,struct DISPPARAMS*,VARIANT*,struct EXCEPINFO*,UINT*);
    /* ITextDocument methods */
    HRESULT (STDMETHODCALLTYPE *get_Name)(ITextDocument *This,BSTR*);
    HRESULT (STDMETHODCALLTYPE *get_Selection)(ITextDocument *This,ITextSelection**);
May the source be with you

jj2007

Quote from: TimoVJL on January 04, 2024, 11:57:05 AMJust check headers:

Thanks, Timo. Since I program almost exclusively in Assembler, I get these interfaces using my COM interface plugin - attached an include file built with the plugin.

Btw Sinsi's solution works fine. With ITextSelection::SetFlags, I can now reset richedit controls to insert mode (there is a nasty bug: after several minutes, a richedit control may switch to overwrite mode, and never come back...).

TimoVJL

Type library is also good place for getting COM interfaces.
VB use them.
A msftedit.dll have it in it's resource.

A translator of typelib
May the source be with you