|
You must. All web servers do it, whether download HTML web pages or sending and receiving SOAP messages. You must encode it (whether you do it or some class you use does it, like an HttpWebClientProtocol used for web service proxies or a simple HttpWebRequest ) and use the same encoding on both the client and server.
Once the server decodes it using the correct encoding, you've got your XML back. This is how a network works - you upload/download bytes and text gets encoded in order to be send as bytes. Most often, APIs do this for you, but it still gets done. If you insist on using socket connections and sending data yourself instead of using one of the many helper classes, then you are responsible for encoding and decoding data.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
How can I drawing on axhost control?
I try this code: (AxHost Control is a)
Graphics g = a.CreateGraphics();
Pen p = new Pen(Color.Blue,2);
g.DrawLine(p,0,0,100,100);
but line dont appear. Thanks.
|
|
|
|
|
An AxHost control is just the base class for a hosted ActiveX control. The ActiveX control is responsible for it's own drawing, so using a Graphics object to draw on top of it won't work unless you provide some way through your controls supported interfaces to draw on it. One such way would be to return an HDC (as an IntPtr in managed code) from some method in your ActiveX control that you can use to create a Graphics object (see Graphics.FromHdc ) and then draw on the ActiveX control.
Also, be sure to call Dispose on your Graphics object to free native resources that the Graphics object uses, otherwise your performance will degrade over time.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
good day everyone,
can someone help me figure out how to get a list of all machines on specified network domain?
thanks a lot.
|
|
|
|
|
If you're using Active Directory for your domain, you can use the DirectorySearcher . See the article Querying Active Directory using .NET Classes and LDAP Queries[^] for an example.
If you're not using an Active Directory for your domain but instead are using old-school NT4 domains, then you'll have to query the WINS server. I'm not aware of any examples doing this, but you could find more information about querying a WINS server in the MSDN Library[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
:-Ohay there,
Before getting into any solution please read the entire message. See we have Exception Class in .net framework from (System.Object). Exception class is the base class for all exceptions(this sentence is from msdn).
So you are agreeing with this concept that, Exception is a Class.
just see the eg:
1. int a=10,b=20;
2. try
3. {
4. a=b/a;
5. }
6. catch(Exception Ex)
7. {
8. MessageBox.Show(Ex.Message.ToString());
9. }
Ok we can fight.
Before fighting the above mentioned eg won't rise any errors. Ok. Here my duty is something else.
If you see the line 6.
catch(Exception Ex) here I am just creating a variable of the type Exception. On line 8. I am calling a Property of the Exception class without creating the instance of Exception. Only initialization is happed in line 6.
How can I call a property of a class without creating an instance of that class ?
Any concept is there like " static property " ? Up to my level best No.
Just think you have different idea on the above mentioned question. Then what Microsoft mean by the signature of Property "Message" in Exception Class.
public virtual string Message {get;}
the above confusion is there for all properties which is available in Exception Class.
One more scenario If I create an instance of Exception class I will get all properties and method which available for the line 8.
What is this ?
Here what is the point creating instance if we want.
Next doubt is about disposing.
I think we can dispose instances of any class. What about the dispose method for an exception class ?
Just think I am creating one instance of Exception class (ins1).
How GC will destruct the inc1. When it destruct ?
Advance thanks for you
Sreejith SS Nair
|
|
|
|
|
Line 6 does create a variable of type Exception . The piece you're missing is that the framework's exception handling takes the object that was thrown using throw and tries to match it up with the exception handlers. If your handler is the one that's called, the Ex reference is set to the object that was thrown (which is either of type Exception or some type derived from Exception ). Your line 8 is then using the instance property Message (which is already a string, no need for ToString ) of the object that was thrown.
You can have static properties on a class; you simply use the static keyword just as you would for fields or methods.
You can only call the Dispose method on objects whose class implements a Dispose method. The convention is that exception objects do not implement a Dispose method, because it would be hard for generic code to know that Dispose should be called.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
sreejith ss nair wrote:
So you are agreeing with this concept that, Exception is a Class
I don't need to agree with it. It is fact. I could disagree until I was blue in the face, but it would remain a fact that Exception is a class.
sreejith ss nair wrote:
How can I call a property of a class without creating an instance of that class ?
You can't the C# compiler won't allow it. You are confusing the fact that you don't see the object being created. In this example you do:
1: try
2: {
3: throw(new Exception())
4: }
5: catch(Exception ex)
6: {
7: Console.WriteLine(ex.Message);
8: }
sreejith ss nair wrote:
I think we can dispose instances of any class. What about the dispose method for an exception class ?
Just think I am creating one instance of Exception class (ins1).
How GC will destruct the inc1. When it destruct ?
Like all objects in the .NET Framework - When the garbage collector chooses to. It is a non-deterministic function so you cannot determine when it is destroyed.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event
|
|
|
|
|
sreejith ss nair wrote:
Just think you have different idea on the above mentioned question. Then what Microsoft mean by the signature of Property "Message" in Exception Class.
public virtual string Message {get;}
the above confusion is there for all properties which is available in Exception Class.
A virtual or abstract member can be overridden by a derivative class, so that if you a derivative class was actually thrown and overrides the Message property, then its Message property's get accessor is called, not that on the Exception class. This is polymorphism, something you really need to understand if you're doing object-oriented development.
See Virtual Methods[^] in the C# Language Specification for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I have 2 methods exported from a dll, MyReader.dll
typedef unsigned short UINT16;
typedef unsigned int UINT32;
typedef unsigned char UINT8;
#define CMYREADER_API __declspec(dllexport)
class CMYREADER_API CMyReader
{
public:
bool mapImage(UINT16 SectorSize, const char * FileOnHardDriveToMap);
bool mapImage(UINT16 SectorSize, bool (* CallbackFunctionAddress)(UINT32 SectorToBeRead, UINT8 * SetToSectorData, bool IsLiteral));
....
};
How can I call the 2nd method from My C# Client? I have declared a delegate to pass as the 2nd argument to the function.
[DllImport("MyReader.dll", EntryPoint ="?mapImage@CMYReader@@QAE_NGP6A_NIPAE_N@Z@Z",CallingConvention=CallingConvention.ThisCall)]
private static extern System.Int32 mapImage(IntPtr inst,System.UInt16 SectorSize, ReadSectorDelegate CallbackFunctionAddress);
But when I give the CallingConvention as CallingConvention.ThisCall , I get the following error.
---------------------------<br />
Microsoft Visual C++ Debug Library<br />
---------------------------<br />
Debug Error!<br />
<br />
Program: E:\Vini\MyRdrTest\bin\Debug\MyRdrTest.exe<br />
Module: <br />
File: i386\chkesp.c<br />
Line: 42<br />
The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. <br />
<br />
(Press Retry to debug the application)<br />
---------------------------<br />
Abort Retry Ignore <br />
---------------------------
But if I change the callingConvention to CallingConvention.StdCall , it does not call the CallBack function. Is there any other way to implement this? What am I doing wrong here?
Kindly help.
Vini
|
|
|
|
|
You can't call class-based DLL exports like this from .NET. You must either change the DLL to provide flat exports (static or file-scope functions) or use COM interop.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Yes you can, actually, but you need to have a class factory which creates an instance of the class (which gives you the IntPtr ) that you pass as the first parameter of a P/Invoke method using CallingConvention.ThisCall .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You can actually P/Invoke class methods so long as you have a class factory to create an instance of that class. The problem here - like the exception text reads - is that your callback function uses a different calling convention. To be honest, I'm not really sure how you're going to get around this. I've never had to deal with callbacks in classes before (just calling methods on exported native classes).
The StdCall shouldn't work since you need to push the class instance's address in the ECX register (which the first parameter in a ThisCall method is used for). Thus, you wouldn't really be calling a method but a function, treating it as if it were static.
I did find this[^], however, which I hope proves helpful.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
You can actually P/Invoke class methods so long as you have a class factory to create an instance of that class.
Is there any link that explains this? I cannot change the calling convention as the method exported is a member of the class and I need to pass the instance ptr of the class as the first argument to the method, to call the class methods. Is there any other way to call the class methods from the DLL?
Will it help, if I change the callback method declaration in the C++ Dll to something else? like,
bool mapImage(UINT16 SectorSize,
bool (* __stdcall CallbackFunctionAddress)(UINT32 SectorToBeRead, UINT8 * SetToSectorData, bool IsLiteral));
To call the methods from the exported class, I have added two methods to the class: 1. To return the instance ptr of the class to the client and 2. To remove the instance of the class. Is this the correct way?
Pls help...
Vini
|
|
|
|
|
|
Tnx. I have seen that previous post of yours before. I am able to call the exported class methods. The issue with callback function, I think I have it right now, is by modifying the C++ DLL source. Added the __stdcall to the Callback method declaration. Is this okay?
bool mapImage(UINT16 iSectorSize, bool (__stdcall * pCallback)(UINT32, UINT8 *, bool))
Tnx for the help.
Vini
|
|
|
|
|
i am doing my finalyear project in remote desktop sharing,i transfer the image to other machine with the help of socket classes tcplistener and tcp client.i transfer image with the help of System.IO.MemoryStream and convert this to bytes with method ToArray() of System.IO.MemoryStream. on receving side bytes are read and written to System.IO.MemoryStream then transfer this stream to bitmap image (Bitmap class instance)by method Bitmap.FromStream(ImageMemStream);ImageMemStream is instance of System.IO.MemoryStream.After some random and long interval of time i got an exception System.drawing.dll on line
Bitmap.FromStream(ImageMemStream);
PLease help me about this.
mughalali
|
|
|
|
|
How are we supposed to help you if you don't tell us what exception you're getting and what the exception message states? That like telling a doctor you have a paint but not telling him where.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Gurus! I got some question for you...
In my C# WinForm application I generate an html page. I created a new file with .htm extention through filestream and wrote some text to it. The question is how can I launch this file from C#? I mean I need to repeat such effect if I just open the folder containing this html file and double click on it in explorer, I need to make in in C#.
www.xedom.com
|
|
|
|
|
try
Process.Start("IExplore.exe", "<yourfile.html>");
Cheers,
Kannan
|
|
|
|
|
System.Diagnostics.Process.Start( htmlFileName ); Process.Start uses the ShellExecuteEx API by default, so it will launch the user's default browser.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Thanx a lot. I'll try this without fall. Also I want to ask you some more - I want to send a request to the server's php page, through my WinForm application, I use code like this
Uri u = new Uri(@"http://www.umc.ua/misc/sendsms.php");
WebRequest req = WebRequest.Create(u);
req.ContentType = "application/x-www-formurlencoded";
req.Method = "POST";
req.Timeout = 300000;
req.Headers.Add("network1","UMC");
req.Headers.Add("Phone1","5918658");
req.Headers.Add("network2","UMC");
req.Headers.Add("Phone2","");
req.Headers.Add("network3","UMC");
req.Headers.Add("Phone3","");
req.Headers.Add("Message","HellofromCSharp");
req.Headers.Add("sender_name","sn");
WebResponse res =req.GetResponse();
text.Text = req.Headers.ToString();
StreamReader sr = new StreamReader(res.GetResponseStream(),Encoding.UTF8);
string str = sr.ReadToEnd().ToString();
RES_text.Text = str;
res.Close();
But my application fails with Timeout expired bug. So could you tell me were the problems is? How can I send data to php page in C# code using POST method? Thanx.
www.xedom.com
|
|
|
|
|
Why are you adding headers? I take it that's what you want to post to the PHP CGI? See the HttpWebRequest.GetRequestStream[^] method documentation in the .NET Framework SDK for an example.
Basically, you get the request stream before you get the HTTP response and write your &-delimited parameters and values (delimited by =) to the response stream using an Encoding that matches up with the HttpWebRequest.ContentType (application/x-www-form-urlencoded uses ASCII encoding, so use Encoding.ASCII or ASCIIEncoding (the same thing, just different ways of getting an instance of it). After you're finished, you flush and close the request stream and then get your response. The link above has a more detailed example.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok, thnank you Heath. But I have done following things and still no effect:
string post_data;
post_data = "?network1=UMC&Phone1=5918658&Message=HellofromCSharp&sender_name=sn";
string page = "@http://www.umc.ua/misc/sendsms.php"+post_data;
WebRequest req = WebRequest.Create(page);
WebResponse res = req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(),Encoding.ASCII);
string str = sr.ReadToEnd().ToString();
RES_text.Text = str;
res.Close();
www.xedom.com
|
|
|
|
|
did you look at the example? When POST'ing data you must get the request stream - not the response stream - and write your post_data (without the preceeding "?") and write it to the request stream, then close it and get your response. This is shown in the example at the bottom of the page I linked.
Microsoft MVP, Visual C#
My Articles
|
|
|
|