Yes, I wanted to avoid bothering them, but I guess I don't have any other option. Thank you very much.
_Erik_
Posts
-
Strange problems with WaitForSingleObject Windows function -
Strange problems with WaitForSingleObject Windows functionI forgot to say this in the original post, sorry for that, but the printer driver was also written by myself, that is why I am so puzzled. Anyways, testing with other printers makes no difference: it works fine everywhere I test it but in the customer's computers it does the same... nothing, not even errors... Thanks for the tip anyway, Eddy.
-
Strange problems with WaitForSingleObject Windows functionI am having a really strange problem with a component designed to watch for the printer events: First of all, the component has been working like a charm for years in all of the computers in which I have tested and with several operating systems (Windows XP, Vista, 7 and 8.1), in 32 and 64 bits, and running as normal user and local admin as well. However, in the computers of my last customer (Windows 7 64 bits) it only works when running as local admin which is, of course, unacceptable. Before bothering the admins of my customer I would like to know if someone of you has any ideas about the issue, because I have to confess I am completely puzzled. Basically, the compoment starts a thread in which it invokes FindFirstPrinterChangeNotification, which returns a valid handle. Then it invokes WaitForSingleObject for that handle and here is where things get strange: in every other computer, as I said before, it receives and processes the signals perfectly, but in my customer's ones, unless run under local admin, it just stays waiting and receiving no signals no matter what the printer is doing. I mean it does nothing, not even errors. It just waits but the signal does never arrive. I have been reading through the MSDN documentation but I cannot find any plausible explanation: the printer is a local printer which prints to a file and, yes, WaitForSingleObject requires SYNCHRONIZE access right, which I think shouldn't be a big deal. I have not pasted code here because, as I said, it works like a charm in every other computer, so it must be a security configuration issue. Any ideas? Thank you very much.
-
MQOTDRiddick Easy peasy
-
function call from an c++ dll in c#This call is wrong:
result = Fct2((IntPtr)2, data, 3);
The first parameter should be a pointer to the address of memory which contains the size of the "data" array. Casting a literal "2" to IntPtr is telling the library that the length of the array is in the block of memory with the address 2. Try changing the function definition like this:
[DllImport("Function.dll", CallingConvention = CallingConvention.Cdecl)]
extern static int Fct3(ref int Size, byte[] data, int timeout);And call it like this:
int dtLength = data.Length;
result = Fct2(ref dtLength, data, 3);See you
-
Classes inheritance and something that confuses meLet's make a better example for this:
class Employee
{
public string Name { get; set; }
}class ContractEmployee : Employee
{
public object Contract { get; set; }
}class Program
{
static void Main()
{
Employee e = new ContractEmployee();
e.Name = "Ricky"; // No problem with this
e.Contract = new object(); // Problem: this does not compile
}
}nstk wrote:
which properties and methods does the object e has?
e
object, at runtime, has the properties and methods defined withinContractEmployee
class, because it is the object you have created with new, so it hasName
(inherited fromEmployee
class), andContract
(defined withinContractEmployee
). However, without any casting, frome
object you will only be able to access those members defined withinEmployee
class (Name
property in this case), because it is the type you have used to declare the object. Why? Becausee
object is declared asEmployee
, andEmployee
does not define a member namedContract
. Yes,e
is aContractEmployee
instance and, yes, it has aContract
property, but the compiler does not know it. All the compiler knows is thate
object is declared asEmployee
, so it allows you to access only the members defined inEmployee
class. So, if you want to access theContract
property ofe
object, in this case, you would need a previous casting operation:((ContractEmployee)e).Contract = new object();
// or
ContractEmployee ce = (ContractEmployee)e;
ce.Contract = new object();nstk wrote:
how should I read this?
Any
ContractEmployee
object is aEmployee
, always, so you can declare anEmployee
and instantiate aContractEmployee
, but not in the other direction, I mean, not all of theEmployee
objects have to beContractEmployee
. -
The perfect teacherCongratulations. You have found the main source of the content in hall of shame: shameful teachers.
-
abstarct class basic question [modified]Member 4282287 wrote:
I need to access to proprieties, methods, etc of class
That does not depend on how you create the objects, I mean, your Create method will not help you to achieve what you want. If you can access KM property of a D1 object which you have declared as its base class type (b in this case), you can becouse KM property is definied within the "b" class interface, but not becouse you have made such a strange Create method. So in your sample:
b myClassAb = new D1();
b newClassAb = myClassAb.Create();
Console.WriteLine(newClassAb.KM)You don't need the Create method at all. Just use the constructor and one instance of the object:
b myClassAb = new D1();
Console.WriteLine(myClassAb.KM) -
Memory expensive rubber band selection?Well, then, draw four rectangles around the area you want to keep clear. Just change the Paint event handler I posted before this way:
private void pct_Paint(object sender, PaintEventArgs e)
{
if (drawRect)
{
e.Graphics.FillRectangle(br, 0, 0, pct.Width, r.Y);
e.Graphics.FillRectangle(br, 0, r.Y, r.X, pct.Height);
e.Graphics.FillRectangle(br, r.X, r.Y + r.Height, pct.Width, pct.Height);
e.Graphics.FillRectangle(br, r.X + r.Width, r.Y, pct.Width, r.Height);
}
}This will work pretty well. Do you also want to save the image after you have darkened the area?
-
code for browserNo doubt, a question like this deserves to be here in the hall of shame.
-
Clicking a button with SendMessage [modified] -
abstarct class basic question [modified]I am sorry but, what is the point in creating an instance of a class to just create another instance of the same class? I mean, since Create method is not static it would just work as a constructor so, why don't you just use a constructor? For example, what you want to do is this:
D1 obj = new D1();
D1 obj2 = D1.Create();And what I am saying is... why not?
D1 obj = new D1();
D1 obj2 = new D1();I guess you want a static Create method in your base class, don't you? In this case you will have to make your Create method static and use generics:
abstract class BaseClass
{
public static T Create<T>() where T : BaseClass, new()
{
return new T();
}
}class DerivedClass : BaseClass { }
This way you could use it like this:
DerivedClass obj = BaseClass.Create<DerivedClass>();
-
Memory expensive rubber band selection?What I understand is that you are trying to darken a rectangle within a image, and that rectangle must be refreshed as long as the mouse is moving. Am I right? If this is what you want to do, the problem is that you are creating too many new Graphics and Bitmap objects in a very short time (and these are expensive objects), and updating the Image property a lot of times as well. The best way to do it is to subscribe to the Paint event of the control and code everything in this event handler, so you will receive a Graphics object as a parameter. In the next example there is only a
PictureBox
in the Form, calledpct
:public partial class Form1 : Form
{
bool drawRect = false;
Rectangle r = new Rectangle();
Brush br = new SolidBrush(Color.FromArgb(50, Color.Red));public Form1() { InitializeComponent(); } private void pct\_Paint(object sender, PaintEventArgs e) { if (drawRect) e.Graphics.FillRectangle(br, r); } private void pct\_MouseDown(object sender, MouseEventArgs e) { drawRect = true; r.X = e.X; r.Y = e.Y; } private void pct\_MouseMove(object sender, MouseEventArgs e) { r.Width = e.X - r.X; r.Height = e.Y - r.Y; Refresh(); } private void pct\_MouseUp(object sender, MouseEventArgs e) { drawRect = false; Refresh(); }
}
I've made it quick. You would have to modify it in order to draw the rectangle if the mouse moves to a lower X and/or lower Y coordinate.
-
send fax with C# 2010 [modified]Thanks... but I guess that would be more useful to the op, and maybe he will not see your post becouse you have answered to me.
-
richTextBox problem 2As Luc has already suggested: Do not assign alltxt to rtb.Text nor richTextBox1.Text; Actually, remove rtb variable, you don't need it; Use alltxt.IndexOf method instead of rtb.Find method to search for the text you want. The indexes will be the same. Use these indexes to make the changes on your rich text box control. The lines:
RichTextBox rtb = new RichTextBox(); rtb = richTextBox1;
are useless becouse RichTextBox is a reference type, so your local rtb variable and your richTextBox1 will both be pointing to the same object.
-
How to Reslove Error? -
Best fit polynomial curve to non-continuous data points [Solved]Ok, now I understand it better. Then maybe bezier curves would be a better choice.
-
Best fit polynomial curve to non-continuous data points [Solved]Not sure if this will help but, have you tried a spline interpolation algorithm?
-
LogicCome on, guys. Stop this mess, ok? I don't pretend to know the absolute truth about this but, man, you are wrong or, at least, you might be confusing beginners. The fact that, as you say, "both terms are evaluated no matter what the first expression evaluates to" with the & operator is the key, and it is not a trivial difference. See this example:
string s = null;
bool b1 = s != null && s.Length == 0;
bool b2 = s != null & s.Length == 0;You see the operands here are boolean expressions. However, while b1 would be assigned false without any problem, a runtime NullReferenceException would be thrown when trying to assing the value to b2. This is a really important difference. Both operands are not the same and can never be considered as if they were the same. Under some circumstances they can return the same result, yes, but that does not mean that they are exactly the same or that you can use any of them when you use boolean expressions. Can we, please, go on with our lifes now?
-
LogicFabio V Silva wrote:
what makes you think I don't know the difference between & and &&?!
Oh, nothing at all but, you know, this is a public forum, and although there are many posts in this thread none of them was giving a good explanation about the differencies between those operators, becouse there are differencies, I know them, you know them and I know you know them, but a beginner might get confused after reading this thread. That's all.