|
Now, i said i would, so i will http://www.codeproject.com/lounge.asp?msg=2309375#xx2309375xx[^]
Your Majesty,
I have been unable to obtain the icon of an open window for some time, despite my toughest efforts. I have been using SendMessage to send a message to a window, notepad for example, with the message WM_GETICON, and trying to get both small and large icons. This always returns with 0. Ma'am, i would greatly appreciate it if you would help me in solving my dilemma, through use of SendMessage or otherwise. Below you will find an example of the code i am using.
I remain your faithful and humble subject,
The Undefeated
hWnd = IntPtr.Zero;
foreach(Process window in Process.GetProcesses()) {
if(window.MainWindowTitle == this.textBox1.Text)
hWnd = window.MainWindowHandle;
}
if(hWnd == IntPtr.Zero)
MessageBox.Show("Could not find window");
...
if(hWnd != IntPtr.Zero) {
int hIcon = SendMessage(hWnd, 0x7f, 1, 0);
if(hIcon == 0)
MessageBox.Show("Damn, it did it again");
else
this.pictureBox1.Image = Bitmap.FromHicon(new IntPtr(hIcon));
}
Wow, writing my user name "The Undefeated" ugh, its so old. I havn't used it in years, many years, but i thought i should perhaps leave it alone anyway
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
|
Such excellence, GetClassLong works like a charm.
Thanks.
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
You are welcome
|
|
|
|
|
To All:
I'm a newbie at filter graphs and I've been working on building a filter graph to convert/play a .mp3 file to a .wav format and play the music. In my filter graph I have an infinite pin tee filter, which is splitting the output to go to three output devices ( 2 sets of headphones and a set of speakers ). I built the filter graph in GraphEdit and it works fine. It splits the output to the 3 output devices. Now I've taken on the challenge of building this filter graph programmatically and I'm running into some difficulties. When I put my filter graph on the ROT to examine it in GraphEdit, either it's not visible when I try to get the remote graph or I get an error, "Object reference not set to an instance of an object." That's one part that would be useful for debugging. I also read that the physical connections that I created programmatically for the pins may be changed when I render the file, which causes the above error.
The second part is that I may be building my filter graph incorrectly (most likely). Like I said, I'm a newbie at this. The code I have started with, came from a project I found on the net, and then I made quite a few modifications to get where I am now. My code doesn't seem to split the outputs to the different output devices. I only get the music to one headset, and nothing to the others. I'm not sure if it's how I'm finding and connecting my pins, or just how I'm building the filtergraph, which is causing me the problems. I read something on one of the forums last night about building the filter graph the way you would put it together in GraphEdit, so I changed my code to connect pins as I added filters. It still is giving me problems with not splitting the outputs to the devices.
There is one more issue. This is being developed on a Vista machine in C#, but I went to the compatibility tab in the properties for the executable and set it to a Compatibility mode of "Windows XP (Service Pack 2)". Did I say that I do have it working in GraphEdit, with the splitting of the outputs? I have added the code below. If anyone has any suggestions or can help me, I would greatly appreciate it.
Thanks in advance.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Runtime.InteropServices;
using DirectShowLib;
public class M2Mkv : Form
{
private Button button1;
private RadioButton MkvRadioButton;
private RadioButton WmvRadioButton;
private GroupBox groupBox1;
private Label label1;
private Container components = null;
// The main com object
private static FilterGraph fg = null;
// The graphbuilder interface ref
private static IGraphBuilder gb = null;
// The mediacontrol interface ref
private static IMediaControl mc = null;
// The mediaevent interface ref
private static IMediaEventEx me = null;
// DD For debugging
DsROTEntry rot = null;
// MPEG 1 stream splitter interface
private static IBaseFilter mp3_file_source = null;
private static IBaseFilter mpg_stream_splitter = null;
private static IBaseFilter dshow_audio_decoder = null;
private static IBaseFilter infinitePinTeeFilter = null;
private static IBaseFilter logitech_earphone_headset = null;
private static IBaseFilter logitech3_earphone_headset = null;
private static IBaseFilter sigmatel_speakers_headset = null;
// variable to store the filename and extension
private static string fName;
private static string fExt;
// one "global" hr
private static int hr;
public M2Mkv()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.MkvRadioButton = new System.Windows.Forms.RadioButton();
this.WmvRadioButton = new System.Windows.Forms.RadioButton();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 16);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Convert";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 120);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 24);
this.label1.TabIndex = 1;
//
// MkvRadioButton
//
this.MkvRadioButton.Checked = true;
this.MkvRadioButton.Location = new System.Drawing.Point(8, 16);
this.MkvRadioButton.Name = "MkvRadioButton";
this.MkvRadioButton.TabIndex = 2;
this.MkvRadioButton.TabStop = true;
this.MkvRadioButton.Text = "Convert to mkv";
//
// WmvRadioButton
//
this.WmvRadioButton.Location = new System.Drawing.Point(8, 40);
this.WmvRadioButton.Name = "WmvRadioButton";
this.WmvRadioButton.TabIndex = 3;
this.WmvRadioButton.TabStop = true;
this.WmvRadioButton.Text = "Convert to wmv";
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.WmvRadioButton,
this.MkvRadioButton});
this.groupBox1.Location = new System.Drawing.Point(16, 40);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(128, 72);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
//
// M2Mkv
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(232, 150);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1,
this.button1,
this.groupBox1});
this.MaximizeBox = false;
this.Name = "M2Mkv";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.Text = "m2mkv";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new M2Mkv());
}
//
// method to ask the user the filename
//
private void button1_Click(object sender, System.EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if( ofd.ShowDialog() == DialogResult.OK )
{
FileInfo fi = new FileInfo( ofd.FileName );
fExt = fi.Extension;
fName = fi.FullName.Substring( 0, fi.FullName.Length - fExt.Length );
CloseInterfaces();
InitInterfaces();
if (MkvRadioButton.Checked)
{
label1.Text = "processing";
button1.Enabled = false;
StopMp3();
PlayMp3();
}
}
}
// Play the music
public void PlayMp3()
{
Convert2Wav();
}
// Stop the music
public void StopMp3()
{
if (mc != null)
{
mc.Stop();
mc = null;
}
}
//
// This method creates the filter graph
//
void InitInterfaces()
{
try
{
//fg = new FilterGraph();
//gb = (IGraphBuilder)fg;
//mc = (IMediaControl)fg;
//me = (IMediaEventEx)fg;
gb = (IGraphBuilder)new FilterGraph();
//gb = (IGraphBuilder)fg;
// mc = (IMediaControl)gb;
// me = (IMediaEventEx)gb;
}
catch(Exception)
{
MessageBox.Show( "Couldn't start" );
}
}
//
//This method stops the filter graph and ensures that we stop
//sending messages to our window
//
void CloseInterfaces()
{
// Clean it up
if( me != null )
{
hr = mc.Stop();
DsError.ThrowExceptionForHR( hr );
hr = me.SetNotifyWindow( IntPtr.Zero , WM_GRAPHNOTIFY, IntPtr.Zero );
DsError.ThrowExceptionForHR( hr );
}
// DD For debugging
if (rot != null)
{
rot.Dispose();
rot = null;
}
if (mp3_file_source != null)
Marshal.ReleaseComObject(mp3_file_source);
mp3_file_source = null;
if (mpg_stream_splitter != null)
Marshal.ReleaseComObject(mpg_stream_splitter);
mpg_stream_splitter = null;
if (dshow_audio_decoder != null)
Marshal.ReleaseComObject(dshow_audio_decoder);
dshow_audio_decoder = null;
if (infinitePinTeeFilter != null)
Marshal.ReleaseComObject(infinitePinTeeFilter);
infinitePinTeeFilter = null;
if (logitech_earphone_headset != null)
Marshal.ReleaseComObject(logitech_earphone_headset);
logitech_earphone_headset = null;
if (logitech3_earphone_headset != null)
Marshal.ReleaseComObject(logitech3_earphone_headset);
logitech3_earphone_headset = null;
if (sigmatel_speakers_headset != null)
Marshal.ReleaseComObject(sigmatel_speakers_headset);
sigmatel_speakers_headset = null;
if (mc != null)
Marshal.ReleaseComObject(mc);
mc = null;
if (me != null)
Marshal.ReleaseComObject(me);
me = null;
if (gb != null)
Marshal.ReleaseComObject(gb);
gb = null;
if( fg != null )
Marshal.ReleaseComObject( fg );
fg = null;
}
//
// This method converts the input file to a wav file
//
void Convert2Wav()
{
IPin mp3_file_sourceOut = null;
IPin mpg_stream_splitterIn = null, mpg_stream_splitterOut = null;
IPin dshow_audio_decoderIn = null, dshow_audio_decoderOut = null;
IPin infinitePinTeeFilterIn = null, infinitePinTeeFilterOut1 = null;
IPin infinitePinTeeFilterOut2 = null, infinitePinTeeFilterOut3 = null;
// Output Devices
IPin logitech_earphone_headsetIn = null;
IPin logitech3_earphone_headsetIn = null;
IPin sigmatel_speakers_headsetIn = null;
try
{
string fileName = fName;
Guid filter_graph_guid = new Guid("E436EBB8-524F-11CE-9F53-0020AF0BA770");
Type t = Type.GetTypeFromCLSID(filter_graph_guid);
gb = (IGraphBuilder)Activator.CreateInstance(t);
Guid file_source_guid = new Guid("E436EBB5-524F-11CE-9F53-0020AF0BA770");
Type file_source_type = Type.GetTypeFromCLSID(file_source_guid);
mp3_file_source = (IBaseFilter)Activator.CreateInstance(file_source_type);
hr = gb.AddFilter((IBaseFilter)mp3_file_source, fileName);
mp3_file_source.FindPin("Output", out mp3_file_sourceOut);
DsError.ThrowExceptionForHR(hr);
Guid splitter_guid = new Guid("336475D0-942A-11CE-A870-00AA002FEAB5");
Type splitter_type = Type.GetTypeFromCLSID(splitter_guid);
mpg_stream_splitter = (IBaseFilter)Activator.CreateInstance(splitter_type);
hr = gb.AddFilter((IBaseFilter)mpg_stream_splitter, "MPEG 1 Stream Splitter");
mpg_stream_splitter.FindPin("Input", out mpg_stream_splitterIn);
mpg_stream_splitter.FindPin("Audio", out mpg_stream_splitterOut);
DsError.ThrowExceptionForHR( hr );
// Connect the file source to the stream splitter
gb.Connect(mp3_file_sourceOut, mpg_stream_splitterIn);
Guid decoder_guid = new Guid("0F40E1E5-4F79-4988-B1A9-CC98794E6B55");
Type decoder_type = Type.GetTypeFromCLSID(decoder_guid);
dshow_audio_decoder = (IBaseFilter)Activator.CreateInstance(decoder_type);
hr = gb.AddFilter((IBaseFilter)dshow_audio_decoder, "ffdshow Audio Decoder 0001");
dshow_audio_decoder.FindPin("In", out dshow_audio_decoderIn);
dshow_audio_decoder.FindPin("Out", out dshow_audio_decoderOut);
DsError.ThrowExceptionForHR(hr);
// Connect the stream splitter to the audio decoder
gb.Connect(mpg_stream_splitterOut, dshow_audio_decoderIn);
Guid tee_filter_guid = new Guid("F8388A40-D5BB-11D0-BE5A-0080C706568E");
Type tee_filter_type = Type.GetTypeFromCLSID(tee_filter_guid);
infinitePinTeeFilter = (IBaseFilter)Activator.CreateInstance(tee_filter_type);
hr = gb.AddFilter((IBaseFilter)infinitePinTeeFilter, "Infinite Pin Tee Filter");
infinitePinTeeFilter.FindPin("Input", out infinitePinTeeFilterIn);
infinitePinTeeFilter.FindPin("Output1", out infinitePinTeeFilterOut1);
infinitePinTeeFilter.FindPin("Output2", out infinitePinTeeFilterOut2);
infinitePinTeeFilter.FindPin("Output3", out infinitePinTeeFilterOut3);
DsError.ThrowExceptionForHR(hr);
// Connect the audio decoder to the infinite pin tee
gb.Connect(dshow_audio_decoderOut, infinitePinTeeFilterIn);
Guid logitech_earphone_guid = new Guid("E30629D1-27E5-11CE-875D-00608CB78066");
Type earphone_type = Type.GetTypeFromCLSID(logitech_earphone_guid);
logitech_earphone_headset = (IBaseFilter)Activator.CreateInstance(earphone_type);
hr = gb.AddFilter((IBaseFilter)logitech_earphone_headset, "Headset Earphone (Logitech USB Headset)");
logitech_earphone_headset.FindPin("Audio Input pin (rendered)", out logitech_earphone_headsetIn);
DsError.ThrowExceptionForHR(hr);
// Connect the infinite pin tee to first headphone through Output1
gb.Connect(infinitePinTeeFilterOut1, logitech_earphone_headsetIn);
Guid logitech3_earphone_guid = new Guid("E30629D1-27E5-11CE-875D-00608CB78066");
Type logitech3_earphone_type = Type.GetTypeFromCLSID(logitech3_earphone_guid);
logitech3_earphone_headset = (IBaseFilter)Activator.CreateInstance(logitech3_earphone_type);
hr = gb.AddFilter((IBaseFilter)logitech3_earphone_headset, "Headset Earphone (3- Logitech USB Headset)");
logitech3_earphone_headset.FindPin("Audio Input pin (rendered)", out logitech3_earphone_headsetIn);
DsError.ThrowExceptionForHR(hr);
// Connect the infinite pin tee to second headphone through Output2
gb.Connect(infinitePinTeeFilterOut2, logitech3_earphone_headsetIn);
Guid sigmatel_speakers_guid = new Guid("E30629D1-27E5-11CE-875D-00608CB78066");
Type sigmatel_speakers_type = Type.GetTypeFromCLSID(sigmatel_speakers_guid);
sigmatel_speakers_headset = (IBaseFilter)Activator.CreateInstance(sigmatel_speakers_type);
hr = gb.AddFilter((IBaseFilter)sigmatel_speakers_headset, "Speakers (Sigma Tel High Definition Audio CODEC)");
sigmatel_speakers_headset.FindPin("Audio Input pin (rendered)", out sigmatel_speakers_headsetIn);
DsError.ThrowExceptionForHR(hr);
// Connect the infinite pin tee to sigmatel speakers through Output3
gb.Connect(infinitePinTeeFilterOut3, sigmatel_speakers_headsetIn);
// use Intelligent connect to build the rest of the graph
hr = gb.RenderFile( fileName + fExt, null );
DsError.ThrowExceptionForHR( hr );
mc = (IMediaControl)gb;
me = (IMediaEventEx)gb;
hr = me.SetNotifyWindow(this.Handle, WM_GRAPHNOTIFY, IntPtr.Zero);
DsError.ThrowExceptionForHR( hr );
// DD For debugging, adds the graph to the ROT table
rot = new DsROTEntry(gb);
// we are ready to convert
hr = mc.Run();
DsError.ThrowExceptionForHR( hr );
}
catch( Exception ex )
{
MessageBox.Show( "Error converting to mvk: " + ex.Message );
}
}
int WM_GRAPHNOTIFY = 0x00008001;
protected override void WndProc( ref Message m )
{
if( m.Msg == WM_GRAPHNOTIFY )
{
IntPtr p1 = Marshal.AllocCoTaskMem(4);
IntPtr p2 = Marshal.AllocCoTaskMem(4);
EventCode code;
if (me == null)
return;
while (me.GetEvent(out code, out p1, out p2, 0) == 0)
{
if( code == EventCode.Complete )
{
label1.Text = "done";
button1.Enabled = true;
mc.Stop();
}
me.FreeEventParams( code, p1, p2 );
Marshal.FreeCoTaskMem(p1);
Marshal.FreeCoTaskMem(p2);
}
return;
}
base.WndProc( ref m );
}
}
GrizMan
|
|
|
|
|
Try the following. I marked the changes I made with "jl - " so you can what was causing the problems. Also, the reason you're not able to connect to the remote graph in GraphEdit is most likely because you have the wrong version for Vista. I explain why this is, in the article http://www.codeproject.com/cs/media/dsgraphedit.asp [^] in the section "Known Issues". Hope this helps.
void Convert2Wav()
{
IPin mp3_file_sourceOut = null;
IPin mpg_stream_splitterIn = null, mpg_stream_splitterOut = null;
IPin dshow_audio_decoderIn = null, dshow_audio_decoderOut = null;
IPin infinitePinTeeFilterIn = null, infinitePinTeeFilterOut1 = null;
IPin infinitePinTeeFilterOut2 = null, infinitePinTeeFilterOut3 = null;
IPin logitech_earphone_headsetIn = null;
IPin logitech3_earphone_headsetIn = null;
IPin sigmatel_speakers_headsetIn = null;
try
{
string fileName = fName;
hr = gb.AddSourceFilter(fName + fExt, fName, out mp3_file_source);
DsError.ThrowExceptionForHR(hr);
mp3_file_source.FindPin("Output", out mp3_file_sourceOut);
Guid splitter_guid = new Guid("336475D0-942A-11CE-A870-00AA002FEAB5");
Type splitter_type = Type.GetTypeFromCLSID(splitter_guid);
mpg_stream_splitter = (IBaseFilter)Activator.CreateInstance(splitter_type);
hr = gb.AddFilter((IBaseFilter)mpg_stream_splitter, "MPEG 1 Stream Splitter");
mpg_stream_splitter.FindPin("Input", out mpg_stream_splitterIn);
DsError.ThrowExceptionForHR(hr);
gb.Connect(mp3_file_sourceOut, mpg_stream_splitterIn);
mpg_stream_splitter.FindPin("Audio", out mpg_stream_splitterOut);
Guid decoder_guid = new Guid("0F40E1E5-4F79-4988-B1A9-CC98794E6B55");
Type decoder_type = Type.GetTypeFromCLSID(decoder_guid);
dshow_audio_decoder = (IBaseFilter)Activator.CreateInstance(decoder_type);
hr = gb.AddFilter((IBaseFilter)dshow_audio_decoder, "ffdshow Audio Decoder 0001");
dshow_audio_decoder.FindPin("In", out dshow_audio_decoderIn);
dshow_audio_decoder.FindPin("Out", out dshow_audio_decoderOut);
DsError.ThrowExceptionForHR(hr);
gb.Connect(mpg_stream_splitterOut, dshow_audio_decoderIn);
Guid tee_filter_guid = new Guid("F8388A40-D5BB-11D0-BE5A-0080C706568E");
Type tee_filter_type = Type.GetTypeFromCLSID(tee_filter_guid);
infinitePinTeeFilter = (IBaseFilter)Activator.CreateInstance(tee_filter_type);
hr = gb.AddFilter((IBaseFilter)infinitePinTeeFilter, "Infinite Pin Tee Filter");
infinitePinTeeFilter.FindPin("Input", out infinitePinTeeFilterIn);
infinitePinTeeFilter.FindPin("Output1", out infinitePinTeeFilterOut1);
DsError.ThrowExceptionForHR(hr);
gb.Connect(dshow_audio_decoderOut, infinitePinTeeFilterIn);
Guid logitech_earphone_guid = new Guid("E30629D1-27E5-11CE-875D-00608CB78066");
Type earphone_type = Type.GetTypeFromCLSID(logitech_earphone_guid);
logitech_earphone_headset = (IBaseFilter)Activator.CreateInstance(earphone_type);
hr = gb.AddFilter((IBaseFilter)logitech_earphone_headset, "Headset Earphone (Logitech USB Headset)");
logitech_earphone_headset.FindPin("Audio Input pin (rendered)", out logitech_earphone_headsetIn);
DsError.ThrowExceptionForHR(hr);
gb.Connect(infinitePinTeeFilterOut1, logitech_earphone_headsetIn);
infinitePinTeeFilter.FindPin("Output2", out infinitePinTeeFilterOut2);
Guid logitech3_earphone_guid = new Guid("E30629D1-27E5-11CE-875D-00608CB78066");
Type logitech3_earphone_type = Type.GetTypeFromCLSID(logitech3_earphone_guid);
logitech3_earphone_headset = (IBaseFilter)Activator.CreateInstance(logitech3_earphone_type);
hr = gb.AddFilter((IBaseFilter)logitech3_earphone_headset, "Headset Earphone (3- Logitech USB Headset)");
logitech3_earphone_headset.FindPin("Audio Input pin (rendered)", out logitech3_earphone_headsetIn);
DsError.ThrowExceptionForHR(hr);
gb.Connect(infinitePinTeeFilterOut2, logitech3_earphone_headsetIn);
infinitePinTeeFilter.FindPin("Output3", out infinitePinTeeFilterOut3);
Guid sigmatel_speakers_guid = new Guid("E30629D1-27E5-11CE-875D-00608CB78066");
Type sigmatel_speakers_type = Type.GetTypeFromCLSID(sigmatel_speakers_guid);
sigmatel_speakers_headset = (IBaseFilter)Activator.CreateInstance(sigmatel_speakers_type);
hr = gb.AddFilter((IBaseFilter)sigmatel_speakers_headset, "Speakers (Sigma Tel High Definition Audio CODEC)");
sigmatel_speakers_headset.FindPin("Audio Input pin (rendered)", out sigmatel_speakers_headsetIn);
DsError.ThrowExceptionForHR(hr);
gb.Connect(infinitePinTeeFilterOut3, sigmatel_speakers_headsetIn);
mc = (IMediaControl)gb;
me = (IMediaEventEx)gb;
hr = me.SetNotifyWindow(this.Handle, WM_GRAPHNOTIFY, IntPtr.Zero);
DsError.ThrowExceptionForHR(hr);
rot = new DsROTEntry(gb);
hr = mc.Run();
DsError.ThrowExceptionForHR(hr);
}
catch (Exception ex)
{
MessageBox.Show("Error converting to mvk: " + ex.Message);
}
}
|
|
|
|
|
In the following code snippet myMath class has five Attributes, the problem which I am facing is that on the console I don't get the Order of the Attributes , right. The attribute with bugID = 1 shows on the top, and strangely it is followed by the fifth attribute bugID = 5, and then 2,3,4.
When I remove the fifth Attribute this is the order of the Attributes 2,1,3,4.
When there are three attributes the behavior is normal as in 1,2,3.
When there are two attributes again the behavior changes to 2,1.
Can Anyone pl. figure out the problem for me
using System.Collections.Generic;
using System;
using System.Linq;
using System.Text;
using System.Reflection;
namespace UsingAttributes
{
[AttributeUsage(AttributeTargets.All,AllowMultiple = true )]
class BugFixAttribute : Attribute
{
private int bugID;
private string coder;
private string date;
private string comment;
public BugFixAttribute(int bugID, string coder, string date)
{
this.bugID = bugID;
this.coder = coder;
this.date = date;
}
public string Comment
{
get
{
return comment;
}
set
{
comment = value;
}
}
public int BugID
{
get
{
return bugID;
}
}
public string Coder
{
get
{
return coder;
}
}
public string Date
{
get
{
return date;
}
}
}
[BugFix(001, "sh", "08/11/2007", Comment = "one")]
[BugFix(002, "sh", "08/11/2007", Comment = "two")]
[BugFix(003, "sh", "08/11/2007", Comment = "three")]
[BugFix(004, "sh", "08/11/2007", Comment = "four")]
[BugFix(005, "sh", "08/11/2007", Comment = "five")]
public class myMath
{
public double DoFunc1(double param1)
{
return param1 + DoFunc2(param1);
}
public double DoFunc2(double param1)
{
return param1 / 3;
}
}
class Program
{
static void Main(string[] args)
{
myMath mm = new myMath();
Console.WriteLine("Result for DoFunc(7) = {0}", mm.DoFunc1(7));
MemberInfo inf = typeof(myMath);
object[] attributes = inf.GetCustomAttributes(typeof(BugFixAttribute), false);
foreach (object attribute in attributes)
{
BugFixAttribute b = attribute as BugFixAttribute;
Console.WriteLine("\nBugID: {0}", b.BugID);
Console.WriteLine("Programmer: {0}", b.Coder);
Console.WriteLine("Date : {0}", b.Date);
Console.WriteLine("Comment: {0}", b.Comment);
}
Console.ReadKey();
}
}
}
Thanx
|
|
|
|
|
AFAIK the call to GetCustomAttributes does not do so in any recognisable order. I have faced a similar issue in the past where the order of arributes was important so I created a custom static method to get my attributes in an ordered fashion.
In your case this could well use the BugID property to order on.
|
|
|
|
|
Jamies entirely right in what he said about retrieving the attributes by order. What you could do is implement a delegate to sort them into order in your reading code.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Or make an attribute collection?
[BugFixAttributeCollection(
new BugFix(001, "sh", "08/11/2007", Comment = "one") ,
new BugFix(002, "sh", "08/11/2007", Comment = "two") ,
new BugFix(003, "sh", "08/11/2007", Comment = "three") ,
new BugFix(004, "sh", "08/11/2007", Comment = "four") ,
new BugFix(005, "sh", "08/11/2007", Comment = "five")
)]
I'd better try it to see whether or not it works...
P.S. Use an ISO 8601 compliant date format.
-- modified at 21:50 Thursday 8th November, 2007
Well it doesn't work as shown above, but I'm getting close...
|
|
|
|
|
I don't suppose you'd want something like this...
[GroupOfAttribute(
"<OneAttribute Num=\"001\" Text=\"sh\" When=\"2007-11-08\" />"
,
"<OneAttribute Num=\"002\" Text=\"sh\" When=\"2007-11-08\" />"
,
"<OneAttribute Num=\"003\" Text=\"sh\" When=\"2007-11-08\" />"
)]
Ugly ugly ugly... error prone and not very typesafe... but it works!
|
|
|
|
|
Hi
I saw from your example that you are using framework 3.0 or above
Try using the follwoing code
List<BugFixAttribute> lst = new List<BugFixAttribute>((IEnumerable<BugFixAttribute> )inf.GetCustomAttributes(typeof(BugFixAttribute), false));
lst.Sort((a, b) => a.BugID < b.BugID ? -1 : 1);
|
|
|
|
|
hi
i use Sql server 2005 reporting Service in my app in local processing mode, in report designer i add a textBox and i want send value from my csharp code to textBox of report, i use this code :
try
{
this.v_customerOrderCountTableAdapter.Fill(this.NorthwindDataSet.v_customerOrderCount);
Microsoft.Reporting.WinForms.ReportParameter rp = new Microsoft.Reporting.WinForms.ReportParameter("textbox5", "Param From Code");
this.reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter[] { rp });
this.reportViewer1.RefreshReport();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
but the following error shown me :
An error occurred during local report processing.
where does my problem and how to send parameters deom my code to report ?
thanks
|
|
|
|
|
Did you add the parameter to the report itself? If the report has parameter called paramater1 and you want to set its value to myvalue then you should do it like this:
<br />
Microsoft.Reporting.WinForms.ReportParameter rp = new Microsoft.Reporting.WinForms.ReportParameter("paramater1", "myvalue");<br />
this.reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter[] { rp });<br />
|
|
|
|
|
i add in a textBox named 'textBox5' to my report in report designer and wrote your code (that like my code), but the above error has shown me.
|
|
|
|
|
It seems that you haven't added the parameter to the report itself
|
|
|
|
|
Hello all,
I have a curious problem relating to XML deserialisation where the deserialiser allows malformed XML to pass through without issue. This needs some further information, so without further ado:
I have the following simple schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="TestSchema">
<xs:complexType>
<xs:sequence>
<xs:element name="Widgets" type="xs:string" nillable="false"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
From this I have created .NET 2 c# classes using the XSD tool, this result in the following class
using System.Xml.Serialization;
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class TestSchema {
private string widgetsField;
public string Widgets {
get {
return this.widgetsField;
}
set {
this.widgetsField = value;
}
}
}
This is then added to a simple test project that looks like this:
static void Main(string[] args)
{
string rawXml = "<TestSchema>";
rawXml += "<Widgets>A value for widgets</Widgets>";
rawXml += "<LaLa>An element that doesnt exist in the schema</LaLa>";
rawXml += "</TestSchema>";
byte[] data = System.Text.Encoding.ASCII.GetBytes(rawXml);
MemoryStream fs = new MemoryStream(data);
TextReader reader = new StreamReader(fs);
XmlSerializer ser = new XmlSerializer(typeof(TestSchema));
TestSchema obj = (TestSchema)ser.Deserialize(reader);
reader.Close();
Console.WriteLine(obj.GetHashCode());
Console.ReadLine();
}
Now all this works, however I wouldn't expect it to! The more eagled eyed will have noticed the following line in the code above:
rawXml += "<LaLa>An element that doesnt exist in the schema</LaLa>";
When the deserialiser is processing the XML string, it seems that any elements that are not in the C# schema class are simply ignored. So the first question is, does anybody know of a way to run the deserialiser in "strict" mode, so that if an unknown element is present then an exception occurs.
When testing different scenarios I also discovered that I could remove a nillable false element and still deserialise, which resulted in the object value being, obviously, null. For example :
string rawXml = "<TestSchema>";
rawXml += "</TestSchema>";
or
string rawXml = "<TestSchema>";
rawXml += "<LaLa>Hold on whats this an element that doesnt exist in the schema</LaLa>";
rawXml += "</TestSchema>";
So the second questions is, is there any way to run the deserialiser in "strict" mode where if a mandatory/nillable false element is not found and exception occurs.
An immediately obvious solution to this problem is to pass the XML through a validator first and then perform the deserialisation. While this will work, in the real world the application is processing alot of XML data and having to validate every one will add to processing time. I would prefer to only validate if a deserialisation exception occurs.
-- modified at 10:31 Thursday 8th November, 2007
|
|
|
|
|
It would seem I have found the solution, a tweak to the code above and malformed XML is no longer allowed:
static void Main(string[] args)
{
string rawXml = "<TestSchema>";
rawXml += "<Widgets>A value for widgets</Widgets>";
rawXml += "<LaLa>Hold on whats this an element that doesnt exist in the schema</LaLa>";
rawXml += "</TestSchema>";
XmlSerializer s = new XmlSerializer(typeof(TestSchema));
byte[] buffer = ASCIIEncoding.UTF8.GetBytes(rawXml);
MemoryStream ms = new MemoryStream(buffer);
XmlReader reader = new XmlTextReader(ms);
XmlDeserializationEvents deserializationEvents = new XmlDeserializationEvents();
deserializationEvents.OnUnknownAttribute = new XmlAttributeEventHandler(UnknownAttributeEventHandler);
deserializationEvents.OnUnknownElement = new XmlElementEventHandler(UnknownElementEventHandler);
deserializationEvents.OnUnknownNode = new XmlNodeEventHandler(UnknownNodeEventHandler);
deserializationEvents.OnUnreferencedObject = new UnreferencedObjectEventHandler(UnreferencedObjEventHandler);
TestSchema obj = (TestSchema)s.Deserialize(reader, deserializationEvents);
reader.Close();
Console.WriteLine(obj.GetHashCode());
Console.ReadLine();
}
private static void UnknownAttributeEventHandler(object sender, XmlAttributeEventArgs e)
{
}
private static void UnknownElementEventHandler(object sender, XmlElementEventArgs e)
{
}
private static void UnknownNodeEventHandler(object sender, XmlNodeEventArgs e)
{
}
private static void UnreferencedObjEventHandler(object sender, UnreferencedObjectEventArgs e)
{
}
As you can see in the code above, the XmlSerializer.Deserialize can also take an instance of XmlDeserializationEvents. If this is setup and passed in these events are created and from there I can handle the error condition.
|
|
|
|
|
Good to know... thanks for posting that!
|
|
|
|
|
Since posting the original solution I have found that you can also set these event directly on the XmlSerializer
XmlSerializer xmlSerializer = new XmlSerializer(objectType);
xmlSerializer.UnknownAttribute += new XmlAttributeEventHandler(xmlSerializer_UnknownAttribute);
xmlSerializer.UnknownElement += new XmlElementEventHandler(xmlSerializer_UnknownElement);
xmlSerializer.UnknownNode += new XmlNodeEventHandler(xmlSerializer_UnknownNode);
xmlSerializer.UnreferencedObject += new UnreferencedObjectEventHandler(xmlSerializer_UnreferencedObject);
From a functionality point of view I don't suppose it makes any difference at all, however IMHO this method is neater.
|
|
|
|
|
hello,
un have 2 application and i send messages between them using named pipes technologie;
i send 2 messages , the first for showing the application and the second for hiding it;
the probleme is before sending the messages i have to know the state of application (show/hide).
how can i know the state of my second application?
|
|
|
|
|
You'll need a method that queries the state of the second application.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
whitch method do you talking about? i can figure out
please help
|
|
|
|
|
A method which you have to write in order to figure out the state of the application !
AliAmjad(MCP)
First make it Run THEN make it Run Fast.
|
|
|
|
|
i m so sorry, but i dont understand what do you mean,
i want to know can i know the state of a dialog or application (hide/show) ?
if yes , how?
thanks
|
|
|
|
|