|
Hi,
how can i pass data from byte[] variable into struct. In C/C++ I use memmove. But isnt something like this...
Thank
Wiizi
|
|
|
|
|
Try something like:
using System.Runtime.InteropServices;
...
public static object ByteArrayToStructure(byte[] buffer, int index, Type tStructure)
{
if (null == buffer || 0 == buffer.Length)
throw new ArgumentNullException("buffer");
if (0 > index || buffer.Length <= index)
throw new ArgumentOutOfRangeException("index");
if (null == tStructure)
throw new ArgumentNullException("tStructure");
int size = Marshal.SizeOf(tStructure);
if (index + buffer.Length < size)
throw new ArgumentException("Insufficient data passed", "buffer");
IntPtr pStructure = Marshal.AllocHGlobal(size);
try
{
Marshal.Copy(buffer, index, pStructure, size);
return Marshal.PtrToStructure(pStructure, tStructure);
}
finally
{
Marshal.FreeHGlobal(pStructure);
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Hey All,
Im doing a simple GUI prototype, and Im using alot of data screen shots from the old application to represent data in the new prototype. Following that thinking I have alot of forms what simply contain picture controls, and I set these bitmaps of the old app to those picture or image control, whatever the new one is called. Anyways, when I set the sizemode property to stretch, the image control doesnt stretch the picture. Any ideas?
Thanks,
Ryan
|
|
|
|
|
Ryan@SalamanderTechnologies wrote:
Anyways, when I set the sizemode property to stretch, the image control doesnt stretch the picture. Any ideas?
I think those names are confusing, try the autosize one.
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
|
Look at the WebClient class in the System.Net namespace.
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
Thanks for the info leppie.
I was looking for something that I could possibly tie into some sort of progress control to show the progress of the download [URLDownloadToFile uses a Callback]. Any ideas?
Regards,
Brian Dela
|
|
|
|
|
Use URLDownloadToFile. Seriously though, I don't think there's any way to do that with the WebClient class.
Hawaian shirts and shorts work too in Summer.
People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage...
-Anna-Jayne Metcalfe on Paintballing
|
|
|
|
|
David Stone wrote:
Use URLDownloadToFile.
I could.. I'm just wondering if there is a method in the BCL to do it.
Regards,
Brian Dela
|
|
|
|
|
U cant use the HttpWebRequest class then, a bit more work, but all .NET
<a TITLE="See my user info" href=http:
|
|
|
|
|
Please tell me how to get all the content of a web page by using this AxSHDocVw.AxWebBrowser!Thax.
|
|
|
|
|
Hi,
I'm writing a .NET Data Provider in C# and I want to create an application that will test all of the objects thoroughly. Can I use reflection for this? What I would like to do is have the test app walk through each object testing all of the properties and methods to make sure that everything is as expected. For instance, I want it to set the ConnectionString property and then read it back to make sure it was stored correctly.
Am I trying to make things too complicated? The Data Provider is relatively simple, so is writing a generic object walker overkill? Any thoughts would be appreciated.
Josh
Find a penny, pick it up, and all day long you'll have a back-ache...
|
|
|
|
|
Have a look at NUnit on sourceforge. nunit.sourceforge.net[^] I think.
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
Or www.nunit.org I know that one is correct.
nUnit rocks for writing test cases.
|
|
|
|
|
I'm writing an MMC snapin using C#. So far I've got most things working and I've moved onto persistance. I need to implement the IPersistStream interface. I've defined the IPersistStream, IPersist and IStream interface in my C# code plus all the structure etc required as parameters. However when MMC or my C++ test harness calls the GetSizeMax method which has an out parameter of type ULARGE_INTEGER (which is a structure wrapping a ulong) I get an access violation. Am I doing anything wrong? I'm quite experienced with COM and C++ but marshalling between managed and unmanaged code is all quite new to me. Can anyone help?
|
|
|
|
|
solidstore wrote:
ULARGE_INTEGER (which is a structure wrapping a ulong) I get an access violation.
ulong is 4 bytes AFAIK. so use a UInt32 Dont get confused with C's long type.
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
Please find below my definitions. When stepping into some of these
interfaces from C++ client the code either works, crashes or steps into the
wrong functions. Any ideas?
<br />
[<br />
StructLayout(LayoutKind.Sequential)<br />
]<br />
public struct _GUID<br />
{<br />
public uint x;<br />
public ushort s1;<br />
public ushort s2;<br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]<br />
public byte[] c;<br />
}<br />
<br />
[<br />
StructLayout(LayoutKind.Sequential)<br />
]<br />
public struct _FILETIME<br />
{<br />
public uint dwLowDateTime;<br />
public uint dwHighDateTime;<br />
}<br />
<br />
[<br />
StructLayout(LayoutKind.Sequential)<br />
]<br />
public struct tagSTATSTG<br />
{<br />
[MarshalAs(UnmanagedType.LPWStr)]<br />
public string pwcsName;<br />
public uint type;<br />
public _ULARGE_INTEGER cbSize;<br />
public _FILETIME mtime;<br />
public _FILETIME ctime;<br />
public _FILETIME atime;<br />
public uint grfMode;<br />
public uint grfLocksSupported;<br />
public _GUID clsid;<br />
public uint grfStateBits;<br />
public uint reserved;<br />
}<br />
<br />
[<br />
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),<br />
Guid("0c733a30-2a1c-11ce-ade5-00aa0044773d")<br />
]<br />
public interface ISequentialStream<br />
{<br />
void Read(out byte pv, uint cb, out uint pcbRead);<br />
<br />
void Write(out byte pv, uint cb, out uint pcbWritten);<br />
}<br />
<br />
[<br />
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),<br />
Guid("0000000C-0000-0000-C000-000000000046")<br />
]<br />
public interface IStream : ISequentialStream<br />
{<br />
void Seek(_LARGE_INTEGER dlibMove, uint dwOrigin, out _ULARGE_INTEGER<br />
plibNewPosition);<br />
<br />
void SetSize(_ULARGE_INTEGER libNewSize);<br />
<br />
void CopyTo(IStream pstm, _ULARGE_INTEGER cb, out _ULARGE_INTEGER pcbRead,<br />
out _ULARGE_INTEGER pcbWritten);<br />
<br />
void Commit(uint grfCommitFlags);<br />
<br />
void Revert();<br />
<br />
void LockRegion(_ULARGE_INTEGER libOffset, _ULARGE_INTEGER cb, uint<br />
dwLockType);<br />
<br />
void UnlockRegion(_ULARGE_INTEGER libOffset, _ULARGE_INTEGER cb, uint<br />
dwLockType);<br />
<br />
void Stat(out tagSTATSTG pstatstg, uint grfStatFlag);<br />
<br />
void Clone(out IStream ppstm);<br />
}<br />
<br />
[<br />
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),<br />
Guid("0000010C-0000-0000-C000-000000000046")<br />
]<br />
public interface IPersist<br />
{<br />
void GetClassID(out _GUID a);<br />
}<br />
<br />
[<br />
StructLayout(LayoutKind.Sequential)<br />
]<br />
public struct _ULARGE_INTEGER<br />
{<br />
public ulong QuadPart;<br />
}<br />
<br />
[<br />
StructLayout(LayoutKind.Sequential)<br />
]<br />
public struct _LARGE_INTEGER<br />
{<br />
public long QuadPart;<br />
}<br />
<br />
[<br />
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),<br />
Guid("00000109-0000-0000-C000-000000000046")<br />
]<br />
public interface IPersistStream : IPersist<br />
{<br />
[PreserveSig()]<br />
int IsDirty();<br />
<br />
void Load(IStream Stm);<br />
<br />
void Save(IStream Stm, int ClearDirty);<br />
<br />
void GetSizeMax(out _ULARGE_INTEGER Size);<br />
}<br />
<br />
[<br />
ProgId("ICRMMC.IcrSnapin"),<br />
Guid("43C8177A-2392-419F-9156-34D24FE22319"),<br />
ClassInterface(ClassInterfaceType.None)<br />
]<br />
public class IcrSnapin : IPersistStream<br />
{<br />
public IcrSnapin()<br />
{<br />
}<br />
<br />
public void GetClassID(out _GUID a)<br />
{<br />
a.x = 0x43C8177A;<br />
a.s1 = 0x2392;<br />
a.s2 = 0x419F;<br />
a.c = new Byte [] {0x91, 0x56, 0x34, 0xD2, 0x4F, 0xE2, 0x23, 0x19};<br />
}<br />
<br />
public int IsDirty()<br />
{<br />
return 1;<br />
}<br />
<br />
public void Load(IStream Stm)<br />
{<br />
}<br />
<br />
public void Save(IStream Stm, int ClearDirty)<br />
{<br />
}<br />
<br />
public void GetSizeMax(out _ULARGE_INTEGER Size)<br />
{<br />
Size.QuadPart = 1234;<br />
}<br />
<br />
}<br />
|
|
|
|
|
I want to paste from my app into Notepad.
I am doing a straightforward
Clipboard.SetDataObject(stringValue, true)
and then when I look into Notepad, paste is disabled (as is copy/cut). I can cut and paste to and from other apps with notepad, no problem. What am I missing?
Sincerely,
Lindsay
|
|
|
|
|
The stringValue wasn't. So, since I'd not done anything with setting a DataProvider, I'm assuming that if the object type is not "well known", then you get nothing.
Sincerely,
Lindsay
|
|
|
|
|
Hi, is there a way to have a server run button jump to an anchor in the page?
Im having trouble getting request.redirect(...) to work, because just adding currenturl+#myanchorname doesnt seem to work. I dont want to use a link, becuase i want them to enter text in a box and then do a search, where it jumps to the anchor based on the text in the box.
if anyone has dont this before it be alot of help
thanks
steve
|
|
|
|
|
in c++ when i would serialize an object i would always put a version as the second string serialized.. then when i deserialized i would read that version and read in the rest of the data based on what version the file was, in case variables had been added/removed between that version and the current version.
how does C# handle this? it seems like it serializes and deserializes in its own way.. how do i handle multiple versions of an object when serializing?
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
dazinith wrote:
how does C# handle this?
Very poorly IMHO.
If the structure/class has changed between versions then you will get an exception thrown when it tries to deserialize the object.
There is currently a problem if you serialized a Hashtable in version 1.0 of the framework and try to deserialize that Hashtable in version 1.1. The cause is that MS added a new member to the Hashtable in the new version.
I do not know what would happen if you implement ISerializable to do as you mentioned (storing a Version object and have your deserialization code from ISerializable use that Version object to read back the correct data). Perhaps this would make a good article
dazinith wrote:
still a newb.. cut me some slack
We all were at one time or another
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
I have an mdi application where the parent window is split into two areas (left and right side). The left side is the navigation area and is part of the parent window. Every time a user clicks on one of the link labels on the left a new window appears on the right. But I can not get the child form to maximize to the designated work area. Does any one have any ideas on how to do this? Many thanks.
|
|
|
|
|
can we make a label or linkLabel Transparent? like we do with the forms?
sorry for my bad English.
|
|
|
|
|
You english is fine.
Maybe you can set the background color to transparent, or opacity percentage. I'm not sure....but that may be something to check.
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|