|
Hi! Nair,
I can not find the answer by myself in MSDN.
Can you tell me where I can get the answer to this question? or you can tell me the answer directely.
Thank!
Best regards!
momer
|
|
|
|
|
The constructor documentation[^] for the FieldOffsetAttribute clearly states that the offset is in bytes.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi! Stewart,
1,I want to invoke the DeviceIoControl() API in C#,then how to define IOCTL_SCSI_PASS_THROUGH ?
//vc++ code :
DeviceIoControl( hFile, IOCTL_SCSI_PASS_THROUGH, &SPTWB, length,&SPTWB, length, &dwBytesReturned, FALSE );
Should I copy all the definition of those terms which construct the definition of IOCTL_SCSI_PASS_THROUGH form some headfiles to my c# porject? or there is an other way to do the same work?
2,ZeroMemory( &SPTWB, sizeof( SCSI_PASS_THROUGH_WITH_BUFFERS ) );
I can not find the dll file which
contain this funtion.
How to this in c#? Or there is another function to do the same work in C#?
Best Regards!
momer
|
|
|
|
|
You should start by reading about the classes you're plan on using, like the StructLayoutAttribute and FieldOffsetAttribute (which is typically only useful when you need to declare a struct where the native definition uses a union ). You should also read Marshaling Data with Platform Invoke[^] to better understand how data is marshaled as well as type mappings (like that an unmanaged long is a managed int ; both are 32-bits - this is a common mistake that shouldn't be made).
I would define the IOCTL_SCSI_PASS_THROUGH like so:
internal const int IOCTL_SCSI_PASS_THROUGH = 0x4d004; It's a constant - not a struct.
If you want to find P/Invoke signatures for many commonly used Win32 APIs, I suggest you take a look at http://pinvoke.net[^]. It even has the signature for DeviceIoControl[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi!Stewart,
Thank you very much.
Cheers!
momer
|
|
|
|
|
Hi!Stewart,
Thank you very much.
Cheers!
momer
|
|
|
|
|
You'll definitely get stack overflows and corruption with that one. You should read about and understand the data types you're using. A DWORD , for example, is 32 bits while a managed ulong is 64 bits. You would overflow the stack and cause undeterministic problems.
In most cases - as I mentioned in a previous reply to this thread - you only need to use LayoutKind.Explicit for a struct when a union is involved. In this case, however, since you have CPU-dependent types (namely LPVOID and DWORD_PTR , both 32 bits on a 32-bit CPU and 64 bits on a 64-bit CPU), it's better to declare nested structs (not supported on .NET CF currently). You would then use the LayoutKind.Sequential for SYSTEM_INFO and LayoutKind.Explicit for SYSTEM_INFO_Union1 :
[StructLayout(LayoutKind.Sequential)]
internal struct SYSTEM_INFO
{
public SYSTEM_INFO_Union1 union1;
public uint dwPageSize;
public IntPtr lpMinimumApplicationAddress;
public IntPtr lpMaximumApplicationAddress;
public IntPtr dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public uint dwAllocationGranularity;
public ushort wProcessLevel;
public ushort wPRocessRevision;
}
[StructLayout(LayoutKind.Explicit, Size=4)]
internal struct SYSTEM_INFO_Union1
{
[FieldOffset(0)] public uint dwOemId;
[FieldOffset(0)] public ushort wProcessorArchitecture;
[FieldOffset(2)] public ushort wReserved;
} Specifying the StructLayoutAttribute.Size field in the attribute speeds up calculations when marshaling and is a good idea in cases where unions must be used, but it's not necessary (don't do it if you must define reference fields of IntPtr s, which all depend on the size of an address for a particular CPU.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Ok. Say you need to produce the following XML element:
<Product>
<Product#>1265-66ab5-d</Product#>
</Product>
Now suppose you have the following class
public Class Product
{
[System.XML.Serializaton.XMLElement("Product#")]
public string productnum;
......
....
}
Now try serializing product
Produce newProduct = new Product();
newProduct.product = "1265-66ab5-d";
Serializer xs = new Serializer(typeof(product));
....
....
xs.Serialize(somebuffer, product);
The outcome is:
<Product>
<Product_x0023_>1265-66ab5-d</Product_x0023_>
</Product>
In fact using two ## yields _x0023__x0023_ and /# _x002F__x0023_
|
|
|
|
|
And that is what it should do. Not every value is valid within XML, such as the hash sign (#). It is automatically encoding the correct value for you. There is a class within the System.Xml namespace called XmlConvert that also allows you programmatic access (via static methods) to this encoding and decoding process. Here is a quick example.
private void button1_Click(object sender, System.EventArgs e)
{
string val = "Product#";
string encoded = XmlConvert.EncodeName(val);
MessageBox.Show(encoded);
string decoded = XmlConvert.DecodeName(encoded);
MessageBox.Show(decoded);
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
Nick
But I cannot use a variable inside an XML.Serialization Attribute.
that is I cannot do:
public class Product
{
string val = "Product#";
string encoded = XmlConvert.EncodeName(val);
[System.XML.Serialization(enconded)]
public string productnum
......
}
|
|
|
|
|
What I believe Nick is trying to say that "#" is not valid in a Name[^] token for XML, and that the XML classes are encoding the character (it's valid in certain data, but not name tokens) in one particular way. To avoid this encoding, you shouldn't specify it at all (after all, it isn't valid for element or attribute names).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Good day all…
I am interested in adding the fading color (similar to the Windows Media Player version 10) scheme to my Main Menu. Does anyone have an object type or maybe guide to a location where I can complete this solution?
Thanks in advance for your assistance.
Have a great coding day.
Regards,
Tony D. Abel
|
|
|
|
|
Judah has answered your question below in your first post.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi,
I'm looking for a nice/good DataSet designer, where I can do nice layouts of the dataset and of the relations.
Right now my dataset has 33 tables and about 50-60 or so relations.
Ofcourse it looks more than miserable in the VS designer.
Thanks,
Corneliu.
PS>> I _can't_ redesign it, brake it, split it, change it and so on ...
|
|
|
|
|
You wrote:
I'm looking for a nice/good DataSet designer
Please point this sentance once again. What is it mean ?
Sreejith Nair
[ My Articles ]
|
|
|
|
|
"Nice DataSet designer": a designer like the one that opens when you double click an ".xsd" file in the solution explorer, where you can define tables, keys and relations all visually, and then it gets converted using the MSDataSetGenerator to code.
Tutu.
|
|
|
|
|
I would like to know the record number of the record I am referencing in a data set.
If I have a record set created with the following:
CODE:
adptLoan.SelectCommand.CommandText = "SELECT * FROM loan ORDER BY key_loan";
theRows = adptUpdateLoan.Fill(resultset, "GENERIC");
"what is my record number" = resultset.Tables["GENERIC"].Rows[0]["key_loan"].ToString();
I could change key_loan to any key value, but I still want to know what record number this is within the context of my select statement. Obviously, the one above is simplistic.
Any thoughts on this?
Thanks in Advance.
William
William Olson
e-Olsons.com
|
|
|
|
|
I am somewhat new to C#, but have built a couple of working programs.
I am working on a new project, and have a textbox control on my main form called "textBoxNumberSegments". I am building a routine for then TextChange event, with the line :
string text= this.textBoxNumberSegments.text;
The build fails with the following error:
'System.Windows.Forms.Control.text' is inaccessible due to its protection level
I have no idea how to correct this.
ngb
|
|
|
|
|
There must be a private member called text. The one you want is called Text.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
This problem will arise in two cases.
1. Some time we may create a form which is inherited from others.In this case the child form contain all controls of parents but it's accessibility is protected. So what you can do is, selected controls on your child form and change the Modifier property to public or private to that form.
2.If you are trying to access or modify the values of a form control which have the modifier private from other form.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Except he's accessing this.textBoxNumberSequence.text . Christian is right - he must use Text . The fact that he is accessing the control from this indicates that, most likely, it's defined on this 's type and is accessible regardless of it's access modifier. The only case is if the control is inheritted (this is still valid to reference inheritted members).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
If I make an HttpWebRequest, i.e. HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("http://www.google.com");, is there any way I can get the IP of the Uri (in this case google). I've fooled around with the .Address property, and looked around in the MSDN library, but I can't seem to find it. Does anyone know what property I should be using?
Thanks,
Justin
|
|
|
|
|
Ok, I couldn't figure out how to get the IP address from a HttpWebResponse object, so instead I'm using
IPHostEntry hostentry = Dns.Resolve(uri);
IPAddress = hostentry.AddressList[0];
The problem with the above is that it will not resolve a DNS entry for something like "http://www.google.com", but it will resolve an entry for "google.com" or "www.google.com". However, if you try to create a HttpWebRequest object with either of the latter two uri's, they are invalid - only the first one is valid. I only have one "address bar" in my program, so this is a bit of a problem. So, I need to find a way to get the IP, and create a HttpWebRequest given only one uri - any ideas/suggestions?
Thanks,
Justin
|
|
|
|
|
A quick work around will be a way to format the input from the user, in your case, the address, into an appropriate Uri format so your class can be created. I have written up a simple formatting method that will allow you to accept different formats as you stated above (i.e., www.google.com and google.com) and create the appropriate Uri class from it. Try the following:
private Uri FormatUri(string url)
{
Uri uri = null;
if(!url.ToLower().StartsWith("http://"))
{
uri = new Uri("http://" + url);
}
else
uri = new Uri(url);
return uri;
}
So you can use this as follows:
private void button1_Click(object sender, System.EventArgs e)
{
Uri uri = FormatUri(this.textBox1.Text);
MessageBox.Show(uri.AbsoluteUri);
}
HTH
- Nick Parker My Blog | My Articles
|
|
|
|
|
While I find it odd that you don't know what server responded to you when you, in fact, made the request (a la HttpWebRequest ), you must have some valid reason.
This is possible. Pass HttpWebResponse.Server to Dns.Resolve or similar (like Dns.GetHostByName ) and you can get the IP address. If all you wanted was the name, the Server property would return that for you, as it is clearly documented.
The Dns class would not - and should not - return the protocol scheme "http". DNS - or Domain Name Service - only deals with IP<->hostname mapping. A protocol scheme merely indicates to clients what protocol to use to communicate with the server and, more often than note, the default port (HTTP's default port is 80; SMTP's default port is 25; etc.).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|