2

I am trying to extract content from a external application made in visual basic 6 using c#. I use SendMessage function and others from user32.dll. I can read from textboxes, buttons, etc but the problem comes when I try to read information from labels controls. I have read that labels in visual basic 6 have not Windows Handle (hWnd), so I can't send a WM_GETTEXT message to the control.

I would know if exists any method to read the caption property of these labels objects?

dlopezgonzalez
  • 4,217
  • 5
  • 31
  • 42
  • 1
    Yes, a Label is windowless. Lots of developers have moved to using lightweight/windowless textboxes, buttons, and other controls to help resist application hijacking in general. – Bob77 Sep 24 '13 at 11:16
  • Labels are indeed windowless. Perhaps this could be done if it's possible to access the Component Object Model in the program. I'm not sure if there's a way to access it directly from a different program, or if you'd need to inject an extra DLL into it or something. But if you could iterate VB.Global.Forms you could find the Form object, then iterate its Controls collection to find the label, and pull the text out of the Label's Caption property directly. – Boann Sep 24 '13 at 14:47
  • 1
    Another idea: If you're desperate, and the layout of the window is fairly static, you could screenshot the relevant part of the window and pipe it through an OCR engine. I've never done C# or .NET but there is a .NET wrapper for the Tesseract OCR engine, which has worked well for me in the past in Java. – Boann Sep 24 '13 at 15:00
  • Yes man, this is the idea if there is not solution using hijacking technics. Take a piece of the screen and execute the OCR engine. But then I am dealing with 500K screenshots, this could take a long time. Thanks you. Here we go :( http://stackoverflow.com/questions/1163761/c-sharp-capture-screenshot-of-active-window – dlopezgonzalez Sep 25 '13 at 10:00
  • If you know VB6, the source code in [this question](https://stackoverflow.com/q/27797977) would work, but only on Windows NT 5.x or lower. It took me some hours to translated that into [Python 3](https://github.com/Arnie97/emu-tools/blob/master/shot.py#L120) so maybe you can also translate it into C#. – Arnie97 Apr 02 '19 at 18:34

0 Answers0