|
using System.Runtime.InteropServices;
IHTMLDocument2 doc = (IHTMLDocument2) instVisualObjectCreator.Document;
UCOMIPersistFile pf = (UCOMIPersistFile) doc;
pf.Save(@"c:\myhtmlpage.html",true);
PS : the IHTMLDocument2 interface is from the mshtml primary interop library (which you can add to your project, c:\program files\microsoft.NET\primary interop assemblies\microsoft.mshtml.dll).
|
|
|
|
|
Or he could do it the "Completely managed" way:
using System;
using System.Net;
using System.Text;
namespace Utilities
{
class WebPage
{
static string GetHtml(string address)
{
WebClient client = new WebClient();
return Encoding.Default.GetString(client.DownloadData(address));
}
}
}
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
|
|
|
|
|
Geeee! This is ok for a completely IE-less scenario.
|
|
|
|
|
Yeah. That was my point. Why on earth would you need to use IE?
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
|
|
|
|
|
Well, I guess that saving the html source code from the current web page is the final scenario step for Windows apps that embed IE because they want to show the web page(s). The .NET WebClient helper class is no substitution for showing pages.
|
|
|
|
|
Ah...I see now. I didn't think of it in terms of actually showing pages...just downloading them and parsing their source (which I've done a lot of recently).
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
|
|
|
|
|
How can I install a service PROGRAMICALLY?
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
|
|
I'm having some problems creating only a single instance in a document view in a MDI. So, regardless of the user's interaction with the new form command only 1 form will be shown.
If anyone has an idea, please let me know. Thanks!
|
|
|
|
|
Follow these steps:
*Make the constructor private like this:
private MainForm()
{
}
*Declare a static variable to hold the one-and-only form instance like this:
static MainForm instMainForm=new MainForm();
*Create a property procedure like this:
public static MainForm TheForm {
get {
return instMainForm;
}
}
*To get the form instance, call the "TheForm" property procedure.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
Hi!
The normal call
x = Shell("Rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl ,0")
How can this be done in C#
Thanx in Advance.
|
|
|
|
|
System.Diagnostics.Process.Start(...)
|
|
|
|
|
Its a bit more complicated but here is an example:
using System;
using System.Diagnostics;
Process p = new Process();
p.StartInfo = new ProcessStartInfo(@"Rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl, 0");
p.StartInfo.UseShellExecute = true;
p.Start();
p.WaitForExit();
Andy
He who knows and knows that he knows, is wise; follow him
He who knows and knows not that he knows, is asleep; wake him
He who knows not, and knows that he knows not, is simple; teach him
He whoe knows not and knows not that he knows not, is a fool; kick him
|
|
|
|
|
Thank you both )
|
|
|
|
|
Thanx but both the solutions gives errors.
System.ComponentModel.Win32Exception: The system cannot find the file specified
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at TestWindowsForms.Form1.menuItem24_Click(Object sender, EventArgs e) in d:\visual studio projects\art\testwindowsforms\form1.cs:line 661
at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
at System.Windows.Forms.MenuItemData.Execute()
at System.Windows.Forms.Command.Invoke()
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Yes I've check the command " Rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl, 0 " inside the Start/Run dialog in windows 2000 and it works.
But why doesn't it work when called from the program. Check with other *.cpl files as well.
Any help would be Greatly appreciated !!!
|
|
|
|
|
Solution1 : async call
System.Diagnostics.Process.Start("Rundll32",
"shell32.dll,Control_RunDLL Sysdm.cpl ,0");
Solution2 : sync call
Process p = new Process();
p.StartInfo = new ProcessStartInfo("Rundll32.exe",
"shell32.dll,Control_RunDLL Sysdm.cpl , 0");
p.StartInfo.UseShellExecute = true;
p.Start();
p.WaitForExit();
|
|
|
|
|
When you have to call an unmanged API method that requires a structure that contains a fixed length string, how should you express that in C#
EG:
A method I want to call has this unmanaged structure:
typedef struct foo<br />
{<br />
char szSymbol[20];<br />
DWORD dwVolume;<br />
} FOO;
So in C# I think I would do this:
[StructLayout(LayoutKind.Sequential, Pack=4, CharSet=CharSet.Ansi)]<br />
struct FOO<br />
{<br />
public string szSymbol = new String(' ', 20);<br />
public UInt32 dwVolume;<br />
}
Am I on the right track?
Andy
|
|
|
|
|
Crap - it would appear that you can't initalise structures like that.
He who knows and knows that he knows, is wise; follow him
He who knows and knows not that he knows, is asleep; wake him
He who knows not, and knows that he knows not, is simple; teach him
He whoe knows not and knows not that he knows not, is a fool; kick him
|
|
|
|
|
Use the MarshalAs attribute on the struct's fields to specify how it should convert the string.
Untested/uncompiled:
[StructLayout(LayoutKind.Sequential, Pack=4, CharSet=CharSet.Ansi)]
struct FOO
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=20)]
public string szSymbol;
public uint dwVolume;
} Now if szSymbol is going to be modified by the P/Invoke'd method then you need to use a StringBuilder rather than string to avoid any problems that may occur due to string interning.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thanks heaps - I had just discovered this attribute myself but was going to use UnmanagedType.LPStr
James T. Johnson wrote:
Now if szSymbol is going to be modified by the P/Invoke'd method then you need to use a StringBuilder rather than string to avoid any problems that may occur due to string interning
Rrrright.
Could you elaborate on the StringBuilder part? The szSymbol is going to be modified by the P/Invoke'd method.
TIA
Andy
|
|
|
|
|
Andy Davey wrote:
I had just discovered this attribute myself but was going to use UnmanagedType.LPStr
I'm not that familiar with interop but to me LPStr means a pointer to a string rather than embedding one within a struct. I think this is also how the Interop Marshaller will interpret it.
Andy Davey wrote:
Could you elaborate on the StringBuilder part?
Sure.
Strings in .NET are considered immutable; this allows for some optimizations to be made in both memory requirements and when comparing strings.
Because they are immutable you can have two strings that contain the same value point to the same block of memory. And rather than compare every single character to see if they are equal you can just compare whether the two strings point to the same object.
That is where string-interning comes in, it takes a string and adds it to an internal table which allows you to make use of those optimizations.
But there is a down side to strings being immutable. When you want to do lots of string operations (such as concatenation) you create a lot of new string objects using up memory that isn't used after the next operation.
That is where the StringBuilder comes in (full name: System.Text.StringBuilder ) it maintains an internal buffer/array of characters (similar to C style strings) and does various operations on the array rather than creating new string objects.
When you are done modifying the StringBuilder you can then call .ToString() on it and get out the string that was built.
To link this in with P/Invoke, since you have a buffer that needs a string the proper usage is to supply that buffer with a StringBuilder object rather than a string (which isn't supposed to change).
To change the first struct (going from memory):
[StructLayout(Layout.Sequential, Pack=4, CharSet=CharSet.Ansi)]
struct FOO
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=20)]
public System.Text.StringBuilder szSymbol;
public uint dwVolume;
} Then, because structs can't have default constructors you need to initialize szSymbol to szSymbol = new System.Text.StringBuilder(20); To provide a default constructor you can change FOO from a struct to a class (despite its name StructLayout can be applied to classes )
HTH,
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
I only saw this last night, but in the lastest MSDN they a very comprehensive Marshalling Tutorial
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
Hi all
OK I have a HWND from a window, can I make a Control instance from that? Even though the program is not .NET? If so, why does Control.FromHandle return null?
Help appreciated
Thanks
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
leppie wrote:
OK I have a HWND from a window, can I make a Control instance from that?
A window handle references a unique window in the desktop. Although a handle uniquely identifies a control (whether managed or not), a control is much more than a handle.
One thing I can guess is you want to create a control based on the window styles used by the window referred by the handle. In such a case, make sure to override the control class and fill the CreateParams structure. Creating a new control based on styles from an existing window requires interop (GetClassName, GetWindowLong , ...).
leppie wrote:
why does Control.FromHandle return null?
Control.FromHandle(IntPtr) does not create a control based on the passed parameter. It only tries to match the handle with one of the existing (managed) controls' handles.
|
|
|
|