Click here to Skip to main content
15,905,028 members
Home / Discussions / C#
   

C#

 
GeneralRe: Unable to cast COM object of type 'mshtml.HTMLDocumentClass' to class type 'System.Windows.Forms.HtmlDocument'. Pin
TnTinMn25-Sep-13 16:43
TnTinMn25-Sep-13 16:43 
GeneralRe: Unable to cast COM object of type 'mshtml.HTMLDocumentClass' to class type 'System.Windows.Forms.HtmlDocument'. Pin
BillWoodruff26-Sep-13 8:01
professionalBillWoodruff26-Sep-13 8:01 
GeneralRe: Unable to cast COM object of type 'mshtml.HTMLDocumentClass' to class type 'System.Windows.Forms.HtmlDocument'. Pin
TnTinMn26-Sep-13 15:29
TnTinMn26-Sep-13 15:29 
QuestionChessboard UI Pin
DeFles24-Sep-13 23:40
DeFles24-Sep-13 23:40 
AnswerRe: Chessboard UI Pin
Abhinav S24-Sep-13 23:45
Abhinav S24-Sep-13 23:45 
QuestionOutOfMemoryException Pin
ptvce24-Sep-13 21:04
ptvce24-Sep-13 21:04 
SuggestionRe: OutOfMemoryException Pin
Richard Deeming25-Sep-13 1:38
mveRichard Deeming25-Sep-13 1:38 
Questionenumchildwindows error Pin
eng.iris24-Sep-13 17:58
eng.iris24-Sep-13 17:58 
Quote:
hi guys
i have this code which call an application into my picturebox
it works fine in vb 6 but when i converted to c# i got thi error

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.


and when i trace the code its still in my form handle >>why it didn't go through all window handles??
i tthink my error is in the return of EnumChildProc function ,,,the return value or it calling in EnumChildwindow


here is the code hope sombody help me Frown | :(

 <blockquote class="FQ"><div class="FQA">Quote:</div>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace call_another_exe
{
    public partial class Form1 : Form
    {
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError = true)]
        static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
        // For Windows 
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        //class name
        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
        //get desktop win
         [DllImport("user32.dll", SetLastError = false)]
        static extern IntPtr GetDesktopWindow();
        /////enum children
         [DllImport("user32.dll")]
         [return: MarshalAs(UnmanagedType.Bool)]
         static extern bool EnumChildWindows(IntPtr hwndParent, IntPtr lpEnumFunc, int lParam);
        //get window caption
         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
         static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
        /////get parent of the handle
         [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
         public static extern IntPtr GetParent(IntPtr hWnd);
         ////The SetParent function changes the parent window of the specified child window.
         [DllImport("user32.dll", SetLastError = true)]
         static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
        /////show the window hndle
        [DllImport("user32.dll", SetLastError=true)]
         private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
        ///////
        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern int GetWindowTextLength(IntPtr hWnd);
        /////// constants
        private const string gcClassnameNotePad = "WindowsForms10.Window.8.app.0.33c0d9d";
        public static int CC; //global 
        public int CurrentCount;
        private const int SW_NORMAL = 1;
        private const int SW_MAXMIZE = 3;
        private const int SW_MINIMIZE = 6;
        private const uint WM_DESTROY = 0x0002;
        private const int WM_CLOSE = 0x0010;//&h10

        ////////
        public IntPtr EnumChildProc(IntPtr hwnd)
        {
            StringBuilder sSave;
            StringBuilder lpClassName ;
            long RetVal;
    //Get the windowtext length
   /////  كيف  sSave = Space$(GetWindowTextLength(hwnd) + 1)
            sSave = new StringBuilder("",GetWindowTextLength(hwnd) + 1);
    //get the window text
    GetWindowText(hwnd, sSave,sSave.Capacity);
    //remove the last Chr$(0)
                //sSave = Left$(sSave, Len(sSave) - 1)

            

    if (sSave.ToString().Contains("ProgDVB"))
    {

        lpClassName = new StringBuilder(256);
        //retrieve the class name
        RetVal = GetClassName(hwnd, lpClassName, 256);
       
        if (lpClassName.ToString(0,Convert.ToInt16(RetVal)).Equals("WindowsForms10.Window.8.app.0.33c0d9d"))
        {
            CurrentCount = CurrentCount + 1;

            SetParent(hwnd, this.pictureBox1.Handle);
            if (hwnd != this.pictureBox1.Handle)
            {
                ShowWindow(hwnd, SW_MAXMIZE);
            }
        }
    }
   
    IntPtr y;
    y = new IntPtr(1);
return y;
          }

        public IntPtr EnumChildCount(IntPtr hwnd, IntPtr lparam)
        {
            
    StringBuilder  sSave;
    StringBuilder lpClassName ;
            long RetVal;
    //Get the windowtext length
    sSave = new StringBuilder(GetWindowTextLength(hwnd) + 1);
    //get the window text
    GetWindowText( hwnd, sSave, sSave.Length);
    //remove the last Chr$(0)
      sSave.ToString(0,sSave.Length );
    if (sSave.ToString().Contains("ProgDVB"))
    {
       lpClassName = new StringBuilder(256);
    //retrieve the class name
        RetVal = GetClassName(hwnd, lpClassName, 256);
    //MsgBox RetVal  //Show the classname
       if (lpClassName.Remove(lpClassName.Length, Convert.ToInt16(RetVal)).Equals("WindowsForms10.Window.8.app.0.33c0d9d"))
        {
          
 if (lpClassName.ToString(0,Convert.ToInt16(RetVal)).Equals("WindowsForms10.Window.8.app.0.33c0d9d"))
 {
     CC = CC + 1;
 }
       }
   }     
   
    //continue enumeration
    IntPtr y;
    y = new IntPtr(1);
    return y;
      }

        public IntPtr EnumChildCloseup(IntPtr hwnd, IntPtr lparam)
        {

            StringBuilder sSave;
            StringBuilder lpClassName;
            long RetVal;
            sSave = new StringBuilder(GetWindowTextLength(hwnd) + 1);
            //get the window text
            GetWindowText(hwnd, sSave, sSave.Length);
            sSave.ToString(0,sSave.Length);

            if (sSave.ToString().Contains("ProgDVB"))
            {
                lpClassName = new StringBuilder(256);
                //retrieve the class name
                RetVal = GetClassName(hwnd, lpClassName, 256);
                //MsgBox RetVal
                //Show the classname
                if (lpClassName.Remove(lpClassName.Length, Convert.ToInt16(RetVal)).Equals("WindowsForms10.Window.8.app.0.33c0d9d"))
                {

                    PostMessage(hwnd, WM_DESTROY, 0, 0);
                }
            }
            IntPtr y;
            y = new IntPtr(1);
            return y;

        }
      
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(GetDesktopWindow().ToString());
            EnumChildWindows(GetDesktopWindow(), EnumChildProc(Handle), 0);
        }


        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
           EnumChildWindows(GetDesktopWindow(), EnumChildCloseup(Handle, IntPtr.Zero), 0);
        }
        
      
    }
}
</blockquote>



