Jump to content

Anyone good with COM? Please :)


ken82m
 Share

Recommended Posts

I have been trying to find something to capture the text from a console window. Problem is I have to capture teh text as the app is running. The STDOUT read thing and every other trick has failed.

I found an app called TextCatch that is capable of captruing what I want. It supports COM but I know nothing about it. Below is a very short COM example in VB (they have C++ too if you need it) from the help file. I'm hoping somebody can translate to AutoIT for me :P

I normally don't post here and ask people to actually write code for me but I don't know were to start, hey I'll owe you a beer lol :D

Step-by-Step Example

1. Start a new project in Visual Basic. Form1 is created by default.

2. Add two TextBox, one Label, one CommandButton .

3. Copy the following code into the Form's module:

' Declare TextCatch COM object

Dim TcServer As Object

Private Sub Form_Load()

Set TcServer = CreateObject("TextCatch.TcServer")

End Sub

Private Sub Form_Unload(Cancel As Integer)

Set TcServer = Nothing

End Sub

Private Sub GetTextBtn_Click()

Dim str As String

TcServer.GetFromHandle Val(HwndText.Text), CS_AUTO, str

OutputText.Text = str

End Sub

4. Press "F5" to run the application, input the window handle to be captured, then click "Capture it!" button.

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

SUMMARY

The following section illustrates how you can create an MFC project and import TextCatch as a COM server and capture text from mouse pointed window(ie. Explore of "My Computer").

Step-by-Step Example

1.

With Microsoft Developer Studio, start a new "MFC AppWizard (exe)" project named "TcServerSampleApp."

2.

In step 1 of the MFC AppWizard, choose "Dialog Based" for the application type and then click Finish.

The New Project Information dialog box appears and indicates that the Classes to be created include:

Application: CTcServerSampleApp in TcServerSample.h and TcServerSample.cpp Dialog: CTcServerSampleDlg in TcServerSampleDlg.h and TcServerSampleDlg.cpp

Click OK to create the project.

3. The Dialog box "IDD_TCSERVERSAMPLE_DIALOG" opens in the Visual Studio design/edit area. Modify it according to the instructions in the next two steps.

4. Remove the Label control (IDC_STATIC) and the Cancel button (IDCANCEL).

5. Change the name of the OK button to "IDC_GETTEXT_BUTTON" and the caption to "Capture It!." Close the dialog box design form.

6. Click ClassWizard on the View menu (or press CTRL+W).

7. Select the Message Maps tab. Select IDC_GETTEXT_BUTTONin the Object Ids list box and select "BN_CLICKED" in the Messages list box. Click Add Function and accept the function name "OnGetTextButton". Click OK to close the ClassWizard.

NOTE: This step adds a declaration for the function member "OnGetTextButton();" to the header file named TcServerSampleDlg.h. This step also adds an empty skeleton message handler function named CTcServerSampleDlg ::OnGetTextButton() to the file named TcServerSampleDlg.cpp.

8. Add the following code at the head of TcServerSampleDlg

//////////////////////////////////////////////////////////////////////////

// Import TextCatch COM defination

//

#import "..\Lib\TextCatch.tlb"

//

//////////////////////////////////////////////////////////////////////////

9. Add a public member variable to the class CTcServerSampleDlg, varialble type is TextCatchLib::ITcServerPtr, vairalble name is m_pTextCatchServer:

public:

TextCatchLib::ITcServerPtr m_pTextCatchServer; // Declare the TextCatch ITcServer object

10. Add the following code to the CTcServerSampleDlg::OnInitDialog() so that it appears as shown below:

11. // NOTE: Make sure to initialize COM before trying to create the capture object.

::CoInitialize( NULL );

// Create the TextCatch COM object.

m_pTextCatchServer.CreateInstance( __uuidof( TextCatchLib::TcServer));

if (m_pTextCatchServer == NULL )

{

// Handle creation error.

AfxMessageBox( _T("Fatal error: failed to create TextCatch COM object."), MB_IConerror );

EndDialog( IDCANCEL );

}

return TRUE; // return TRUE unless you set the focus to a control

12. Add the following code to the CTcServerSampleDlg::OnGetTextButton() so that it appears as shown below:

void CTcServerSampleDlg::OnGetTextButton()

