|
That would most likely be a complete was of time. For one, VS.NET is merely a client for the .NET Framework, which is a separate component. It implements and uses code to facilitate designers and invokes the compilers to compile managed code, but nothing more (regarding the .NET Framework).
The .NET Framework - especially Windows Forms - P/Invokes and uses COM interop with native Windows APIs.
More than likely, something changed on your system. Did you install any new patches or service packs? Did you change any code - no matter how "unrelated" you think it is? Have you made sure that you're disposing any modal dialogs or other resources (like any Graphics or Bitmap instances you create)? In most cases the fault is with the code. Just re-installing the .NET Framework will almost never solve the problems. You need to first look at your code.
So be more specific about your problems and what exceptions - if any - you're betting. Give us stack traces and other details regarding your problem, but don't just go reinstalling everything. Not only is that a bad way to resolve issues (not knowing what the problem is - no matter if the fix works or not - will most likely lead to the problem happening again), but it most likely won't resolve your issue.
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 guys
Does anyone know of any articles/tutorials on ANY web site that can paste files that have been copied to clipboard by Windows Explorer? Specifically I need to know how to cast the "Preferred DropEffect" clipboard format to DragDropEffect enumeration in C#. I can do this in C++, but how do I cast them in C#? Also, do I need to cast from an STGMEDIUM structure, then get the hGlobal to the DropEffect DWORD, or does Clipboard automatically do this in .net for casting from DataObjects?
Any pointers would be greatly appreciated
Thanks guys
|
|
|
|
|
This has been covered before in this forum. In the future, try searching first. You can search these forums by clicking the "Search comments" link above.
You don't need to worry about the STGMEDIUM . Basic drag and drop support is supported by .NET, and even in the COM world you don't simply cast an IDataObject (which, BTW, is a completely different interface from .NET's IDataObject ).
In both implementations, however, you do the same: you request a specific clipboard format that you support (optionally supporting multiple clipboard formats that you reference in order of preference till the data is dropped/pasted).
File names - which use the TYMED_FILE clipboard format - are easy to retrieve. Just look at the following example (assume the handler is hooked up to a DragDrop event for some control):
private void myControl_DragDrop(object sender, DragEventArgs e)
{
if ((e.AllowedEffect & DragDropEffects.Copy) != 0 &&
e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string filename in filenames)
listView1.Items.Add(filename);
}
} You should read the DataFormats class documentation and the DragDrop event documentation for more information.
Only in some cases - like handling data from a stream or structure storage document do you really need to interop with the native COM drag and drop/clipboard APIs, and I've carried on long discussions about this that you can search for and read if you're interested.
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]
|
|
|
|
|
class ball
{
int x;
ball()
{ x=Random().Next(10);
}
}
I then create 10 ball, the problem is all balls have the same X. How do I solve this? Thanks
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
try creating a new random object into the class and giveing it a new seed (that could be time dependent)
<br />
class ball<br />
{<br />
int x;<br />
Random r;<br />
ball(seed)<br />
{ <br />
r=new Random(seed);<br />
x=r.Next(10);<br />
}<br />
<br />
}<br />
<\code> <br />
<br />
I hope you understand...<br />
By the way... visit <a href="http://nehe.gamedev.net">http:
|
|
|
|
|
Try to re-use the same Random:
class ball
{
int x;
Random random = new Random();
ball()
{
x=random.Next(10);
}
}
|
|
|
|
|
Corinna John wrote:
class ball
{
int x;
Random random = new Random();
ball()
{
x=random.Next(10);
}
}
The above is still creating a new Random for each new instance of ball. To reuse one Random it would need to be static, possibly:
class ball
{
int x;
private static Random random = new Random();
ball()
{
x=random.Next(10);
}
}
|
|
|
|
|
Hi all,
I have a windows form application which is a MDI. It has a basic editing toolbar (add,edit,delete buttons). I want to enable the toolbar buttons if a MDI child is active. Disable them when no MDI child is active. How can I do this?
|
|
|
|
|
This is a matter of logic. See here i have a tool bar with few toolbar buttons.I will nable or disable toolbar buttons based on users selection.
Eg:
private void PBToolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
try
{
switch(PBToolBar.Buttons.IndexOf(e.Button))
{
case 0:
{
formA PBAUS = new formA();
PBAUS.Show();
}break;
case 1:
{
toolBarButton10.Enabled=false;
LoadPlan();
}break;
case 2:
{
MessageBox.Show(e.Button.ToolTipText.ToString());
}break;
case 3:
{
save();
toolBarButton10.Enabled=true;
menuItem11.Enabled=true;
}break;
continue.......................
Here what i am doing is , i am getting the index of toolbar button that user clicked.And based on this values i will enable or disable toolbar buttons.
See the logic above and try to figurout your self to achive your goals.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
[C#]
[StructLayout(LayoutKind.Explicit)]
public class SYSTEM_INFO
{
[FieldOffset(0)] public ulong OemId;
[FieldOffset(4)] public ulong PageSize;
[FieldOffset(16)] public ulong ActiveProcessorMask;
[FieldOffset(20)] public ulong NumberOfProcessors;
[FieldOffset(24)] public ulong ProcessorType;
}
In C#,ulong type data has 8 bytes capacity.
How many bytes between field OemId and field PageSize?
Thanks!
momer
|
|
|
|
|
|
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 ...
|
|
|
|