i appreciate your great help

thank you
AnswerRe: enumchildwindows error Pin
Eddy Vluggen25-Sep-13 1:59
professionalEddy Vluggen25-Sep-13 1:59 
GeneralRe: enumchildwindows error Pin
eng.iris25-Sep-13 2:25
eng.iris25-Sep-13 2:25 
QuestionThat assembly does not allow partially trusted callers Pin
gautam baruah123-Sep-13 22:57
gautam baruah123-Sep-13 22:57 
AnswerRe: That assembly does not allow partially trusted callers Pin
Abhinav S24-Sep-13 17:01
Abhinav S24-Sep-13 17:01 
Questionread and write sector of hard disk in windows 7 and up version Pin
ptvce23-Sep-13 18:40
ptvce23-Sep-13 18:40 
AnswerRe: read and write sector of hard disk in windows 7 and up version Pin
Abhinav S23-Sep-13 19:40
Abhinav S23-Sep-13 19:40 
QuestionUnderstanding changes of the mouse icon Pin
amirpooya23-Sep-13 2:36
amirpooya23-Sep-13 2:36 
AnswerRe: Understanding changes of the mouse icon Pin
Eddy Vluggen23-Sep-13 2:38
professionalEddy Vluggen23-Sep-13 2:38 
AnswerRe: Understanding changes of the mouse icon Pin
V.23-Sep-13 3:01
professionalV.23-Sep-13 3:01 
GeneralRe: Understanding changes of the mouse icon Pin
Eddy Vluggen23-Sep-13 3:32
professionalEddy Vluggen23-Sep-13 3:32 
GeneralRe: Understanding changes of the mouse icon Pin
V.23-Sep-13 3:35
professionalV.23-Sep-13 3:35 
GeneralRe: Understanding changes of the mouse icon Pin
Eddy Vluggen23-Sep-13 5:50
professionalEddy Vluggen23-Sep-13 5:50 
AnswerRe: Understanding changes of the mouse icon Pin
BillWoodruff23-Sep-13 4:55
professionalBillWoodruff23-Sep-13 4:55 
AnswerRe: Understanding changes of the mouse icon Pin
Pete O'Hanlon23-Sep-13 7:07
mvePete O'Hanlon23-Sep-13 7:07 
GeneralRe: Understanding changes of the mouse icon Pin
ExcellentOrg23-Sep-13 8:23
ExcellentOrg23-Sep-13 8:23 
GeneralRe: Understanding changes of the mouse icon Pin
Pete O'Hanlon23-Sep-13 8:41
mvePete O'Hanlon23-Sep-13 8:41 
GeneralRe: Understanding changes of the mouse icon Pin
ExcellentOrg25-Sep-13 20:05
ExcellentOrg25-Sep-13 20:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.