{

if (IDOK ==AfxMessageBox("Three seconds after you close this dialog, "\

"the mouse pointed window will be captured.", MB_OKCANCEL))

{

ShowWindow(SW_HIDE);

Sleep(3000);

CPoint p;

GetCursorPos(&p);

HWND hWnd = ::WindowFromPoint(p);

if (hWnd)

{

BSTR bstrResult = NULL;

CString strResult;

try

{

m_pTextCatchServer->GetFromHandle((long)hWnd, TextCatchLib::ctAuto, &bstrResult );

USES_CONVERSION;

strResult = OLE2A(bstrResult);

::SysFreeString(bstrResult);

bstrResult = NULL;

GetDlgItem(IDC_RESULT_EDIT)->SetWindowText(strResult);

}

catch ( _com_error captureError )

{

AfxMessageBox( _T("Unable to capture."), MB_ICONINFORMATION );

}

}

ShowWindow(SW_SHOW);

}

}

13. Add windows message handler WM_CLOSE to the class CTcServerSampleDlg, select "WM_CLOSE" in the Messages list box. Click Add Function and accept the function name "OnClose". Click OK to close the ClassWizard.

Add the following code to the CTcServerSampleDlg::OnClose() so that it appears as shown below:

void CTcServerSampleDlg::OnClose()

{

// Closes the TextCatch COM library on the current apartment

if (m_pTextCatchServer != NULL)

m_pTextCatchServer.Release();

::CoUninitialize();

CDialog::OnClose();

}

14. Build and run the project. RESULTS: When you click the "Capture It!" button in the dialog box, a message window will popup. If you clicked "OK", 3 seconds after close this message box, the mouse pointed windows will be captured by TextCatch and the result will be displayed.

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

wow, that's even more confusing :P

I just don't understand the

TcServer.GetFromHandle Val(HwndText.Text), CS_AUTO, str

I don't know what to do with CS_AUTO.

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

yeah that's why I didn't post that one figured it would scare people lol :P

Do you know of any simple tools that would grab the text currently being displayed on a console window?

maybe this will help, then again maybe not lol

_____________________________________________________

Register/UnRegister TextCatch COM server

To register TextCatch COM server, you can run TextCatch.EXE with the /Register command-line Option. If you run TextCatch setup program, it will be registered as COM server automatically.

To unregistered an out-of-process server, Run TextCatch.EXE with the /Unregister command-line option. If you run TextCatch uninstall program, it will be unregistered from registry automatically.

--------------------------------------------------------------------------------

GetFromHandle Method

Syntax:

Visual Basic: GetFromHandle(

hWnd As Long,

iStyle As Long,

sResult As String ) As Long

C++: HRESULT STDMETHODCALLTYPE GetFromHandle(

/* [in] */ LONG hWnd,

/* [in] */ LONG iStyle,

/* [out] */ BSTR *sResult)

Parameter:

hWnd: Window's handle to capture.

nInputTypeEnum: Window's class type define enum value.

sResult: The returned captured text.

Return value: If this method succeeds, return value is zero. If it fails, return value is non-zero.

GetFromPoint Method

Syntax:

Visual Basic: GetFromPoint(

x As Long,

y As Long,

nInputTypeEnum As InputTypeEnum,

Result As String ) As Long

C++: HRESULT STDMETHODCALLTYPE GetFromPoint(

/* [in] */ LONG x,

/* [in] */ LONG y,

/* [in] */ InputTypeEnum nInputTypeEnum,

/* [out] */ BSTR *sResult)

Parameter:

x: x-coordinate of the point, in screen coordinates.

y: y-coordinate of the point, in screen coordinates.

nInputTypeEnum: Window's class type define enum value.

sResult: The returned captured text.

Return value: If this method succeeds, return value is zero. If it fails, return value is non-zero.

GetFromHandleWithScan Method

Syntax:

Visual Basic: GetFromHandleWithScan (

hWnd As Long,

bCoordinatesFlag As Boolean,

sResult As String ) As Long

C++: HRESULT STDMETHODCALLTYPE GetFromHandleWithScan(

/* [in] */ LONG hWnd,

/* [in] */ VARIANT_BOOL bCoordinatesFlag,

/* [out] */ BSTR *sResult)

Parameter:

hWnd: Window's handle to capture.

