|
Hi #realJSOP,
I have declared that object STATIC inside a form that is alive untill the app is closed, why it is not enough?
Thanks
|
|
|
|
|
I am not sure if I understand this. What I meant was that if I create a static object on the form, it has to be alive until that form (not application) is.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
When the modal form goes out of scope (closes), you can't access anything declared inside it because the form is no longer available/in scope.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Clear.
The form is used only to update date and time, it doesn't store any information.
|
|
|
|
|
Declare an EXTERNAL static class that the form can access
public static class Globals
{
public static MyDateTime { get; set; }
} In your form, when you close it:
Globals.MyDateTime = DateTime.Now;
When your form closes, examine Globals.MyDateTime to ensure it's the expected value.
The next time you open the form, the value will be the same as the last time you opened the form, and when you close it agaim, set Globals.MyDateTime again.
The Globals.DateTime will be available everywhere else in the app as well.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Thanks for the sample #realJSOP.
Actually I don't need to save the exact moment the form is closed.
This form is used to give the user the possibility to change the time and/or the date of the device (Windows CE based) on which the app is running and it is not used to change a variable used somewere else in the app.
So I declared an external static class and in this class I declared my form instance:
public static class Cl_Forms
{
public static FormDateTime Suc3 = new FormDateTime();
}
As you suggest, in this way the form shown in a modal way should be static and should not be disposed until the app is running.
Now I'm testing this solution.
Unfortunately the exception occurred rarely and randomly and it was not easy to reproduce it.
|
|
|
|
|
Yes, that is what I said as well.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
Sorry, I was not clear.
I understood what you said, FormMain, in wich I declared a FormDateTime instance, is always in the background and is never closed.
|
|
|
|
|
I have no idea what you really want. I told you to make the form modelss so it never disposes, and you said it can't be modelss. Then I suggested that you make abn external statuic class because you wanted the form to be model. WTF do you actually want to do?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I want to understand.
I have made what you suggested and now my app is running with the form instance declared in a static class, sometime I push buttons to see if I get the exception.
But I wanted to know why this is better considering that I had declared the form static instance inside a form that is never closed until the application is running.
WTF...
|
|
|
|
|
Can you post the complete error message? You say it works sometimes and sometimes does not, makes it tough to respond to.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
Thank you lw@zi,
here is the complete error message:
Error
sa7.exe
ObjectDisposedException
at Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar)
at System.Windows.Forms.Control.get_Visible()
at System.Windows.Forms.Form.ShowDialog()
at SA7.SetupHome_UC.DateTimeBt_Click(Object senter, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at BeeMobile.TransparentControls.TImageButton.OnClick(EventArgs e)
at System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 IParam)
at System.Windows.Forms.ContainerControl.WnProc(WM wm, Int32 wParam, Int32 IParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 IParam)
at Microsoft.AGL.Form.EVL.EnterMainLoop(IntPtr hwnMain)
at System.Windows.Forms.Application.Run(Form fm)
at SAT.Program.Main()
|
|
|
|
|
What controls do you have on the form? Ones which are directly on the Form i.e controls whose parent is the form. And you are disposing anything on the form? Perhaps posting the code on the form may help.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
In the form there are:
3 BeeMobile.TransparentControls.TImageButton
2 BeeMobile.TransparentControls.TLabel
2 BeeMobile.RoundTextBox.RoundTextBox
1 BeeMobile.MonthCalendar.MonthCalendar
1 BeeMobile.iWheel.iWheel
2 System.Windows.Forms.Timer
For what I know, I do not dispose any control voluntarily...
Here is the code on the form:
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using LangD = SA7.Cl_LangData;
using Gr = SA7.Cl_Graphics;
using Globals = SA7.Cl_Globals;
namespace SA7
{
public partial class FormDateTime : Form
{
private bool FormDateTime_FirstShow = true;
Cl_DateTime Tempo = new Cl_DateTime();
public struct SYSTEMTIME
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
[DllImport("coredll.dll")]
private extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);
[DllImport("coredll.dll")]
private extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);
public FormDateTime()
{
InitializeComponent();
this.Location = new Point((800 - this.Width) / 2, (480 - this.Height) / 2);
}
private void FormDateTime_Load(object sender, EventArgs e)
{
if (FormDateTime_FirstShow) {
FormDateTime_FirstShow = false;
}
CtrlsDesc();
UpdateDateTime();
ExitTr.Enabled = true;
}
private void FormDateTime_Paint(object sender, PaintEventArgs e)
{
Gr.DrawFrContour(e, 0, 1, 1, this.Width - 1, this.Height - 1);
}
public void CtrlsDesc()
{
AbortBt.Text = FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinExit);
UpdateBt.Text = FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinUpadateTime);
DateLb.Text = FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinDate);
TimeLb.Text = FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinTime);
OKVBt.Text = FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinOK);
}
private void UpdateDateTime()
{
DateTime tmp;
tmp = DateTime.Now;
DateRTB.Text = string.Format("{0:00} {1} {2}", tmp.Day, GetMonthStr(tmp.Month), tmp.Year);
TimeRTB.Text = string.Format("{0:00}:{1:00}:{2:00}", tmp.Hour, tmp.Minute, tmp.Second);
UpdateDate();
UpdateTime();
}
private void UpdateDate()
{
DateTime tmp;
tmp = DateTime.Now;
MonthCalendar.CurrentMonth = tmp;
MonthCalendar.SelectedDate = tmp;
}
private void UpdateTime()
{
DateTime tmp;
tmp = DateTime.Now;
((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[0]).SelectedIndex = tmp.Hour;
((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[1]).SelectedIndex = tmp.Minute;
((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[2]).SelectedIndex = tmp.Second;
}
private string GetMonthStr(Int32 mese)
{
switch (mese)
{
case 1:
return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinGen);
case 2:
return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinFeb);
case 3:
return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinMaz);
case 4:
return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinApr);
case 5:
return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinMag);
case 6:
return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinGiu);
case 7:
return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinLug);
case 8:
return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinAgo);
case 9:
return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinSet);
case 10:
return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinOtt);
case 11:
return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinNov);
case 12:
return FormMain.LF.GetStr(LangD.LANG_Win, LangD.LANG_WinDic);
default:
break;
}
return "";
}
private void UpdateBt_Click(object sender, EventArgs e)
{
DateTime tmp;
ExitTr.Interval = Globals.EXIT_TR_TIME;
SYSTEMTIME systime = new SYSTEMTIME();
GetSystemTime(ref systime);
tmp = DateTime.Parse(string.Format("{0:00}/{1:00}/{2:00} {3:00}:{4:00}:{5:00}", MonthCalendar.SelectedDate.Month, MonthCalendar.SelectedDate.Day, MonthCalendar.SelectedDate.Year, ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[0]).SelectedIndex, ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[1]).SelectedIndex, ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[2]).SelectedIndex));
tmp = tmp.ToUniversalTime();
systime.wDay = (short)tmp.Day;
systime.wMonth = (short)tmp.Month;
systime.wYear = (short)tmp.Year;
systime.wHour = (short)tmp.Hour;
systime.wMinute = (short)tmp.Minute;
systime.wSecond = (short)tmp.Second;
SetSystemTime(ref systime);
UpdateTr.Enabled = true;
}
private void UpdateTr_Tick(object sender, EventArgs e)
{
UpdateTr.Enabled = false;
Close();
}
private void AbortBt_Click(object sender, EventArgs e)
{
ExitTr.Enabled = false;
Close();
}
private void OKVBt_Click(object sender, EventArgs e)
{
ExitTr.Interval = Globals.EXIT_TR_TIME;
TimeRTB.Text = string.Format("{0:00}:{1:00}:{2:00}", ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[0]).SelectedIndex, ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[1]).SelectedIndex, ((BeeMobile.iWheel.TextCylinder)TimeIW.Cylinders[2]).SelectedIndex);
DateLb.Visible = true;
TimeLb.Visible = true;
DateRTB.Visible = true;
TimeRTB.Visible = true;
AbortBt.Visible = true;
UpdateBt.Visible = true;
MonthCalendar.Visible = false;
TimeIW.Visible = false;
OKVBt.Visible = false;
}
private void MonthCalendar_SelectedDateChanged(object sender, EventArgs e)
{
ExitTr.Interval = Globals.EXIT_TR_TIME;
MonthCalendar.Visible = false;
DateRTB.Text = String.Format("{0:00} {1} {2}", MonthCalendar.SelectedDate.Day, GetMonthStr(MonthCalendar.SelectedDate.Month), MonthCalendar.SelectedDate.Year);
DateLb.Visible = true;
TimeLb.Visible = true;
DateRTB.Visible = true;
AbortBt.Visible = true;
UpdateBt.Visible = true;
TimeIW.Visible = false;
OKVBt.Visible = false;
TimeRTB.Visible = true;
}
private void TimeRTB_Click(object sender, EventArgs e)
{
ExitTr.Interval = Globals.EXIT_TR_TIME;
UpdateTime();
DateLb.Visible = false;
TimeLb.Visible = false;
DateRTB.Visible = false;
TimeRTB.Visible = false;
AbortBt.Visible = false;
UpdateBt.Visible = false;
MonthCalendar.Visible = false;
TimeIW.Visible = true;
OKVBt.Visible = true;
}
private void DateRTB_Click(object sender, EventArgs e)
{
ExitTr.Interval = Globals.EXIT_TR_TIME;
UpdateDate();
DateLb.Visible = false;
TimeLb.Visible = false;
DateRTB.Visible = false;
TimeRTB.Visible = false;
AbortBt.Visible = false;
UpdateBt.Visible = false;
TimeIW.Visible = false;
OKVBt.Visible = false;
MonthCalendar.Visible = true;
}
private void FormDateTime_Click(object sender, EventArgs e)
{
ExitTr.Interval = Globals.EXIT_TR_TIME;
}
private void ExitTr_Tick(object sender, EventArgs e)
{
ExitTr.Enabled = false;
Close();
}
}
}
The timer ExitTr is used to close the form if the user lets the form opened without doing anything for some time. It is started at the form show.
The timer UpdateTr is used to close the form with a short delay.
Now that I copy here my code I notice that when I close the form in UpdateTr I don't stop the running timer ExitTr, this could be a problem?
|
|
|
|
|
Hi guys, im trying to use TranslateMessage to send a key to a external program, but im not having success so far..
My code is following:
[DllImport("user32.dll")]
static extern bool TranslateMessage([In] ref MSG lpMsg);
const int WM_KEYDOWN = 0x0100;
const int WM_KEYUP = 0x0101;
public struct MSG
{
public IntPtr hwnd;
public uint message;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public POINT pt;
}
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
}
static void Main(string[] args)
{
Thread.Sleep(3000);
MSG m = new MSG();
m.message = 0x0D;
m.wParam = (IntPtr)WM_KEYDOWN;
m.pt = new POINT();
m.time = 0;
bool p = TranslateMessage(ref m);
}
as you can see im trying to send enter key for example but it does nothing..
thanks in advance
|
|
|
|
|
|
Thanks for answer
The problem is that Postmessage, sendmessage, keybd_event, sendkeys are blocked in this game.
The only thing I have left is to use TranslateMessage but I cant make it work to send a key press
|
|
|
|
|
As the documentation clearly states, TranslateMessage cannot be used to send a message to another program.
If the external program prevents you from sending messages to it, then you can't send messages to it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Translate message does what the name suggests: you provide it with a message and it translates it an places the result back onto the same thread message queue. It can't be used to send messages to a different process, because (if nothing else) it doesn't have any means to tell it which process to feed the translated message to.
If a game has messages blocked, there's probably a reason: normally to prevent people from cheating.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Previously, our software had to be created for both 32bit and 64bit Windows. Now, product management decided that we do not need to support 32bit Windows anymore (that's great with regard to third party SDKs and drivers).
In almost all of our some 200 projects, the DEBUG and RELEASE configurations have the "Platform target" of "Any CPU" only (only some wrappers of third party components are specialized). Of course, the software will run on 64bit systems with such settings.
But compiling for 64bit only could allow for more compiler optimizations (or am I mistaken?), so I'd prefer to create 64bit executables.
As shown in How do I specify the platform for MSBuild? - Stack Overflow[^] , there is no possibility to simply add a parameter to the msbuild command line, instead every project has to be changed...
What's the easiest way to do so? Or do I not need to care because there's no advantage in doing so?
Note: we use C# with Visual Studio Professional 2015 Version 14.0.25425.01 Update 3.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
One way to do that is to write an app to modify the .csproj files: they are XML, and contain the Platform:
<PlatformTarget>AnyCPU</PlatformTarget>
It wouldn't take much to knock up a quick app to convert all 200.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Bernhard Hiller wrote: But compiling for 64bit only could allow for more compiler optimizations (or am I mistaken?), so I'd prefer to create 64bit executables. Not really, the compiler doesn't do anything special, it just sets that flag on the binary (which can be modified later, by the way). What matters is the bitness at which the program actually runs. To the C# compiler, "optimization" means simple things such as using fewer temporary variables and branching directly on a condition instead of constructing a boolean out of it and then testing it, that sort of thing.
There are various optimizations that you can do though:
- Drop 32bit versions of dependencies and drop the release that uses them. Sounds like that's the plan.
- Write code that explicitly assumes pointers are 8 bytes (doesn't come up a lot in C# obviously, but you can do it).
- In 32bit mode, FP math gets done with x87 instructions, occasionally this required some workarounds to deal with 80bit/64bit precision mismatches, all of that nonsense can be removed. Most projects didn't bother with this in the first place.
- Boldly using System.Numerics.Vectors all over the place, which is fast (well, some parts of it are fast, definitely double check) in 64bit mode but worse than pointless in 32bit mode.
- Using things from System.Runtime.Intrinsics with X64 in the name, such as System.Runtime.Intrinsics.X86.Sse.X64, without checking
IsSupported and without fallback.
|
|
|
|
|
Thanks for that information.
That means then that I do not need to change any settings, as I won't get any performance improvements when compiling to x64 instead of AnyCPU, except for those special cases you showed (getting rid of those 32bit dependencies is the most important point for me).
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
I read up on it last year, because I have a 32bit Win Forms project and needed to support 64bit Win10.
From what I read, compiling with X64 just creates a giant bloated program that consumes tons of memory.
Using X32 creates a smaller program that is more efficient and compact.
So I opted for Any CPU and it works fine on both Win7 32 bit OS, Win10 64 bit OS. Of course some NuGet libraries gave me issues in which I had to detect the OS and load the correct version.
Several examples given was Office 32 vs Office 64, and why Visual Studio is 32 bit.
Suppose it could be debated again.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Maybe the question you should really be asking is, "what improvements will (in performance, efficiency etc.) will be seen by switching to x64?". Since 32 bit code will run fine on 64 bit systems it is important to change for the right reasons.
|
|
|
|
|