|
Hi Luc,
Sorry to reply to an old message - I didn't want to email you directly and your email link is missing in CP pages.
If you have a moment would you take a look at a question I posted yesterday here[^]? I know you're far more competent with this P/Invoke stuff than me and I'd value your opinion!
Cheers,
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi Davey69!According to MSDN documetation lpData type is LPSTR which specifies a pointer to an array of 8-bit characters maybe terminated by null character.According to me it's equal to System.Byte type-it's a pointer to byte array.But you said it's array of MIDIEVENT structs.It's strange.When you need to marshal constant size array within a struct just marchal it as an managed array,but when it's size is variable use IntPtr as you have done.
Life is a stage and we are all actors!
|
|
|
|
|
Yeah, you're right. A char is a byte so a char[] is a byte[] - in the c++ world anyway (unfortunately not in C#)!
The MIDIEVENT structures are word aligned, so it's treated as a byte array internally by Windows. Passing a pointer to a byte array works fine, but using the defined MIDIEVENT structures makes assigning the various elements of that structure much easier.
Got the problem fixed now anyway, but thanks for your input.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
DaveyM69 wrote: Passing a pointer to a byte array works fine, but using the defined MIDIEVENT structures makes assigning the various elements of that structure much easier.
DaveyM69 wrote: A char is a byte so a char[] is a byte[] - in the c++ world anyway
In fact ANSI C char range is from -127 to 127 and BYTE is equal to unsigned char ,so that they aren't equal.
That's why BYTE is equal to System.Byte always.
But I like your approach -just give the API to do annoying initialization work.It's more efficient rather than doing using custom logic in .NET.
Life is a stage and we are all actors!
modified on Friday, August 14, 2009 7:01 PM
|
|
|
|
|
Hi,
Am reading an excel file containing columns and storing it into the database. The excel sheet contains a column called STATUS which includes (NOT STARTED , IN-PROGRESS , COMPLETE) several rows have different statuses. Everytime the excel sheet is read the values are stored into the table in the db.
Now in the latest excel sheet some of the rows have a changed status i.e a row which had STATUS as "NOT-STARTED" in the previous excel sheet, will now have status as "IN-PROGRESS". How do I compare this with the actual data in the database table and update that particular row with the new STATUS using LINQ.
Help appreciated,,,
|
|
|
|
|
Please don't cross post. It's against the role.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
got u ..... i dint know which forum to post it in...so posted in both........
|
|
|
|
|
Well, you kind of gave it away in your post title - it's a LINQ issue.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I’m still fairly new with this stuff and was writing an application that will get some computer and bios info from computers on our network using WMI. I’ve got things working so that I’m getting the information that I want, however, I would like to add some error handling in case the property I’m searching for doesn’t exist. Currently the program just stops if it can’t find the property/value.
Would it be best to use a try catch? If so would I need to write it in for every property value?
Thanks
-Rob
ManagementScope scope = new ManagementScope("\\\\" + target + "\\root\\cimv2");
ManagementPath pathBios = new ManagementPath("Win32_Bios");
ManagementPath pathSystem = new ManagementPath("Win32_ComputerSystem");
ObjectGetOptions obj = new ObjectGetOptions(null);
ManagementClass wmiBios = new ManagementClass(scope, pathBios, obj);
ManagementClass wmiSystem = new ManagementClass(scope, pathSystem, obj);
foreach (ManagementObject bios in wmiBios.GetInstances())
{
queueStack.Enqueue("Manufacturer: " + bios.Properties["Manufacturer"].Value.ToString().Trim());
queueStack.Enqueue("rev: " + bios.Properties["smbiosbiosversion"].Value.ToString().Trim());
queueStack.Enqueue("SN: " + bios.Properties["Serialnumber"].Value.ToString().Trim());
queueStack.Enqueue("Status: " + bios.Properties["Status"].Value.ToString().Trim());
}
I've added a try/catch for each wmi value being returned
modified on Monday, August 17, 2009 3:11 PM
|
|
|
|
|
eeffoc42 wrote: Would it be best to use a try catch?
That is one way and the best way. There coud be error hundling as returning result, but throwing expection has its own uses. If You don't have unhandled expection the program will have a poped up a form or send it to debbuger if attached.
eeffoc42 wrote: If so would I need to write it in for every property value?
That is up to you and based on a case. If property has some limits like value is too low then yes.
I do not know what Expection is thrown, here is some examples:
<br />
try<br />
{<br />
XmlReaderSettings xrs = new XmlReaderSettings();<br />
xrs.IgnoreWhitespace = true;<br />
xrs.IgnoreComments = true;<br />
String nonExsistingFile = "C:\Haha.txt";<br />
<br />
XmlReader reader = XmlReader.Create(nonExsistingFile , xrs);<br />
<br />
}<br />
catch (FileNotFoundException ex)<br />
{<br />
}<br />
If you have your own class, and if it doesn't throw exception, those try catch woudn't have any effect.
If you are looking custom Exception look here:
http://blog.gurock.com/articles/creating-custom-exceptions-in-dotnet/[^]
|
|
|
|
|
Hi,
it is often wise to add a try-catch construct, provided you do something with what you catch; an empty catch block is mostly unacceptable, since that just would ignore and swallow the problem.
Suggestion: when showing an exception, always use Exception.ToString() to get all of it.
You would need as many try-catch constructs as you want your error handling to be granular; if your code normally runs fine, put it all in one try-catch; if you want your foreach loop to continue with the next object, then you need to put the try-catch inside the foreach.
Often it is better to avoid an exception all together; example:
PropertyData pd=bios.Properties["Manufacturer"];
if (pd!=null) queueStack.Enqueue("Manufacturer: "+pd.Value.ToString().Trim());
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
eeffoc42 wrote: ManagementScope scope = new ManagementScope("\\\\" + target + "\\root\\cimv2")
ManagementScope class usually is combined with ConnectionOptions class in order to allow you to prompt account security credentials for the remote computer connect or/and to configurate COM impersonation level used for remote connection operations. For error handling you could just use singe try/catch block.
Life is a stage and we are all actors!
modified on Friday, August 14, 2009 4:27 PM
|
|
|
|
|
My current block in the road is figuring out how to compare files through sockets. I know its possible just not sure how. Would I use TCP/IP? I'm lost
|
|
|
|
|
|
well both methods would work I guess, but which would be more effiecnt?
|
|
|
|
|
If you chose to send entire file, you coud also compare what was changed. But if you wan't to know only if it is changed, sending hash woud be enough
|
|
|
|
|
Is it possible to specify a web service entirely via the app.config file? What I'm trying to avoid is statically adding a web service reference to a desktop app.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
You can change the URL of the web service via configuration files. The only way I can think of to use a web service with out the autogenerated code is to just call it yourself and parse the XML into your own objects but really overkill.
|
|
|
|
|
I dug up a solution where the desktop app goes and searches a server for a WINDOWS service and registers it. You still need the proxy class but changing servers was easy. The link is in the office and I can send it on Monday if you think it will be useful.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
i want to show time country wise in c#.net
i am building an web application.i want to display it in a scrolldelay kind of thing,wherein the time of each country is displayes for lets say after every 30 secs.
example is here :http://www.advance-international.com
in the example u can see the time ,weather of particular cities
i want to do something like it
pls help
|
|
|
|
|
This section is for C# Applications. not for Web app.
I think you are using ASP.NET that uses same sytax.
I Suggest look into ayax
|
|
|
|
|
I can't tell you how to display the time zones, but to get them and get their time, look at the TimeZoneInfo class. It's got a method to get every time zone, and another method called ConvertTime. Both of those should be useful
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
string versus String !
I have a question (a little embarrassing because I see it so late), what is the difference between String and string ? not in the way that String is a Class and string is a reference type. But rather how to think about them in the term of uses.
I searched and find this piece of gold, but I don't know how to use it very well:
Use "String" to refer specifically to the String class.
Use "string" when referring to an object of the String class.
How to use them, accordingly?
thanks again.
|
|
|
|
|
String == string. They're aliases of the same class, just like ulong is an alias of UInt64
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
They are the same.
If you want to use reference try like this:
String someString = "";
DoSomething(ref someString);
Function:
private void DoSomething(ref String str)
{
str = "Was Empty";
}
|
|
|
|