bCoordinatesFlag: Specifies the return result formats.

sResult: The returned captured text. If bCoordinatesFlag is set True, with format like "#line","Result","x:y"; others return only result.

Return value: If this method succeeds, return value is zero. If it fails, return value is non-zero.

GetFromPointWithScan Method

Syntax:

Visual Basic: GetFromPointWithScan (

x As Long,

y As Long,

bCoordinatesFlag As Boolean,

Result As String ) As Long

C++: HRESULT STDMETHODCALLTYPE GetFromPointWithScan (

/* [in] */ LONG x,

/* [in] */ LONG y,

/* [in] */ VARIANT_BOOL bCoordinatesFlag,

/* [out] */ BSTR *sResult)

Parameter:

x: x-coordinate of the point, in screen coordinates.

y: y-coordinate of the point, in screen coordinates.

bCoordinatesFlag: Specifies the return result formats.

sResult: The returned captured text. If bCoordinatesFlag is set True, with format like "#line","Result","x:y"; others return only result.

Return value: If this method succeeds, return value is zero. If it fails, return value is non-zero.

SetRegistrationInfo Method

Syntax:

Visual Basic: SetRegistrationInfo(

UserName As String,

LicenseCode As String) As Long

C++: HRESULT STDMETHODCALLTYPE SetRegistrationInfo(

/* [in] */ _bstr_t UserName ,

/* [in] */ _bstr_t LicenseCode)

Parameter:

UserName: the username of registration.

LicenseCode: the license registration code.

Return value: If this method succeeds, return value is zero. If it fails, return value is non-zero.

AboutBox Method

Syntax:

Visual Basic: AboutBox() As Long

C++: HRESULT STDMETHODCALLTYPE AboutBox()

Parameter:

None

Return value: return value is always zero.

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

do you think I could see the source of ..\Lib\TextCatch.tlb if you can find it? maybe search your computer for TextCatch.tlb? that should give me the value of the enum.

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

I took a wild guess and ran this:

$1 = ObjGet("C:\Program Files\skesoft\Text Catch\TextCatch.tlb", "Enum")

$2 = ObjGet("C:\Program Files\skesoft\Text Catch\TextCatch.tlb", "InputTypeEnum")

$3 = ObjGet("C:\Program Files\skesoft\Text Catch\TextCatch.tlb", "nInputTypeEnum")

FileWriteLine("C:\Enum.txt", "Enum=" & $1)

FileWriteLine("C:\Enum.txt", "InputTypeEnum=" & $2)

FileWriteLine("C:\Enum.txt", "nInputTypeEnum=" & $3)

And got this craziness lol:

Enum=@OÆ

InputTypeEnum=À_Æ

nInputTypeEnum=À_Æ

That looks pretty worthless so I attached the file too

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

ctAuto=`Où

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

I wasn't sure which you meant to send me.

When I ran this:

$object = ObjGet ("C:\Program Files\skesoft\Text Catch\TextCatch.tlb")

filewriteline ("C:\enum.txt", "ctAuto="& $object)

I got: ctAuto=`Où

with this:

$object = ObjGet ("C:\Program Files\skesoft\Text Catch\TextCatch.tlb", "ctAuto")

filewriteline ("C:\enum.txt", "ctAuto="& $object)

I got: ctAuto=Hø>

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

thanks for trying man. :P

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

A quick search turned up a VBA example here which would make a much better starting point for AutoIt.

I think you might be better served by focusing here on what you are trying to accomplish rather than this COM project however. I'm betting there are other options available that won't stretch your knowledge so much and won't require you to plunk down $30 for textCatch to do it...

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

I'll keep looking I guess. Spent over an hour looking on google already. Not sure why capturing a console window is so hard. Or more likely nobody cares to do it anymore lol :P Unfortunately this is some custom stuff I'm trying to monitor and this about the only way I can gaurantee it's working via script.

But thanks for the advice and Happy Holidays.

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

My point was that there may be other ways to do this easily in AutoIt.

What do you mean exactly by "Console Window"?

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

a command prompt (cmd) I have a command line telnet application and once it initializes and completes it's connection as long as everything is working. I would want to capture the text in that window so that I can parse it for certain words.

Basically the company has a third party telnet server that calls other apps so just having the telnet client connection does nto neccessarily mean the service is properly working.

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...