|
i write this code :
when i debuged , in line 5 i see this error : "Exception of type 'System.OutOfMemoryException' was thrown."
do u know what should i do?
1- HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter);
2- DataGrid DataGrd = new DataGrid();
3- DataGrd.DataSource = dsGrid;
4- DataGrd.DataBind();
5- DataGrd.RenderControl(htmlWrite);
|
|
|
|
|
|
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
<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);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
[DllImport("user32.dll", SetLastError = false)]
static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool EnumChildWindows(IntPtr hwndParent, IntPtr lpEnumFunc, int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[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);
private const string gcClassnameNotePad = "WindowsForms10.Window.8.app.0.33c0d9d";
public static int CC;
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;
public IntPtr EnumChildProc(IntPtr hwnd)
{
StringBuilder sSave;
StringBuilder lpClassName ;
long RetVal;
sSave = new StringBuilder("",GetWindowTextLength(hwnd) + 1);
GetWindowText(hwnd, sSave,sSave.Capacity);
if (sSave.ToString().Contains("ProgDVB"))
{
lpClassName = new StringBuilder(256);
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;
sSave = new StringBuilder(GetWindowTextLength(hwnd) + 1);
GetWindowText( hwnd, sSave, sSave.Length);
sSave.ToString(0,sSave.Length );
if (sSave.ToString().Contains("ProgDVB"))
{
lpClassName = new StringBuilder(256);
RetVal = GetClassName(hwnd, lpClassName, 256);
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;
}
}
}
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);
GetWindowText(hwnd, sSave, sSave.Length);
sSave.ToString(0,sSave.Length);
if (sSave.ToString().Contains("ProgDVB"))
{
lpClassName = new StringBuilder(256);
RetVal = GetClassName(hwnd, lpClassName, 256);
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
|
|
|
|
|
eng.iris wrote: i tthink my error is in the return of EnumChildProc function Compare it to the implementation here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
i solved it
i tried delegates and it works fine
thanks alot
|
|
|
|
|
I am trying to use a winform user control in an .aspx page. I could do it successfully without any issue. But now when I am trying to use an external .dll inside this user control then it is throwing me an error – “That assembly does not allow partially trusted callers”. But I could use this same user control inside a winform without any error. How could I make my web application a fully trusted to an external .dll? Kindly help.
|
|
|
|
|
|
does any body know how can read and write the hard disk sector with c# not assemblly?
thanks
|
|
|
|
|
PInvoke.net\[^] has API wrappers that may allow you to do this.
You can also explore this[^] article which would help you achieve this task.
|
|
|
|
|
|
The answer will not change. There's no way to say whether the mouse-cursor has changed.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
cross posting is frowned upon. Everyone here is helping on voluntarily basis.
If I understood your question correct I think it is a little over your head. (and over mine for that matter) My initial thought would be that you'll have to dig deep down into the bowls of Windows somewhere hooking up some sort of plugin that understands the event changes, more specifically for mouse events and/or draw events and writing a service that uses that plugin.
But that's just quick thinking.
|
|
|
|
|
V. wrote: you'll have to dig deep down into the bowls of Windows somewhere hooking up some sort of plugin that understands the event changes There is no specific event; the mouse-cursor could even be hidden with a bitmap floating over it, acting like a cursor.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I didn't think it would be one event .
|
|
|
|
|
V. wrote: I didn't think it would be one event I don't think it would be at all.
Even if you handle all WM_MOUSEMOVE and other messages, you'd still be guessing what the actual cursor looks like.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Please do not remove questions from Q&A that people have responded to, in depth.
thanks, Bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
Well, you could get this information for the standard cursors using GetCursorInfo, which retrieves the details of the current cursor whether or not your application owns it. There is, however, a big catch, and that's the fact that the reference to the cursor is a handle and I can't see any cursor function that will allow you to match a handle to a cursor. What you could do, though, is load every standard cursor (via the API and not the .Net functionality), and capture the handle there - this handle is global, so when it's loaded once, the same reference is used regardless of what application attempts to load the same cursor.
|
|
|
|
|
If all you want to know whether a URL was loaded or not, you do not need to look at mouse cursor, your application will be lot more robust if you decided to do some kind of Async call and then time-out from your receiver.
Shape of mouse cursor is way down on the totem pole of events and in any case its user-interface thing and No good application design should depend on the tail of responses.
That said, all mouse cursors have a constant value (IMHO they used to be called Handles back in the days of WIN32 API) that does not change across application.
If this was the only way out, I'd write a WIN SDK C++ app in which I create full sized transparent always-on-top window with no borders that scans all mouse events. and return the base WndProc unhandled ... Dabble a bit in Spy tool that comes with visual studio.
|
|
|
|
|
You might want to check who you replied to. I don't really want to do any async calls to check whether or not a URL was loaded.
|
|
|
|
|
Sorry... Reply was meant for original poster...
|
|
|
|
|
"Make the necessary changes to Example 5-14 to make the Employee
class a subclass of the Citizen class. Display some properties from
the Citizen class, such as the SSN and Age. The output should look
something like:
Citizen's Information:
SSN: 555-55-5555
Age: 36
Job Information:
Company Name: Pille Mandla
Company ID: 123-WxYz"
I'm about halfway done with my certification e-book/course… This was one of the little homework assignments…
I realize I could have done it two different ways, I was wondering if there was any other way of accomplishing this…
I realize it is just a simple program, but… As far as performance wise (let's pretend it's a larger program), which way is the most optimal?
Here is what I done:
using System;
public class Citizen
{
private string ssn;
private string age;
public string SSN
{
get { return ssn; }
set { ssn = value; }
}
public string Age
{
get { return age; }
set { age = value; }
}
public void DisplayCitizenInfo()
{
Console.WriteLine("Citizen's Information:");
Console.WriteLine("SSN: {0}", ssn);
Console.WriteLine("Age: {0}\n", age);
}
public Citizen()
{
Console.WriteLine("Please enter the citizens Social Security number: ");
SSN = Console.ReadLine();
Console.WriteLine("Please enter the citizens age: ");
Age = Console.ReadLine();
}
}
public class Employee : Citizen
{
private string name;
private string id;
public string Name
{
get { return name; }
set { name = value; }
}
public string Id
{
get { return id; }
set { id = value; }
}
public void DisplayInfo()
{
Console.WriteLine("Employee's name: {0}", name);
Console.WriteLine("Employee's id: {0}", id);
}
}
class MyClass
{
static void Main(string[] args)
{
Employee emp = new Employee();
Console.Write("Please enter the employee's name: ");
emp.Name = Console.ReadLine();
Console.Write("Please enter the employee's id: ");
emp.Id = Console.ReadLine();
emp.DisplayInfo();
}
}
|
|
|
|
|
In this example, you've got some stuff wrong. For a start, why do you have a separate method to display the information from each class. You would have been better off overriding a method here. Similarly, I would look at changing the way that you gather information - the Citizen constructor violates way too many good practices. If I were writing this, I would look at something like this
public class Citizen
{
public string Ssn;
public int Age;
public virtual void GetDetails()
{
SSN = GetInput("Please enter the citizen's Social Security number: ");
Age = GetAge();
}
public virtual void DisplayInfo()
{
Console.WriteLine("Citizen's Information:");
Console.WriteLine("SSN: {0}", Ssn);
Console.WriteLine("Age: {0}{1}", Age, Environment.NewLine);
}
protected string GetInput(string message)
{
Console.WriteLine(message);
return Console.ReadLine();
}
private void GetAge()
{
bool success = false;
int age;
while (!success)
{
string tempAge = GetInput("Please enter the citizen's age: ");
bool success = int.TryParse(tempAge, age);
if (!success)
{
Console.WriteLine("Unfortunately, you did not enter a valid integer (or whatever message you like here");
}
}
}
}
public class Employee : Citizen
{
public string Name;
public string Id;
public override void GetDetails()
{
base.GetDetails();
Name = GetInput("Please enter the employee's name:");
Id = GetInput("Please enter the employee's id:");
}
public override void DisplayInfo()
{
base.DisplayInfo();
Console.WriteLine("Employee's name: {0}", Name);
WriteLine("Employee's id: {0}", Id);
}
} As you can see, the classes are now largely self contained. We have some common functionality handled very simply for us, and we have a consistent interface that we are coding to. Actually, while I'm demonstrating this, it's a good idea to consider why I'm using fields, rather than properties. There's a commonly held belief that you MUST expose properties rather than fields, but in simple cases like this, that's a load of horse-hooey. If you are only using a property to store a value, and your class isn't doing something like Serialization, then you don't need a property there.
Note that I've just knocked this together in the editor and I've not had much sleep, so there may be the odd minor typo in there. I apologise if that is the case.
|
|
|
|
|
Okay, thank you for your response and your feedback/constructive criticism…
I myself haven't had much sleep when I finished this little exercise… I should have set it up a little better…
This exercise came at the end of chapter 5, it was discussing the basics of inheritance, properties, read-only and const keywords…
I'm guessing the book just wanted me to practice writing code for inheritance and properties…
With that said, I do realize I could have just created an object in the main method to ask the user to enter a Social Security number and age…
I just want to practice, and throwing in a constructor…
|
|
|
|
|
Have you guys ever found a bug or misbehaviour that you were unable to correct?
I´ve had a bug haunting me for weeks that makes me wonder if there are unsolveable bugs out there.
I lack experience since ive only been coding proffessionally for 5 years.
If you had one,what was it and what made you give up?
(I´m coding in C#, thats why i posted it on this forum.)
|
|
|
|
|
Söderlund wrote: I´m coding in C#, thats why i posted it on this forum Well, it's the wrong place, this forum is for technical questions; try the Lounge[^] for this type of discussion.
Veni, vidi, abiit domum
|
|
|
|
|