|
You can try this :
using (FileStream fs = new FileStream(last_save_location, FileMode.Append, FileAccess.Write))
{
fs.Write(message, 8, bytesRead - 8);
fs.Close();
}
I know nothing , I know nothing ...
|
|
|
|
|
Almost always, this is because the log is being called twice, from different threads, in a shorter period than the file takes to open and close. Synchronise the file calls (that is, put a lock block around them).
|
|
|
|
|
hi
i have two forms form1 and form2 i have two btns in form1 if i clik btn1 of form1 btn2 of form1 turns green and form2 opns and form1 hides and if i clk the btn from form2 form1 opns but it do not save the previous values means btn2 of form1 is not green this time. how can i save the previous value.
thanks
|
|
|
|
|
It sounds like in form2 you are creating a new instance of form1 rather than unhiding the existing instance.
|
|
|
|
|
yes m creating the new instance but how can i unhide the existing instance?
|
|
|
|
|
See my reply below for an alternative to the one already given and reasons why it may be a better way.
|
|
|
|
|
That's easy , have no worries
Form1 Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form2 form2;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (form2 == null)
{
form2 = new Form2(this);
form2.Show();
}
else
{
form2.Show();
}
this.Hide();
button2.BackColor = Color.Green;
}
}
}
Form2 Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form form1;
public Form2(Form form1)
{
InitializeComponent();
this.form1 = form1;
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (form1 == null)
{
form1 = new Form();
form1.Show();
}
else
{
form1.Show();
}
this.Hide();
}
}
}
Form1 Is The Main Form
I know nothing , I know nothing ...
|
|
|
|
|
thanks u hve solved my problm 
|
|
|
|
|
You welcome , and don't forget to vote for me
I know nothing , I know nothing ...
|
|
|
|
|
You do realise that trolling for votes will only get people downvoting you don't you?
|
|
|
|
|
The solution given works as you have seen BUT it is not generally recommended as now your Form2 is coupled to Form1 , coupling is generally not a good idea.
A better solution is for Form1 to control everything, and Form2 to raise an event to inform Form1 that the button has been clicked:
public partial class Form1 : Form
{
private Form2 form2;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (form2 == null)
{
form2 = new Form2();
form2.ButtonClicked += new EventHandler(form2_ButtonClicked);
form2.FormClosing += new FormClosingEventHandler(form2_FormClosing);
}
form2.Show();
Hide();
button2.BackColor = Color.Green;
}
private void form2_ButtonClicked(object sender, EventArgs e)
{
Show();
form2.Hide();
}
private void form2_FormClosing(object sender, FormClosingEventArgs e)
{
form2.ButtonClicked -= form2_ButtonClicked;
form2.FormClosing -= form2_FormClosing;
form2 = null;
if (!Visible)
Close();
}
}
public partial class Form2 : Form
{
public event EventHandler ButtonClicked;
public Form2()
{
InitializeComponent();
}
protected virtual void OnButtonClicked(EventArgs e)
{
EventHandler eh = ButtonClicked;
if (eh != null)
eh(this, e);
}
private void button1_Click(object sender, EventArgs e)
{
OnButtonClicked(EventArgs.Empty);
}
}
|
|
|
|
|
|
How can I transcribe a Matlab image processing program (.m files) in C#?
|
|
|
|
|
It's a big question , you need to but your self , at some tutorials
I recommended to start from Here[^]
I know nothing , I know nothing ...
|
|
|
|
|
If you're looking to convert the code from Matlab to C#, you'll have to rewrite it from scratch, by hand. I don't know of any conversion tool that will do it for you.
|
|
|
|
|
|
Given that this is the C# forum, I'm going to say "no".
Mainly because the link doesn't refer to C# code, but C++.
You can't use that code in C#, and you shouldn't use it in C++ because - as it says at the top of the article - the function that refers to it has been superseded...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
OriginalGriff wrote: You can't use that code in C#
You sure?
[DllImport("user32", SetLastError = true, CharSet = CharSet.Auto)]
static extern bool InsertMenu(IntPtr hmenu, uint position, uint flags,
uint item_id, [MarshalAs(UnmanagedType.LPTStr)]string item_text);
|
|
|
|
|
Yes, ok, Mr Picky!
I was trying to simplify for a beginner that he was going the wrong way...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
OriginalGriff wrote: as it says at the top of the article - the function that refers to it has been
superseded...
Not entirely... keep reading the statement.
You can still use InsertMenu, however, if you do not need any of the extended features of InsertMenuItem.
|
|
|
|
|
You need more API functions than "InsertMenu" for Manipulating the System Menu Using C#
So Here you go Simple Class to do this[^]
I know nothing , I know nothing ...
|
|
|
|
|
I am trying to use any DLL in Windows 7 64 bit version. It give me exception "BadImageFormatException was unhandled". The same .dll works fine with Windows XP. The .dll was written in ASM and built using AnyCPU platform.
Here is the call in project:
[DllImport("library.dll")] static extern bool MyFunction(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
Anyone has come across it, is there a way to resolve it?
Best regards.
|
|
|
|
|
Here are some facts relating to 32/64 bit code:
1.
When you build a native-code DLL, you must decide whether you want it to use the 32-bit or the 64-bit architecture, which are both supported by most modern Intel/AMD processors.
2.
When you build a managed code DLL or EXE, you can choose between 32-bit, 64-bit, or automatic ("AnyCPU"). With 32-bit or 64-bit, it is the EXE itself that enforces the execution mode; with "AnyCPU" the EXE will run in 32-bit execution on 32-bit Windows, and in 64-bit execution on 64-bit Windows.
3.
And you can't mix 32-bit and 64-bit code in a single process, Windows simply doesn't allow a mode switch in mid execution, so the DLLs must match the EXE's mode (AnyCPU DLLs are always fine, the other managed ones and all unmanaged ones must match).
Assembly code is native code obviously, and 64-bit and 32-bit assembly source files look quite different, as the programming model is not the same at all. So I guess your "ASM DLL" really is a 32-bit beast, notwithstanding the fact that you created it on a 64-bit Win7 system.
So you could use your 32-bit native DLL, and use it on any 32-bit operating system (with a managed EXE built for x86 or for AnyCPU); or use it on a 64-bit OS with a managed EXE built for x86 (but not for "AnyCPU" as that would start in 64-bit mode and then fail to reference the DLL code).
In practice, you could simply rebuild the app (the EXE part should suffice) for x86, see the project properties. There also is a hack using CORFLAGS, which basically would alter the properties of an existing EXE file (not recommended when you have the source code anyhow).
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Saturday, April 30, 2011 5:16 PM
|
|
|
|
|
I tried to build my project as "AnyCPU", x86 and 64 bit, results are always the same: "BadImageFormatException was unhandled".
According to the guideline, I used CORFLAGS. After call: CorFlags.exe library.dll I have:
Error CF008 : The specified file does not have a valid managed header.
|
|
|
|
|
The compiler is expecting a managed library: did you add the library.dll to your project references? You should not do that if the library is native (non managed), the DllImport line should suffice.
|
|
|
|