c# - GetWindowText() function is not executing correctly at all times -


i'm writing small application wish url chrome browse.

in order first check if chrome browser open or not use following code:

 intptr windowtitletextptr = getforegroundwindow();   stringbuilder windowtitletext = new stringbuilder();   getwindowtext(windowtitletextptr, windowtitletext, 256); // problem   ... 

i'm using getwindowtext() function windows title text, i'm facing problem there.

if chrome window has no url , new tab have no issues, windowtitletext.tostring() equal new tab - google chrome.

however if open webpage, in case url filled url @ line getwindowtext() get: vs32host.exe has stopped working message window asking me enter image description here

what's going on?

help!

you should allocate memory within stringbuilder instance:

  stringbuilder windowtitletext = new stringbuilder();    int size = 256;   windowtitletext.length = size; // <- memory allocation    getwindowtext(windowtitletextptr, windowtitletext, windowtitletext.length); // <- read text allocated memory 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -