|
They are on different project. Both files are part of their own dlls.
The error that the compiler (for file 1) is "Argument 3: cannot convert from 'USB_Comm.BoxInfo' to 'HID_API_Library.BoxInfo'
USB_Comm is namespace for file 1.
HID_API_Library is namespace for file 2.
|
|
|
|
|
In that case, in USB_Comm don't declare your own BoxInfo (again). Instead, use HID_API_Library.BoxInfo.
You can add a #using HID_API_Library.BoxInfo directive to the top of your file to be able to reference BoxInfo directly, without having to specify the namespace all the time.
Like the other poster said: the two types, though structurally the same, are technically not the same type.
|
|
|
|
|
Two "structurally equal but separately declared structs" are not the same type.
So, declare that struct only once. Or, since you only need to use a couple of ints from the struct, you could pass those instead of the struct.
|
|
|
|
|
I'm trying to copy a file to a destination path (for example \newserver\destinationFolder), that can be in another domain or using a different username/password than the current user. How can I specify these new network credentials before doing the File.Copy(...) ?
pls guide me a way to copy file onto remote server of different domain with credentials..
Thanks inadvance... .
No Defeat Is Final Until You Stop Trying!.......
|
|
|
|
|
|
Thanks Mario for the reply..
But i want to achieve this in windows plotform not through web.
i should be able to transfer files once i know remote server's username,password and domain..
pls help me in this regard
No Defeat Is Final Until You Stop Trying!.......
modified on Thursday, June 23, 2011 1:24 AM
|
|
|
|
|
I am having a problem where when my c sharp program opens and closes excel, it leaves a reference to Excel.exe in the task manager running after I call the program to close in my code. After searching, I found the following information, but I need help implementing it into this method.
The link says that an com object with more than 1 child method per variable assignment gives the garbage collector problems. Is anyone able to rewrite the code (or at least get me started) below to have more variables and only 1 child method per variable?
Thanks for reading!
http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects-in-c[^]
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
public string dateRan = "";
public string timeRan = "";
public string userRan = "";
private void writeExcel(string data, int row, int column, bool createSheet, bool closeSheet, bool carriageReturn)
{
if (createSheet == true)
{
dateRan = loggingClass.returnDate(false, true);
timeRan = loggingClass.returnTime(false, false, true);
userRan = System.Environment.UserName;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(Missing.Value);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Cells[2, 1] = "User:";
xlWorkSheet.Cells[2, 2] = System.Environment.UserName;
xlWorkSheet.Cells[3, 1] = "Date ran:";
xlWorkSheet.Cells[3, 2] = dateRan;
xlWorkSheet.Cells[4, 1] = "Time ran:";
xlWorkSheet.Cells[4, 2] = timeRan;
}
else
{
if (data == "pass")
{
xlWorkSheet.get_Range("A" + row, "Z" + row).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Green);
}
if (data == "fail")
{
xlWorkSheet.get_Range("A" + row, "Z" + row).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
}
if (data == "manual")
{
xlWorkSheet.get_Range("A" + row, "Z" + row).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
}
xlWorkSheet.Cells[row, column] = data;
xlApp.Visible = true;
if (closeSheet == true)
{
xlWorkSheet.Application.ActiveWindow.SplitRow = 1;
xlWorkSheet.Application.ActiveWindow.FreezePanes = true;
xlWorkSheet.get_Range("A1", "Z1").Font.Bold = true;
xlWorkSheet.Columns.AutoFit();
xlWorkSheet.Rows.AutoFit();
xlWorkBook.SaveAs(@"c:\temp\log_" + dateRan.Replace("/", "-") + "__" + timeRan.Replace(":", ".") + ".xls", Excel.XlFileFormat.xlWorkbookNormal, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
xlWorkBook.Close(true, Missing.Value, Missing.Value);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
}
}
|
|
|
|
|
You need to store the range objects you create in a place you can clean them up. I think calling into Cells[..] is fine.
|
|
|
|
|
Thank you Bob.
I believe I have it working successfully now, but I discovered our servers don't have office on them, so I am now looking for another solution ... maybe epplus, I don't know?
|
|
|
|
|
At work we use Aspose in one of our projects. I don't know what the licensing costs for that is, though. Alternatively you can create tabular data in another format, for example CSV or HTML.
|
|
|
|
|
How to detect invalid character input in ListView control?
I want to detect invalid character input while editing a ListBox's item and show a tooltip with warning.
I know how to do it for TextBox control:
private void textBox1_TextChanged(object sender, EventArgs e)
{
ToolTip myTooltip = new ToolTip();
if (textBox1.Text.Contains("Invalid Character"))
{
myTooltip.Show("You entered an invalid character", textBox1);
}
}
How to make it for a ListBox control?
Thank you.
|
|
|
|
|
|
Thank you for the reply.
But I can't make use of this method as I need a real-time check for user input.
|
|
|
|
|
You can combine two events to achieve the goal.
First create a flag, like isEditing = false;
On BeforeLabelEdit Event change it to true, meanwhile on AfterLabelEdit Event change it to false.
Then on KeyDown Event check first if isEditing == true, then process the key.
May this be the solution?
EDIT:
On BeforeLabelEdit Event you can store the value and on AfterLabelEdit Event get the value and see if it is changed then rise an custom event? Can this be a better way?
|
|
|
|
|
I found plenty of exmaples of serializing a class to XML, but the resulting XML doesn't seem to have the same format as other XML data I see in the table.
Anyone have an example of the right way to do this?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
Would you like to elaborate on what you consider to be the "right" way? What are you trying to do with the serialized class?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Store the data in SQL
Everything makes sense in someone's mind
|
|
|
|
|
Do you want to store it as XML or in a proper data structure.
If xml, do you need to search the data or can it be stored as simple text?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm trying to serialize a class to SQL, thn later deserialize it back to the class. No need to search
Everything makes sense in someone's mind
|
|
|
|
|
Then you can just store the result of the serialisation in a TEXT column.
|
|
|
|
|
Ok, so I think I have it almost figured out. I'm now trying to create generic Serialize and Deserialize methods:
private static string serialize<T>(T ObjToSerialize)
{
string retVal = string.Empty;
XmlSerializer serializer = new XmlSerializer(ObjToSerialize.GetType());
System.Text.StringBuilder sb = new System.Text.StringBuilder();
using (System.IO.StringWriter writer = new System.IO.StringWriter(sb))
{
serializer.Serialize(writer, ObjToSerialize);
}
retVal = sb.ToString();
return retVal;
}
private static T deserialize<T>(string XmlString) where T : new()
{
T type = new T();
object retVal;
XmlDocument doc = new XmlDocument();
doc.LoadXml(XmlString);
XmlNodeReader reader = new XmlNodeReader(doc.DocumentElement);
XmlSerializer ser = new XmlSerializer(type.GetType());
object obj = ser.Deserialize(reader);
retVal = (T)obj;
return retVal;
}
The Deserialize isn't compiling. It's telling me that I can't cast T to an object. What's wrong here?
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote: It's telling me that I can't cast T to an object.
Why do you even need to do that? Can't you just do something like this?
T retVal = null;
XmlDocument doc = new XmlDocument();
doc.LoadXml(XmlString);
XmlNodeReader reader = new XmlNodeReader(doc.DocumentElement);
XmlSerializer ser = new XmlSerializer(typeof(T));
retVal = (T)ser.Deserialize(reader);
return retVal;
Also, you can probably simplify it by just deserializing using a StringReader instead of loading an XmlDocument then deserializing from that
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Here is the VB.NET version I had laying around (should be fairly simple to convert to C#):
Public Shared Function ToXml(Of T)(ByVal item As T) As String
If item Is Nothing Then
Return String.Empty
End If
Dim serializer As New XmlSerializer(GetType(T), String.Empty)
Dim stream As New MemoryStream
Dim settings As New XmlWriterSettings
settings = New XmlWriterSettings
settings.OmitXmlDeclaration = True
settings.Indent = True
Dim writer As XmlWriter = XmlWriter.Create(stream, settings)
Dim ns As New XmlSerializerNamespaces
ns.Add(String.Empty, String.Empty)
serializer.Serialize(writer, item, ns)
stream.Position = 0
Dim xml As String = New StreamReader(stream).ReadToEnd
writer.Close()
stream.Close()
Return xml
End Function
Public Shared Function FromXml(Of T)(ByVal xml As String) As T
If String.IsNullOrEmpty(xml) Then
Return CType(Nothing, T)
End If
Dim serializer As New XmlSerializer(GetType(T))
Dim reader As New StringReader(xml)
Dim xmlReader As New XmlTextReader(reader)
Dim item As T = DirectCast(serializer.Deserialize(xmlReader), T)
reader.Close()
Return item
End Function
|
|
|
|
|
One reason for that of course could be that the source of the other XML does not use C# serialization for creation.
|
|
|
|
|
Hi world
i have to draw 2D forms (ellipse, lines, arcs...)in WPF using code.
i don't know from where i should start xD ..........
do you have an idea O_o !!! if yes tell me pleaaaaze, cause i have to finish my application this month.
thanks.
|
|
|
|