|
Nahh i'm too lazy and my email is still broken.... anyways internal protected does enuf for me
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
I need to send a file between a server and client machine, and although I assume I will need to use serialization I do not seem to be getting very far has anyone attempted this before?
|
|
|
|
|
Is it on the same network? Can't you use an UNC path and CopyFile?
|
|
|
|
|
No I need to send the whole file across the internet so it is not on a private network.
|
|
|
|
|
Hi I was wondering if anyone knew the best way of simply retrieving the IP address of the current computer? I have tried the System.Net namespace but found nothing useful.
|
|
|
|
|
Just use 127.0.0.1
It's actually a pretty tricky question. Networks come in all sorts of configurations, and you might even have more than one network card.
Something like the ipconfig program can give you your IP address, but that's not necessarily your IP to the outside world.
If you're using NAT, you'll have an IP that's in the private range (192.168... or 10... for instance). This won't be your IP address to the outside world, instead your NAT will actually be using this.
I'm not sure where the best place is to find all this stuff, but I think I'd start sniffing around WMI to see if it's any help.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
IPHostEntry hostInfo = Dns.GetHostByName(hostName);<br />
IPAddress[] address = hostInfo.AddressList;<br />
The address array will contains all the IP adresses of your computer.
|
|
|
|
|
I have a C# app with 4 forms with "TopMost = True"
When I perform a task Switch to another app,(using <alt> <tab>), these 4 forms remain on top of the application I switch to.
How can I either hide them and bring them back when I switch back to this app, or allow the other application to fall on top of these 4 forms?
Thank you in advance for any help!!
Ray Sotkiewicz
C# infant
|
|
|
|
|
Form.TopMost makes the Form a system modal window. It's supposed to be ontop of all other windows. If you only want it to be a top-level form for your application, then either set the Owner property of the child forms to the main form of your application, or call AddOwnedForm on the main form, passing the child forms as parameters. See the documentation for the Owner property and AddOwnedForm method in the Form documentation in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How do I put a string into a xml file in a windows application, in a window form? I use a DataReader and not a dataset.
the code looks like this:
I have a XmlDocument myXml
............
string sqlString=" SELECT NumeMat,NumeCD,durata, nrstud "+
" FROM materii AS m, corpdidactic AS cd, activitate as a"+
" WHERE m.IDMat = a.IDMat AND cd.IDCD = a.IDCD"
+
" ORDER BY IDAct";
SqlCommand sqlCmd=new SqlCommand(sqlString, sqlConn);
SqlDataReader sqlDr=sqlCmd.ExecuteReader();
string result=
""+
"<activitati>";
string pageContent="";
while(sqlDr.Read())
{
string activ= "<activitate>\n"+
" <numemat>"+sqlDr["NumeMat"].ToString()+"\n"+
" <numecd>"+sqlDr["NumeCD"].ToString()+"\n"+
" <durata>"+sqlDr["durata"].ToString()+"\n"+
" <nrstud>"+sqlDr["nrstud"].ToString()+"\n"+
"\n";
pageContent=pageContent+activ;
result=result+pageContent;
}
sqlDr.Close();
result=result+"\n";
how can I put "result" in myXml.xml???
When I was working to a project in ASP, I used DocumentContent property....
|
|
|
|
|
You've already got your string (although your multiple concatenations are horribly inefficient - take a look at the StringBuilder instead), you just have to write it to a file. The easiest way is to just use a StreamWriter with a new file and use Write . See the classes in the System.IO namespace for additional options. This is just a simple I/O scenario.
Note, using an XmlTextWriter would really only be useful if you used WriteRaw . You've already got your XML in a string, so there's no reason to parse that and create the elements and attributes. Just use a basic TextWriter (or rather a derivative class).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey
Is there anyone that knows of a simple way to change color on the background of an object in the listbox?
I know how to changes the color of the Text, but not the bakground.
//Jimmy
PS Im not to god on this control Manupulations so explain well =)
|
|
|
|
|
ListBox.BackColor perhaps?
If you want to control the background color of a particular item, you'll have to use owner drawing by setting DrawMode to something besides DrawMode.Normal and handling the DrawItem event, or overriding the OnDrawItem method in a derived class.
There's many examples of this on CodeProject. Just search for "ListBox" or something.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes i found how to do that, lookt throw the difrent methods in grafic and found that i could just bound to fill the item with color.
Thanks alot for helping =)
//Jimmy
|
|
|
|
|
So call FillRectangle first, then call DrawString . Always worked for me.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Can someone explain to me how interfaces are such a big help in creating objects? I was under the impression that an Interface was a template for an Object, just sort of a class with only method signatures
inside them, not actual code inside the methods. But from seeing code and hearing bits and pieces from individuals, they are more than that.
Please enlighten me oh coding gods and gurus.
Thanks,
JJ
|
|
|
|
|
Interfaces are contracts. They define methods, properties, and events that a class must implement in order for callers to use certain features. Classes can only extend one class in .NET, but structs and classes can implement as many interfaces as you want.
Take IList for example. Since it inherits form ICollection and IEnumerable , this means that any class that implements IList is enumerable and has methods and properties that let you add, remove, and index items, as well as clear them. This fosters a good OO design because a caller doesn't have to know the exact Type of an object to use its methods.
For instance, the DataGrid.DataSource accepts an Object . Internally, it checks if this object supports IList or IListSource . It doesn't care if it is a DataSet , an array, or any collection. Just that it supports one of those two interfaces.
This is very handy for creating abstract implementations like plug-ins. You don't need to know a specific Type at design-time or run-time, just that it suports a particular interface. Lets say an application that can uses plug-ins reads a list of Types from the configuration file and defines an interface like so:
public interface IPlugin
{
void Initialize(Control parent);
string Caption { get; }
} Then when the applications get each type, it can do something like this:
IPlugin plugin = (IPlugin)Activator.CreateInstance("some type");
plugin.Initialize(this); It doesn't need to know the Type, just that the Type implements the interface (you should catch exceptions though, in case the cast fails).
For more information about plug-ins, which are a good example of interfaces, try searching[^] CodeProject.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath,
I found out where my confusion is. See I had noticed in code the follwoing:
public class MyClass: System.windows.form{
}
and I thought what is on the right of the colon was an interface
System.windows.form and was wondering how it could benefit MyClass if it
was an interface but has no defined methods in it. But I was mistaken its a base class that has methods and properties to use from it.
JJ
|
|
|
|
|
Hi all,
I would like to implement this interface for my C# Class,The IDropTarget interface has been created, as shown below.
[ComImport,
Guid("00000122-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown) ]
public interface IDropTarget
{
[PreserveSig()]
int DragEnter(IDataObject pDataObj, uint grfKeyState, object pt, ref uint pdwEffect);
[PreserveSig()]
int DragOver(uint grfKeyState, object pt, ref uint pdwEffect);
[PreserveSig()]
int DragLeave();
[PreserveSig()]
int Drop(IDataObject pDataObj, uint grfKeyState, object pt, ref uint pdwEffect);}
Compiles without any problem.
However when I try to register:
[DllImport("ole32.dll")]
static extern int RegisterDragDrop(IntPtr hwnd, ref IDropTarget DropTarget); gives an error saying Expected (ret code is highlighted as error) Expected class ,Delegate ,enum,Interface or struct.
However, changing the int enum gives the same Error.
The function is actually defined as
WINOLEAPI RegisterDragDrop(
HWND hwnd, //Handle to a window that can accept drops
IDropTarget * pDropTarget
//Pointer to object that is to be target of drop);
WINOLEAPI on further examination turns out to be HRESULT with 3 values 0,1,2
What am I doing wrong ?
Could any one please help ? thanks in advance.
Thanks
Ven
|
|
|
|
|
For one, you don't need to ref the IDropTarget in RegisterDragDrop - it's already a reference Type so passing an instantiated instance. This could be one of the problems.
Second, in your IDropTarget , are you using the IDataObject defined in the .NET base class library, or an interop'd one that you'd have to define like you are with IDropTarget . Though the OLE interfaces are used internally by .NET, the IDropTarget interfaces are vastly different.
As far as the error, returning int should be no problem. An HRESULT is a 32-bit signed integer. Preserving the signatures of all the IDropTarget methods isn't necessary, either. This really is only helpful if you need to return a success code that isn't S_OK (0). Even in this case, though, you can always throw a COMException with the error code (or success code), which is the correct way (at least for errors). This can provide additional information to the caller if they support IErrorInfo . This behavior is provided in part by the CLR.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath,
1.I have started without ref in the IDropTarget didnot help.
2.Have defined the IdataObject locally in the file as [ComImport(),ComInterface]
3.My actual problem is compilation error at static extern int<- RegisterDragDrop
changing the retcode to void,enum etc is not changing the error.
Even DllImport("ole32.dll",PreserveSig=false"} still gives the same error at
the same place.
hope i have explained the problem. Appreciate your help anyway. thanks again
|
|
|
|
|
Regardless of whether or not the ref was a problem, it still shouldn't be there. Now, if this was a pointer to a pointer (i.e., IDropTarget **), then you should use ref . A pointer to a value type (i.e., numeric, boolean, byte, char, struct, enum) would require ref or out .
As far as the error goes, let me introduce you to ildasm.exe - the IL disassembler that comes with the .NET Framework SDK. As I mentioned before - and which should be evident since .NET supports drag-n-drop with native Windows - .NET uses the OLE drag-n-drop internally. Logically, you should think to look into the assembly that would use it (just trying to introduce a thought process here). Logically, this is in the System.Windows.Forms.dll assembly.
So, run ildasm.exe and open that assembly (or use something like .NET Reflector). Find the UnsafeNativeMethods class (typical name in base class libraries). There'll you'll find the defnition used by Microsoft (which obviously works). you'll also find reference to IOleDropTarget , which is what they use internally for IDropTarget (the name doesn't matter - only the IID and methods / dispids depending on inheritence). If ever you have problems determining how something should be defined, changes are that the base class libraries are using them internally somewhere.
The method should be defined as:
[DllImport("ole32.dll", CallingConvention=CallingConvention.Winapi)]
static extern int RegisterDragDrop(HandleRef hWnd, IOleDropTarget target); See nested interfaces for definitions of the interfaces, too. They use "Ole" in the interface name and prefix the method names with it (to help distinguish it from implementations), but it doesn't matter so long as the vtable order for IUnknown-inherited interfaces and DISPIDs for IDispatch-inherited interfaces remain the same (for dual interfaces, both order and DISPIDs should be the same).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath.
You have been helpful, I would follow your advice. Thanks again..
|
|
|
|
|
Hi, I am trying to use ILAsm and ILDasm inside an application and I need to be able to run the programs and intercept any errors and/or output that they create. Are there FxCL classes to do this or is there another way? (I'm using C#). I searched around on the articles on the site but couldn't find anything relating to this. Maybe I just don't have the right keywords. Any links or advice would be great. Thanks.
-Noah Fields
|
|
|
|
|
Take a look at the System.Diagnostics namespace, especially the Process and ProcessStartInfo classes.
Searching for those two classes on the net should lead you to lots of examples on how to start applications and redirect their output to yourself.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|