SendMessage Method :cannot evaluate expression because a native frame is on top of the call stack


hi gurus,

i getting message "cannot evaluate expression because native frame on top of call stack"  while executing sendmessage method. method performs operation i.e click final button , complete process , 1 "save as" window pops up,  then here stuck every time. have tried publish code , run same situation coming.

i have 2 question after doing hell lot of google...

question 1: why control getting stuck every time @ sendmessage?

question 2: how can windows handle of save window can close during execution of sendmessage method.

code body

        [dllimport("user32.dll", charset = charset.auto, setlasterror = true)]

        private static extern intptr sendmessage(intptr hwnd, uint msg, int wparam, int lparam);

        public void buttonhandles()

        {

            

            thread.sleep(10000);

            try

            {

                process[] processes1 = process.getprocessesbyname("<processname>");

                foreach (process p1 in processes1)

                {

                   

                    if (findwindowex(p1.mainwindowhandle, intptr.zero, null, "&finalize") != intptr.zero)

                    {

                        autobuttonhandle = findwindowex(p1.mainwindowhandle, intptr.zero, null, "&finalize");

                        thread.sleep(10000);

                       

                      }

// while check if finalize button clicked or not                         do

                       {

                            if (autobuttonhandle == intptr.zero)

                            {

                              autobuttonhandle = findwindowex(p1.mainwindowhandle, intptr.zero, null, "&finalize");

                            }

                            try

                            {

                                if (nstateclickreturn == intptr.zero)

                                {

//below method having issue. control stuck here.

                                    nstateclickreturn = sendmessage(autobuttonhandle, bm_click, intptr.zero,intptr.zero);

                                  

                                }

                             

                                                               

                                sendkeys.sendwait("{enter}");

                            }

                            catch (system.threading.threadabortexception e)

                            {

                                console.writeline(e.stacktrace);

                            }

                           // nstateclickreturn = postmessage(autobuttonhandle, bm_click, 0, 0);

                            checkforredactiontofinish();

                            //thread.sleep(10000);

                        } while (nstateclickreturn == intptr.zero || autobuttonhandle == intptr.zero);

                    }

              

               // thread.sleep(10000);

              

                //process[] processes3 = process.getprocessesbyname("docmgr");

               

                //foreach (process p3 in processes3)

                //{

                //    ////the button's caption "send" , "button"

                //    if (findwindowex(p3.mainwindowhandle, intptr.zero, null, "&save") != intptr.zero)

                //    {

                //        autobuttonhandle1 = findwindowex(p3.mainwindowhandle, intptr.zero, null, "&save");

                //        thread.sleep(10000);

                //        //buttonhandle 0 thats think problem

                //        sendmessage(autobuttonhandle1, bm_click, intptr.zero, intptr.zero);

                //    }

                //}

            }

            catch (win32exception e)

            {

                console.writeline(e.stacktrace);

            }

        }

                            if (autobuttonhandle == intptr.zero)

                            {

                              autobuttonhandle = findwindowex(p1.mainwindowhandle, intptr.zero, null, "&finalize");

                            }

                            try

                            {

                                if (nstateclickreturn == intptr.zero)

                                {

//below method having issue. control stuck here.

                                    nstateclickreturn = sendmessage(autobuttonhandle, bm_click, intptr.zero,intptr.zero);

                                  

                                }

hi nitin797,

there's logic error in code snippet think. if handle autobuttonhandle intptr.zero, sendmessage method still called.

[dllimport("user32.dll", charset = charset.auto, setlasterror =  true)] private static  extern intptr sendmessage(intptr hwnd, uint msg, int wparam, int lparam); 

also can see, 3rd , 4th parameter of method of type int, in code send 2 intptrs it. won't compile. doubt if have tested code in project.

please post whole error message , stack trace can furtherly investigate problem.

to troubleshoot problem, recommend firstly make example project call sendmessage method, make sure works ok proper signature. try not use try-catch block debug code step step.


we trying better understand customer views on social support experience, participation in interview project appreciated if have time. helping make community forums great place.
click here participate survey.



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'