|
Hi everyboody
I tried DirectX.Capture modified can be archived into a wmv, but I do not know how to share?
|
|
|
|
|
I have these 5 method objects. These 5 method objects have exactly same function calls. Example as below:
int method = 3;
int result = 0;
Method1 m1 = new Method1();
Method2 m2 = new Method2();
Method3 m3 = new Method3();
Method4 m4 = new Method4();
Method5 m5 = new Method5();
switch (method)
{
case 1: m1.SolveThis(ref int result); break;
case 2: m2.SolveThis(ref int result); break;
case 3: m3.SolveThis(ref int result); break;
case 4: m4.SolveThis(ref int result); break;
case 5: m5.SolveThis(ref int result); break;
}
(inside each m* contains different methods, for the sake of arugment).
Is it possible to do this as below?
Object mm;
int method = 3;
int result = 0;
switch (method)
{
case 1: mm = new Method1; break;
case 2: mm = new Method2; break;
case 3: mm = new Method3; break;
case 4: mm = new Method4; break;
case 5: mm = new Method5; break;
}
mm.SolveThis(ref int result); // this line doesn't see "SolveThis" funtion in .NET.
Anyone have any thoughts?
|
|
|
|
|
Blubbo wrote: Anyone have any thoughts?
Yes. A head full.
1. What you probably want is called an interface . Have all these MethodX classes implement a common interface which is a promise to implement whatever you like, such as a void SolveThis(ref int) method.
2. Please use PRE tags when posting code (or tabular data). It improved readability.
3. Your choice of names is horrible. A method is a method, a class is a class; don't define a class called MethodX. SolveThis is another poor choice, "this" has a special meaning in object-oriented languages such as C#.
4. Why is it your SolveThis method using a ref parameter, and apparently not using any return value?
5. If you're new to C# (or to programming in whatever language) I strongly recommend you choose, buy and study a book (a real book, one you own) and acquire good practices from day one; it is the easiest and fastest way to make real progress.
|
|
|
|
|
1) I haven't used interface in my code before... the next responder by RobCroll has suggested a good solution for my question.
2) Yes, I am aware of PRE tags but apparently forgot to include that in my initial posting. My bad!
3) I was having hard time on what to say to give the reader the example without revealing important codes in my source (its work related).
4) I use int return value to provide the error code in case the function call failed to process. that's why I use ref parameter.
5) I am not new to C#. I have few books here and also online resources to help me out... I am still working on improving the efficiency of my codes.
|
|
|
|
|
Blubbo wrote: I have few books here
Every book on C# is bound to discuss interfaces, so my best advice is to read one of those books you have from cover to cover and you will learn some of the basics you seem to be lacking right now. Browsing some on-line material is no substitute, it is a handy addition.
|
|
|
|
|
Create an interface get the other classes to implement that interface
interface ISolution
{
int SolveThis(int question);
}
public class SolutionClass1 : ISolution
{
...
public int SolveThis(int question)
{
return result;
}
}
ISolution solution;
int method = 3;
int result;
switch (method)
{
case 1: solution = new SolutionClass1; break;
case 2: solution = new SolutionClass2; break;
case 3: solution = new SolutionClass3; break;
case 4: solution = new SolutionClass4; break;
case 5: solution = new SolutionClass5; break;
}
result = solution.SolveThis(result);
"You get that on the big jobs."
|
|
|
|
|
hmm... this might be the solution to my question. I'll give this a shot. Thanks!
|
|
|
|
|
If the methods are different, then why not create one static class with several methods with different names or overloaded methods(assuming the signatures are different)?Do you have a particular need for naming all the methods the same in the different classes?
|
|
|
|
|
Is this a case where you can assume that every Method you will call has the same signature, and returns the same type of result ?
If that's the case, there's an interesting solution, I'll post here.
best, Bill
When I consider the brief span of my life, swallowed up in the eternity before and after, the little space which I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which knows me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then. Blaise Pascal
|
|
|
|
|
I have a user drawn form with rounded corners. I have set the .TransparencyKey of the form to the background color but when I set the SmoothingMode to .AntiAlias I get a halo effect on the corners when the form is displayed against a light background, as the background color is black. If I change the background color to SystemColors.Control I get the halo when the form is displayed against my dark desktop.
Is there a quick fix to this problem or do I have to (painfully) sample all of the colours used in the anti-alias effect and make them all transparent (if this is indeed possible) to get rid of this halo?
protected override void OnPaint(PaintEventArgs e)
{
Graphics gr = e.Graphics;
LinearGradientBrush GrBrush;
GraphicsPath gPath;
int w;
int h;
w = this.Width;
h = this.Height;
gr.SmoothingMode = SmoothingMode.HighQuality;
GrBrush = new LinearGradientBrush(new Point(0, 0), new Point(0, 75), Color.FromArgb(255, 51, 51, 51), Color.FromArgb(255, 0, 0, 0));
gPath = new GraphicsPath();
gPath.AddArc(new Rectangle(0, 0, 15, 15), 180, 90);
gPath.AddArc(new Rectangle(w-16, 0, 15, 15), 270, 90);
gPath.AddLine(new Point(w-1, 75), new Point(0, 75));
gPath.CloseAllFigures();
gr.FillPath(GrBrush, gPath);
gr.DrawPath(new Pen(GrBrush), gPath);
GrBrush = new LinearGradientBrush(new Point(0, 14), new Point(0, h-1), Color.FromArgb(255, 1, 1, 1), Color.FromArgb(255, 0, 0, 80));
gPath = new GraphicsPath();
gPath.AddArc(new Rectangle(-10, 15, 400, 50), 180, 45);
gPath.AddLine(new Point(w-1, 15), new Point(w-1, 75));
gPath.AddArc(new Rectangle(w-16, h-21, 15, 15), 0, 90);
gPath.AddArc(new Rectangle(0, h-21, 15, 15), 90, 90);
gPath.CloseAllFigures();
gr.FillPath(GrBrush, gPath);
gr.DrawPath(new Pen(GrBrush), gPath);
GrBrush = new LinearGradientBrush(new Point(5, 80), new Point(5, h-6), Color.FromArgb(255, 245, 245, 255), Color.FromArgb(255, 150, 150, 160));
gPath = new GraphicsPath();
gPath.StartFigure();
gPath.AddArc(new Rectangle(5, 80, 10, 10), 180, 90);
gPath.AddArc(new Rectangle(w-16, 80, 10, 10), 270, 90);
gPath.AddArc(new Rectangle(w-16, h-21, 10, 10), 0, 90);
gPath.AddArc(new Rectangle(5, h-21, 10, 10), 90, 90);
gPath.CloseAllFigures();
gr.FillPath(GrBrush, gPath);
gr.DrawPath(new Pen(GrBrush), gPath);
}
Any help would be appreciated. Thx.
|
|
|
|
|
Hi all!.
I would like use unmanaged code from C in C#.
I built a DLL with C code with this functions:
<pre lang="c++">
struct GetPluginData
{
int data[22];
};
DLLEXPORT extern "C" __declspec (dllexport) GetPluginData GetDataArray(int number);
In C# I've got this code:
[StructLayoutAttribute(LayoutKind.Sequential, Pack=1)]
public unsafe struct GetPluginData
{
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 22, ArraySubType = UnmanagedType.I4)]
public int[] data;
}
[DllImport("RBRPlugin.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDataArray")]
[return: MarshalAs(UnmanagedType.Struct)]
public static extern GetPluginData GetDataArray(int number);
In button event or othe place code, I wrote this:
GetPluginData tes = GetDataArray(1);
And I'm getting the error: The type signature of this method is not PInvoke compatible.
I'm looking for information throught google, but no result found...
Thanks in advance!
|
|
|
|
|
There is another way you can marshal the return type from that function.
First, declare the return type from the C function to be a pointer to the GetPluginData structure instead of the structure itself.
Declare the return type as an IntPtr in C#, and then use the functions in the Marshal class to read the structure from unmanaged memory into a managed structure.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi!
Thanks for the info Richard. The solution was write for Hans Passans in StackOverflow:
[DllImport("RBRPlugin.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "GetDataArray")]
public static extern GetPluginData GetDataArray(int number);
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct GetPluginData
{
public unsafe fixed int data[22];
}
public GetPluginData temp1 = new GetPluginData();
private void button1_Click(object sender, EventArgs e)
{
GetPluginData test = GetDataArray(1);
temp1 = test;
unsafe
{
fixed (GetPluginData* p = &temp1)
{
p->data[0] = 1;
}
}
}
Like you read, the principal problem was the array in GetPluginData struct, it must be fixed.
Thaks!
|
|
|
|
|
Hi,
i am developing WCF application using MVC3.
I m using xmlserialization to serialize data.
Here is the sample code:
namespace A{
[serializable]
[DataContract(Name="User")]
[XmlAttribute("User")]
Public class User {
[DataMember(Name="ID"]
[XmlAttribute("ID"),IsRequired=false]
public void ID {get; set;}
[DataMember(Name="ID"]
[XmlAttribute("IDSpecified"),IsRequired=false]
public void IDSpecified{get; set;}
}
}
Now i am assigning values to this properties and trying to serialize xml.
User.ID=1;
User.IDSpecified=2;
It is giving error because property names are starting with same string "ID". If i change "Specified" instead of "IDSpecified" then it is serialize fine because property name is different.
So is there any rule that property name should not start wth same characters
Pls help me ASAP.
Thank you.
modified 20-Dec-11 8:49am.
|
|
|
|
|
Why cant you use
[DataMember(Name="ID"]
[XmlAttribute("ID"),IsRequired=false]
public void ID {get; set;}
[DataMember(Name="SpecifiedID"]
[XmlAttribute("SpecifiedID"),IsRequired=false]
public void SpecifiedID{get; set;}
instead of
[DataMember(Name="ID"] ***
[XmlAttribute("ID"),IsRequired=false]
public void ID {get; set;}
[DataMember(Name="ID"] ***
[XmlAttribute("IDSpecified"),IsRequired=false]
public void IDSpecified{get; set;}
Is it permitted to use same Id for two different data members ?
|
|
|
|
|
hI,
Sorry for the mistake in question. Datamember names are different only.
[DataMember(Name="ID"]
[XmlAttribute("ID"),IsRequired=false]
public void ID {get; set;}
[DataMember(Name="SpecifiedID"]
[XmlAttribute("SpecifiedID"),IsRequired=false]
public void SpecifiedID{get; set;}
Still i m getting same error.
|
|
|
|
|
rk2881 wrote: It is giving error because property names are starting with same string "ID".
I bet that it's due to the datamember; it's no problem to have identifiers that start with the same prefix.
rk2881 wrote: Pls help me ASAP.
We're volunteers, and your question is just as important as all the others here.
Bastard Programmer from Hell
|
|
|
|
|
Did you notice that you have duplicate DataMember names? Thats not allowed. Also, how do you have get/set on a void method?
|
|
|
|
|
Thanks for the reply.
I found the solution. Here is the link:
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx
|
|
|
|
|
hello guys... i have this datagridview inwhich I add some data using DataTable. Now If I add more than one rows in my grid, it adds two empty rows at the bottom while it should add just one. Here is the code
private void CellDblClick(object sender, DataGridViewCellEventArgs e)
{
int colPartNum = 1;
string colPartDetails = "Keyboard";
int colQty = 5;
double colPartCost = 15;
AllItemsDT.Rows.Add(colPartNum, colPartDetails, colQty, colPartCost);
AddRowsToGrid(AllItemsDT);
}
private void AddRowsToGrid(DataTable dt)
{
dgItemDetails.AutoGenerateColumns = false;
dgItemDetails.Columns[0].DataPropertyName = dt.Columns[0].ColumnName;
dgItemDetails.Columns[1].DataPropertyName = dt.Columns[1].ColumnName;
dgItemDetails.Columns[2].DataPropertyName = dt.Columns[2].ColumnName;
dgItemDetails.DataSource = dt;
dgItemDetails.Rows[0].Selected = true;
}
So why it is adding two empty rows at the bottom if I add more than one rows, while it should add just one? thnx
|
|
|
|
|
You may need to call AllItemsDT.AcceptChanges()
And I'm unsure you need most of what's in AddRowsToGrid
|
|
|
|
|
It's 32 bit Window application using kernel32.dll for serial port communication.
(I know about System.IO.Ports.SerialPort class existence, but application run fine in XP.)
In window 7 its not working as expected.
I disabled UAC, run as administrator. This started application but some function are not executing properly.
Like for GSM modem interface,
Modem response for AT command is OK, but in window 7 its not responding for app.
But if i use hyper-terminal in win7, its responding for AT.
What needs to be done to able to run the app?
I tried Google before posting here, but not much help.
I think, its kernel32.dll which the app unable to access or window 7 is restricting some function/feature of it?
Can any one please guide/help me?
regards
|
|
|
|
|
Windows 7 is a lot stricter about hardware access than XP, and this is probably your problem. Have you tried running your app in Compatibility Mode?[^]
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
yes i tried that also.
but application not working as excepted. After compatibility mode setting, application able to read and write on serial port but unable to access modem status (GSM modem status, its capturing in XP like ring, busy etc).
[DllImport("kernel32.dll")]
public static extern Boolean GetCommModemStatus(IntPtr hFile, out UInt32 lpModemStat);
Also for GSM if i use ATZ command its responding, but not for AT.
It has to be with security, access control setting.
any other idea.
regards
|
|
|
|
|
Having code execute well on one operating system does not imply the code is correct or good enough.
When inexplicable things happen, that tells me you are ignoring success/failure results somewhere. Make sure you look at every return value for system calls (such as the ones you're calling in kernel32.dll), call GetLastError correctly when such a function signals an error, and do not swallow exceptions, always report something is wrong, with the necessary details.
And be careful how you handle GetLastError, as the P/Invoke layer interferes with it; I explained it in here[^].
|
|
|
|
|