|
I have commented last line of the code and all works fine for now:
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://www.umc.ua/misc/sendsms.php");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string postData = "network1=UMC&Phone1=5918658&Message=We did it! &sender_name=sn";
byte[] buffer = Encoding.ASCII.GetBytes(postData);
request.ContentLength = buffer.Length;
Stream s = request.GetRequestStream();
s.Write(buffer, 0, buffer.Length);
s.Flush();
s.Close();
//HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//response.Close();
Could you explain me please for what I need this line-
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
www.xedom.com
|
|
|
|
|
That's what submits the request and gets the response from the server. You can ignore the response if you like, but you really should check the HttpWebResponse.StatusCode to make sure the operation succeeded.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am looking into porting a COM C++ out of process server to C#. Been looking for an example of an out process server written in C#, can't seem to find any info in MSDN or anywhere else.
Any assistance appreciated.
Thanks in Advance.
Colin
|
|
|
|
|
See Nick's article, Creating a CCW for COM-enabled Non-.NET Applications[^] and follow the same things, paying attention to the note I prompted him to add about not using auto-generated class interfaces.
Then you register the executable as you would a DLL. Take a look at this sample:
using System;
using System.Drawing;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyKeyFile(@"C:\Path\To\KeyFile.snk")]
namespace Test
{
[Guid("0eea66bf-21bf-4c8c-8678-ad58106343a7")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ITest
{
[DispId(0)]
DialogResult ShowDialog();
}
[ClassInterface(ClassInterfaceType.None)]
[Guid("861e1098-7705-4686-945e-236a0ef439ef")]
[ProgId("Test.Test")]
public class Test : Form, ITest
{
static void Main()
{
Application.Run(new Test());
}
public Test()
{
SuspendLayout();
Text = "Out-of-Proc Server Test";
Label lbl = new Label();
Controls.Add(lbl);
lbl.Location = new Point(8, 8);
lbl.Text = "Hello, world!";
ResumeLayout();
}
}
} Compile it and run:
regasm.exe /tlb /codebase Test.exe Finally, I create a very simple JScript file that I ran with cscript.exe (Windows Scripting console host):
var test = new ActiveXObject("Test.Test");
test.ShowDialog(); The important thing is that your interfaces are dispatch interfaces (or dual) so that the script engine can find and invoke your members.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
Thanks for the reply, I looked at Nicks Article, following the same things and using the sample I could not get it to run out of process.
A better description of what I am trying to do might help:
I have built a COM Callable Wrapper (CCW) using Microsoft .NET & C#. The CCW uses attributes to provide a COM interface into a .NET component. This CCW can be created in-process using standard CoCreateInstance calls. However, it is necessary that this CCW runs out-of-process replacing an original COM component built using VC++ as a COM EXE service.
I have used the SDK supplied COMREG sample instead of REGASM to register the component with an AppID indicating that it should be run with a surrogate process – the system supplied surrogate DllHost.EXE.
The CCW can then be created out of process when CoCreateInstanceEx with a local COSERVERINFO address, ie, via DCOM. However, existing clients use standard CoCreateInstance to create the CCW; however standard CoCreateInstance causes the CCW to be created in-process instead of out of process.
Is their a mechanism to force the CCW to be created out-of-process (as if created using CoCreateInstanceEx) with the standard CoCreateInstance call.
I am investigating futher, any further you have to add would be greatly appreciated.
Regards
Colin
|
|
|
|
|
Yeah, I know what an out-of-proc server is. I've been working with COM since it was known as OLE (so to speak). Did you try compiling, registering, and executing the script file I wrote in my reply? It works perfectly fine. You compile it as an exe:
csc /t:exe Test.cs Follow the rest of the instructions and you'll get an out-of-proc server.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I followed your instructions to the letter, and I did not get an out of process server
|
|
|
|
|
What exactly do you mean that you don't get an out-of-process server? It works just fine. My forte' is interoperability in .NET and I do this all the time. The example does work, and if you need a typelib the /tlb switch on regasm.exe will generate one. If you make a script file like I provided, then execute the script with the Windows Scripting Host (cscript.exe for this example). Check the task manager and you'll see the application running. The ShowDialog method defined in the explicit class interface is just one method to show in this example. If you need access to anything else (like form properties, methods, or your own class's properties and methods) then you'll need to define those in the class interface as well, or at least another dispatch interface you could implement. The CLR will take care of the rest.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I created a script file, exactly as you provided. I get a dialog box with "Out-of-Proc Server Test" in the title bar and Hello world as expected. I have checked task manager and the application I see running is cscript.exe. Is this what you mean? What application do you mean? I was expecting test.exe(the out-ofproc server exe), which is not in task manager, maybe I am missing something here. My understanding of an out of process server is "A server, implemented as an .EXE application, which runs outside the process of its client", cscript being the client in this case. I apologise for the confusion, if I have caused any. I have done this in COM, however this is the first time I have tried to do it in .NET.
|
|
|
|
|
mscoree.dll - the CLR host - creates an AppDomain for the executable and loads the assembly, executing the main entry point and marshalling calls. This does not create a separate process as you've seen. I'm not even sure you could do this using pure .NET. You might have to create your own shim (like mscoree.dll) that runs as a process and marshals calls to your managed AppDomain. I remember seeing some code once for a custom host such as this (sorry, can't remember where - though you could try SourceForge) and it was by no means a simple task.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Have a look at my plugin manager article, someone mentioned that was similar to an out of process server.
|
|
|
|
|
Leppie,
Thanks for the reply, I had a look at your plugin manager article, tried to do the same in my situation and could not get it to run out of process.
A better description of what I am trying to do might help:
I have built a COM Callable Wrapper (CCW) using Microsoft .NET & C#. The CCW uses attributes to provide a COM interface into a .NET component. This CCW can be created in-process using standard CoCreateInstance calls. However, it is necessary that this CCW runs out-of-process replacing an original COM component built using VC++ as a COM EXE service.
I have used the SDK supplied COMREG sample instead of REGASM to register the component with an AppID indicating that it should be run with a surrogate process – the system supplied surrogate DllHost.EXE.
The CCW can then be created out of process when CoCreateInstanceEx with a local COSERVERINFO address, ie, via DCOM. However, existing clients use standard CoCreateInstance to create the CCW; however standard CoCreateInstance causes the CCW to be created in-process instead of out of process.
Is their a mechanism to force the CCW to be created out-of-process (as if created using CoCreateInstanceEx) with the standard CoCreateInstance call.
I am investigating further, any further you have to add would be greatly appreciated.
Regards
Colin
|
|
|
|
|
Sorry, but my COM knowledge is worse than zero I have no need for it and it looks like too much crap for my liking.
|
|
|
|
|
I would like to play a Direct3D animation inside of a window panel. Can anyone point me in the right direction. I have nothing implemented for that so far. Is it simply a case of specifying that the panel is the Owner of the animation?
|
|
|
|
|
See the Device constructor which takes a Control as the 3rd parameter, which is uses for the rendering surface.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Can anyone give me some information on the commenting schema for the self-generated doc files?
ie> /// <summary> blah </summary>
I need information on what other tags can be used, and what they are for. I can't seem to find any decent documentation on this anywheres online.
Thanks in advance,
Jon
|
|
|
|
|
|
|
You're welcome!
Regards,
Jeff Varszegi
EEEP!
|
|
|
|
|
Hi, how can I dectect when a column of listview chage its width at runtime?.
It happend When the user chage de width of the colums (Sistem.Windows.Columnheader) withe the mouse.
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
Extend the ListView class and override WndProc like so (a sample application is provided):
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class Test : Form
{
static void Main()
{
Application.Run(new Test());
}
public Test()
{
SuspendLayout();
Text = "MyListView Test";
MyListView lv = new MyListView();
Controls.Add(lv);
lv.Dock = DockStyle.Fill;
lv.View = View.Details;
lv.ColumnHeaderChanged += new ColumnHeaderChangedEventHandler(
lv_ColumnHeaderChanged);
ColumnHeader col1 = new ColumnHeader();
col1.Text = "One";
ColumnHeader col2 = new ColumnHeader();
col2.Text = "Two";
lv.Columns.Add(col1);
lv.Columns.Add(col2);
ResumeLayout();
}
private void lv_ColumnHeaderChanged(object sender,
ColumnHeaderChangedEventArgs e)
{
Console.WriteLine("Column {0} changed: new width = {1}",
e.ColumnHeader.Text, e.ColumnHeader.Width);
}
}
public class MyListView : ListView
{
private IntPtr hWndHeader;
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
hWndHeader = SendMessage(Handle, LVM_GETHEADER, 0, 0);
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_NOTIFY)
{
NMHDR hdr = (NMHDR)Marshal.PtrToStructure(m.LParam, typeof(NMHDR));
if (hdr.hwndFrom == hWndHeader &&
(hdr.code == HDN_ITEMCHANGEDA || hdr.code == HDN_ITEMCHANGEDW))
{
NMHEADER header = (NMHEADER)
Marshal.PtrToStructure(m.LParam, typeof(NMHEADER));
int index = header.iItem;
if (index >= 0 && index < Columns.Count)
{
ColumnHeader col = Columns[index];
OnColumnHeaderChanged(new ColumnHeaderChangedEventArgs(col));
}
}
}
}
public event ColumnHeaderChangedEventHandler ColumnHeaderChanged;
protected virtual void OnColumnHeaderChanged(ColumnHeaderChangedEventArgs e)
{
if (ColumnHeaderChanged != null)
ColumnHeaderChanged(this, e);
}
private const int WM_NOTIFY = 78;
private const int HDN_ITEMCHANGEDA = -301;
private const int HDN_ITEMCHANGEDW = -321;
private const int LVM_GETHEADER = 4127;
[StructLayout(LayoutKind.Sequential)]
public class NMHDR
{
public IntPtr hwndFrom;
[MarshalAs(UnmanagedType.U4)] public int idFrom;
[MarshalAs(UnmanagedType.U4)] public int code;
}
[StructLayout(LayoutKind.Sequential)]
public class NMHEADER
{
public IntPtr hwndFrom;
[MarshalAs(UnmanagedType.U4)] public int idFrom;
[MarshalAs(UnmanagedType.U4)] public int code;
public int iItem;
public int iButton;
public IntPtr pitem;
}
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg,
int wParam, int lParam);
}
public delegate void ColumnHeaderChangedEventHandler(object sender,
ColumnHeaderChangedEventArgs e);
public class ColumnHeaderChangedEventArgs : EventArgs
{
private ColumnHeader columnHeader;
public ColumnHeaderChangedEventArgs(ColumnHeader header)
{
columnHeader = header;
}
public ColumnHeader ColumnHeader
{
get { return columnHeader; }
}
} For fun I implemented the ColumnHeaderChanged event, though you could just skip all that and implement your code where I call OnColumnHeaderChanged (which fires the event - the proper way to fire an event in order to allow derivative classes to override your event handler without handling the event itself, which is faster and allows for more control).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you!
Thats what I need. Its is very complicated for me now but works fine. I hope understand it all soon.
I will use it in my DataListView custom control.
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
The best way to understand it is the read the documentation for the classes and members I used. Many of what I did, however, is from the Platform SDK for common controls. I re-declared several native structs as classes (not as structs as I normally would so that I can use Marshal.PtrToStructure , which requires a class instance) and P/Invoked SendMessage . The constants are defined in winuser.h and commctrl.h.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How take IP-address of workgroup or domain computers?
Demonstrate with an C# example.
Cosma
|
|
|
|
|
If you know the names of these computers use the Dns.GetHostByName method. This returns an object of class IPHostEntry which contains a list of IP addresses associated with the host.
<br />
System.Net.IPHostEntry hostEntry = System.Net.Dns.GetHostByName(hostName);<br />
System.Net.IPAddress[] adresses = hostEntry.AddressList;<br />
See the documentation for further information.
|
|
|
|