|
Thanks I figured it out (@"\bla\bla\bla");
|
|
|
|
|
Either escape them using "\" (so "\\") or use the literal string identifier "@" before the string, like "@C:\Program Files...". Looking at the documentation for the compiler error would've told you that.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello gurus,
I would like to know how can I retrieve the IPv6 address of the current computer in C#? IPv6 is activated under Windows Server 2003 and I activated it under Windows XP.
In my application, I would like to use IPv6 instead of IPv4. Is it an advantage that new application are ready for IPv6?
Thanks for your help.
Best regards.
There is no spoon.
|
|
|
|
|
What happens when you run this?
<br />
using System.Net;<br />
<br />
<br />
IPHostEntry hostEntry = Dns.GetHostByName(Dns.GetHostName());<br />
IPAddress[] addresses = hostEntry.AddressList;<br />
for(int x = 0; x < addresses.Length; x++) {<br />
Console.WriteLine(addresses[x]);<br />
}<br />
Regards,
Jeff Varszegi
EEEP! An Extensible Expression Evaluation Package
|
|
|
|
|
I have the following:
"::1 192.168.0.110 192.168.204.1 192.168.74.1"
which does not seem to be an IPv6 address.
There is no spoon.
|
|
|
|
|
::1 (with scope ID 0) is the local hosts's IPv6 address.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath!
I'm working on the multi-player mode of my game. I want to use IPv6.
::1 is the scope. okay. but how can I get the physical address of the host? like for IPv4? I have IPv6 enabled on .NET 1.1.
According to Gary Brewer's article (http://www.codeproject.com/csharp/ipv6.asp) an IPv6 address looks like this:
"xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx"
his article shows how to use IPv6 wiht .NET 1.1 sockets but it does not shows how to handle addresses.
When I do ipconfig /all with IPv6 activated, I can read my IPv6 address. I would like to do display the IPv6 address of the host.
Thanks for the help.
There is no spoon.
|
|
|
|
|
Man, you really should learn about IPv6 addresses before you start digging into them. ::1 is the interface address. 0 would be the scope. Try running my little sample code on your machine.
Also, "::" in an IPv6 address masks out consecutive zeros, so it doesn't always include 8 32-bit integers.
The point is, you don't need to worry about all this. Use something like I did in my sample app and just use one of the interfaces returned in the IPHostEntry.AddressList property. It doesn't matter which one you use, they will all work. If all it returns is IPv6 (which won't be happening for several years at least), then you'd connect to that one. The .NET classes you'd be using really don't care which you use in many cases.
The ability of an app to use IPv6 is just the ability to recognize and connect using IPv6 addresses, but it doesn't mean that an app must use it. Use whatever address is return, whether it's the 1st address in the list or the last. It doesn't really matter.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
First, you must make sure you compile against (or run against, although you won't be able to (easily) support IPv6 in the latter case) the .NET Framework v1.1.
Take this simple example:
using System;
using System.Net;
using System.Net.Sockets;
public class IPAddresses
{
static void Main(string[] args)
{
string name = Environment.MachineName;
if (args.Length > 0)
name = args[0];
IPHostEntry host = Dns.GetHostByName(name);
foreach (IPAddress address in host.AddressList)
{
Console.WriteLine("{0,15}: {1}", address.AddressFamily, address);
if (address.AddressFamily == AddressFamily.InterNetworkV6)
Console.WriteLine(" ScopeID: {0}", address.ScopeId);
}
}
} You can simply get the IPHostEntry using the Dns class and enumerate the IPAddress es.
Having your .NET application support IPv6 really isn't an issue. .NET already supports this - all you have to do is leverage it, such as allowing for IPv6 formatted addresses or checking for IPv6 support and trying to connect using IPv6.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Using your sample, I have "InterNetworkV6: ::1" for the address.
How can someone connect to a server that uses IPv6 addresses?
if a user type "::1" as server address I guess it won't work?
There is no spoon.
|
|
|
|
|
As I said before, you're forgetting about the scope ID. 0::1 is your local host address, which, IIRC, can be written as ::1 (I can't remember if a beginning 0 is necessary to specify).
Again, you really should read about IPv6. The best place is probably http://www.ipv6.org[^], which contains links to other resources.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
im writing a program i dev c++ who skude aktivate an ather program when the
USB-port is aktivated but i do not know who to get indikation from the
USB-port, any sudgestion?
|
|
|
|
|
|
Hello,
Are there any free controls out there that I can use in my application to let users browse folders and files just like Windows' Explorer? If it's possible I want it to have the xp look.
Thanks in advance
~~~~~~~~~~~~~~
Martin Lundberg
Student, Sweden
I have to thank every member of the Code Project for making it such a great place for a beginner to learn!
|
|
|
|
|
|
FolderBrowserDialog , actually.
This simply wraps the SHBrowseForFolder Shell API, which is the common approach.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
But I don't want a dialog that pops up, i want it laying on the form...like in explorer, can I do that too with FolderBrowserDialog?
Thanks again!
~~~~~~~~~~~~~~
Martin Lundberg
Student, Sweden
I have to thank every member of the Code Project for making it such a great place for a beginner to learn!
|
|
|
|
|
No, you can't do that with FolderBrowseDialog . Like I said, it wraps the SHBrowseForFolder Shell API. You should've read about that for more information.
If you're trying to make the umpteenth million Windows Explorer "replacement", you're definitely going to spend most of your time re-declaring unmanaged structs, interfaces, and P/Invoking lots of unmanaged APIs. The link mayasm gave you only shows yet another way to use a function that brings up the same (or very similar - in terms of implementation) dialog that SHBrowseForFolder does, only the latter API encapsulates all the ITEMIDLIST s and what-not, saving the caller a lot of work.
There was an article a long time ago I read either here on CodeProject or on MSDN[^] that discussed a way to do this. You might try searching google.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello again
hehe, I'm not trying to do the tenthmilion windows explorer replancement =) I'm trying to make an basic code editor for html,css and other things. And for that I need an easy way of browsing folders and selecting files to open and do other stuff like renaming, deleating, etc.
I've found a control att windowsforms.com called Hypercode FileList and FolderTree, these seams to work but they don't have the xp look automaticly. Maybe they change if i add a manifest as described in some article here on codeproject, but I don't know.
That explains a little more what I'm trying to do and what I'm searching for? =)
Well, Thanks again for all the answers and thoughts!
~~~~~~~~~~~~~~
Martin Lundberg
Student, Sweden
I have to thank every member of the Code Project for making it such a great place for a beginner to learn!
|
|
|
|
|
There is someone here:
C# does Shell, Part 1[^]
abcdabcdabcdabcda
Don't forget, that's Persian Gulf not Arabian gulf!
Murphy: Click Here![^] I'm thirsty like sun, more landless than wind...
|
|
|
|
|
Thanks! =) I will read it through! =)
~~~~~~~~~~~~~~
Martin Lundberg
Student, Sweden
I have to thank every member of the Code Project for making it such a great place for a beginner to learn!
|
|
|
|
|
Hi
I am trying to write an application that makes calls to the crypt32.dll. I have been able to do this with some other functions within this dll, but I am having problems with the CertVerifyRevocation function. Does anybody have any sample code for calling this function from C# code. I have tralled the forums and message boards of many places but have failed to find a concrete example.
Thanks,
Jamie.
|
|
|
|
|
WHy don't you use .net framework classes for cryprtography? Well, if you couldn't find how to use that function , you can write a managed C++ dll and use it in C#.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
While Mazdak's reply (use the System.Security.Cryptography classes) would normally apply, I realize that the current .NET FCL does not include information for cert revocation lists and verify them.
If you need to call functions defined in the crypt32.dll library, you need to P/Invoke them, so a good working knowledge of how types map between unmanaged and managed code (like knowing that an unmanaged LONG is a managed int (System.Int32 ) is necessary.
While the P/Invoke method declaration is easy, there is a heck of a lot of structures to re-declare in managed code, and the marshaller does not support marshalling nested structs, so you're pretty much stuck. As Mazdak recommened, write a mixed-mode MC++ (Managed C++ extensions) that use the native APIs and provide a managed class wrapper - it'll be MUCH easier than the alternative!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for your reply.
You are probably correct in saying that using managed C++ extensions would be easier, but I haven't looked at MC++ enough to know that. The problem is that there is already a sizeable part that has already been written (by other people) that uses calls into the crypt32.dll and the amount of effort and time to change the existing code would be much greater than carrying on in this manner, because adding the call to CertVerifyRevocation is the only extension to the current implementation.
What I was looking for were some resources to explain the mapping of types between managed and unmanaged code, and how to manage memory correctly to use the unmanaged functions (IntPtr usage, Marshalling memory etc...)
Thanks.
Jamie.
|
|
|
|