Click here to Skip to main content
15,888,579 members
Home / Discussions / C#
   

C#

 
GeneralRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Member 1212766512-Nov-15 2:58
Member 1212766512-Nov-15 2:58 
AnswerRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Richard Andrew x6412-Nov-15 3:08
professionalRichard Andrew x6412-Nov-15 3:08 
AnswerRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Bernhard Hiller12-Nov-15 4:12
Bernhard Hiller12-Nov-15 4:12 
GeneralRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
BillWoodruff12-Nov-15 5:45
professionalBillWoodruff12-Nov-15 5:45 
AnswerRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
BillWoodruff12-Nov-15 6:03
professionalBillWoodruff12-Nov-15 6:03 
AnswerRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Member 1212766512-Nov-15 21:26
Member 1212766512-Nov-15 21:26 
Questionrun file with associated extension in current instance (ddeexec?) Pin
robinsc10-Nov-15 9:51
robinsc10-Nov-15 9:51 
AnswerRe: run file with associated extension in current instance (ddeexec?) Pin
John Torjo10-Nov-15 10:21
professionalJohn Torjo10-Nov-15 10:21 
I don't think it's possible. Anyway, long story short - that's not the way to do it.
It's your job to find out if another instance is running, and if so, to notify it. It's not an easy task though. There's quite a bit of code required to do this. Namely, first find out if another instance of your app is running, and if so, you need to notify it and send it the new file to open.

More or less, something like this:

C#
// step 1 - win32 api functions used
[StructLayout(LayoutKind.Sequential)]
public struct COPYDATASTRUCT {
  public IntPtr dwData;
  public int cbData;
  [MarshalAs(UnmanagedType.LPStr)] public string lpData;
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);

public const int WM_COPYDATA = 0x004A;

...

// step 2 - in your Main()
var running_already = Process.GetProcessesByName("Yourapp").ToDictionary(x => x.Id, x => x);
running_already.Remove(Process.GetCurrentProcess().Id);
if (running_already.Count > 0) {
    // there's another instance running
    if (args.Length == 0)
        // just let the other instance run
        return;
    // for the other instance - what to open
    string open = args[0];

    var cds = new win32.COPYDATASTRUCT {
        dwData = new IntPtr(0),
        cbData = open.Length * 2 + 1,
        lpData = open
    };
    var handle = running_already.First().Value.MainWindowHandle;
    win32.SendMessage(handle, win32.WM_COPYDATA, IntPtr.Zero, ref cds);
    return;
}

// step 3 - in your main window
protected override void WndProc(ref Message m) {
	if (m.Msg == win32.WM_COPYDATA) {
		var st = (win32.COPYDATASTRUCT) Marshal.PtrToStructure(m.LParam, typeof (win32.COPYDATASTRUCT));
		string open = st.lpData;
		util.postpone(() => on_file_drop(open), 100);
	}

	base.WndProc(ref m);
}

-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!

GeneralRe: run file with associated extension in current instance (ddeexec?) Pin
robinsc10-Nov-15 11:10
robinsc10-Nov-15 11:10 
GeneralRe: run file with associated extension in current instance (ddeexec?) Pin
John Torjo10-Nov-15 11:31
professionalJohn Torjo10-Nov-15 11:31 
GeneralRe: run file with associated extension in current instance (ddeexec?) Pin
Eddy Vluggen10-Nov-15 14:22
professionalEddy Vluggen10-Nov-15 14:22 
GeneralRe: run file with associated extension in current instance (ddeexec?) Pin
John Torjo11-Nov-15 4:15
professionalJohn Torjo11-Nov-15 4:15 
AnswerRe: run file with associated extension in current instance (ddeexec?) Pin
Bernhard Hiller12-Nov-15 4:16
Bernhard Hiller12-Nov-15 4:16 
QuestionWindows App for NGO Pin
COder87610-Nov-15 7:01
COder87610-Nov-15 7:01 
AnswerRe: Windows App for NGO Pin
Gerry Schmitz10-Nov-15 8:00
mveGerry Schmitz10-Nov-15 8:00 
AnswerRe: Windows App for NGO Pin
Richard MacCutchan10-Nov-15 8:39
mveRichard MacCutchan10-Nov-15 8:39 
AnswerRe: Windows App for NGO Pin
BillWoodruff10-Nov-15 14:32
professionalBillWoodruff10-Nov-15 14:32 
QuestionMissingManifestResourceException Pin
Rob Shields10-Nov-15 2:58
Rob Shields10-Nov-15 2:58 
AnswerRe: MissingManifestResourceException Pin
OriginalGriff10-Nov-15 3:32
mveOriginalGriff10-Nov-15 3:32 
AnswerRe: MissingManifestResourceException Pin
phil.o10-Nov-15 4:54
professionalphil.o10-Nov-15 4:54 
Questionhow to get Image from DataSet Pin
goldsoft10-Nov-15 0:29
goldsoft10-Nov-15 0:29 
AnswerRe: how to get Image from DataSet Pin
John Torjo10-Nov-15 0:40
professionalJohn Torjo10-Nov-15 0:40 
GeneralRe: how to get Image from DataSet Pin
goldsoft10-Nov-15 1:02
goldsoft10-Nov-15 1:02 
GeneralRe: how to get Image from DataSet Pin
John Torjo10-Nov-15 4:07
professionalJohn Torjo10-Nov-15 4:07 
QuestionHow to get data(json) to listview by MVVM? Pin
Lê Thiên Hoàng8-Nov-15 14:08
Lê Thiên Hoàng8-Nov-15 14:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.