|
I don't understand your reply. I already tried something like this:
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e){
for(double i = 0; i < 1.05; i += 0.05){
this->Opacity = i;
this->Refresh();
}
}
But that didn't do anything. Can someone give me a little more info? Thanks.
|
|
|
|
|
There are at least two problems with your code:
1. there is no delay in your loop, it will sprint from 0 to 1 as fast as it can, all will be over in a fraction of a second.
2. the Form isn't visible while the Load handler is executing; it is only when Load is done that the Form becomes visible, so this is the wrong place for such loop.
The recommended solution to both these issues is as follows:
- give your Form an initial opacity of zero;
- in your Load handler, start a Windows.Forms.Timer with an interval of say 100 msec;
- in the timer's Tick handler, check the Form's opacity; if it is less than 1.0, add 0.05 to it; otherwise, stop the timer.
The reason you choose a Windows.Forms.Timer is that its events get handled by the main thread, and that is the only thread that is allowed to touch Controls and Forms. Other timers would tick on some threadpool thread, resulting in either some InvalidCrossThread exception, or the need for more code, based on Control.Invoke
Also notice there is no explicit loop anywhere; the timer will keep firing until you tell it to stop (when opacity reached 1.0).
|
|
|
|
|
I am reading a courrpted file, and I know that It will throw any exception,
and hence I want to catch it and make the app smoth.
<pre>WORD mydata;
try
{
ar >> mydata;
}
catch(CInvalidArgException* e)
{
}
catch(CArchiveException* e)
{
}
And the application throws below exception
First-chance exception at 0x7c812afb in xxxxxxxxxxx Microsoft C++ exception:
CArchiveException at memory location 0x0497e360.
kinldy help....
|
|
|
|
|
either I didn't understand or your question does not make sense.
What do you mean by corrupted file?
is it corrupted because of file format? or something else
|
|
|
|
|
Issue is control is not comming in to the
catch(CArchiveException* e) block while debuging.. but still CArchiveException is thrown.
soe if CArchiveException is thrown.. then the control should come to catch(CArchiveException* e) right ? That is not happninig 
|
|
|
|
|
You are catching the exceptions but ignoring them, so you will not see anything in your code. Add some code in the catch block to process the exception.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Issue is control is not comming in to the
catch(CArchiveException* e) block while debuging.. but still CArchiveException is thrown.
soe if CArchiveException is thrown.. then the control should come to catch(CArchiveException* e) right ? That is not happninig 
|
|
|
|
|
You have no code in your catch block so there is nowhere for it to go. Add some code and try again, at least you will be able to inspect the contents of the exception object.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
In the actual code I had few lines extrating the exception message and logging it.
but in the code I posted it was not there.... but controls never enters the catch block, even though the code was there and exception it throws was same ie (CArchiveException* e)
|
|
|
|
|
Once you have added actual code to the catch blocks, try running outside your IDE. Some, like Visual Studio, sometimes intercept exceptions before your catch block becomes active, although you typically can influence that through some IDE settings.
|
|
|
|
|
You're catching a pointer to CArchiveException, shouldn't you catch a reference to it?
ex. catch(CArchiveException & e) or maybe catch(CArchiveException const & e)
John
|
|
|
|
|
See here[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hi!
I'm stuck with the calling that DLL.
Can someone help me how to read the values of the DLL? OCIOpen of the opening returns sucess, but that reading doesn't work.
I guess... The problem is unmanaged/managed, but I don't how to solve it.
************ Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at WindowsFormsApplication3.Form1.oci.OCIRead(Int32 lOIObject, Int32 lDevice, Int32 lIndex,
OCIRead or OCIGetIndexInfo doesn't work.
using System.Runtime.InteropServices;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
[StructLayout(LayoutKind.Sequential)]
public struct OIDATA
{
[MarshalAsAttribute(UnmanagedType.SafeArray, SafeArrayUserDefinedSubType = typeof(Int32))]
public Int32[] lData; //'array of data, values depeds of index number
public Int32 lCheckAlarm; //'when read request is done and this is > 0 user should check alarm
public Int32 lCategory; //'when this is > 0 device configuration is changed
public Int32 lReadError; //'read error is occured
[MarshalAsAttribute(UnmanagedType.SafeArray, SafeArrayUserDefinedSubType = typeof(byte))]
public byte[] szData; // 'String * 128 'raw index read data as comma separated
}
/*
[StructLayout(LayoutKind.Explicit)]
public unsafe struct OIDATA
{
[FieldOffset(0)]
public fixed Int32 lData[32];
[FieldOffset(128)]
public Int32 lCheckAlarm;
[FieldOffset(132)]
public Int32 lCategory;
[FieldOffset(136)]
public Int32 lReadError;
[FieldOffset(140)]
public fixed byte szData[128];
}
*/
public OIDATA pOIDATA = new OIDATA();
public Int32 lObject = 0;
public Int32 lComPort = 5;
public Int32 OCI_OUTDOORTEMP = 3;
public Int32 OCI_MIN_INDEX = 0;
public Int32 OCI_MAX_INDEX = 63;
public sealed class oci // api // DLL Wrapper
{
internal const string DllName = "oci200.dll"; // handy const
[DllImport(DllName)]
public static extern Int32 OCIOpen(ref Int32 lOIObject, Int32 lComPort);
[DllImport(DllName)]
public static extern Int32 OCIRead(Int32 lOIObject, Int32 lDevice, Int32 lIndex, [param: MarshalAs(UnmanagedType.Struct)] ref OIDATA pOIData);
// _EXPORT(long) OCIGetIndexInfo(long lIndex,char **pszInfo,long *plRead,long *plWrite);
[DllImport(DllName)]
public static extern Int32 OCIGetIndexInfo(Int32 lIndex ,
[In, MarshalAs(UnmanagedType.LPStr)] System.String pszInfo,
ref Int32 plRead, ref Int32 plWrite);
}
private void cmdConnect_Click_1(object sender, EventArgs e)
{
Int32 l = oci.OCIOpen(ref lObject, lComPort);
lstOuman.Items.Add("OCIOpen: " + l);
pOIDATA.lData = new Int32[32];
pOIDATA.lCategory = 1;
pOIDATA.lCheckAlarm = 0;
pOIDATA.lReadError = 0;
pOIDATA.szData = new byte[128];
Int32 lIndex = OCI_OUTDOORTEMP;
Int32 lDevice = 2;
System.String pszInfo ;
Int32 plRead = 0;
Int32 plWrite = 0;
//pOIDATA.szData[127] = 0;
Int32 k = oci.OCIRead(lObject, lDevice, OCI_OUTDOORTEMP, ref pOIDATA); //This is where error occurs
lstOuman.Items.Add("OCIRead: " + k);
txtOuman.Text = k.ToString();
// l = pOIDATA.lData[0];
for (int i = OCI_MIN_INDEX; i < OCI_MAX_INDEX; i++)
{
long result = oci.OCIRead(lObject, lDevice, i, ref pOIDATA); //This is where error occurs
lstOuman.Items.Add(" " + i + " arvo: " + result );
//_EXPORT(long) OCIGetIndexInfo(long lIndex,char **pszInfo,long *plRead,long *plWrite);
long results = oci.OCIGetIndexInfo(i, "", ref plRead, ref plWrite);
lstOuman.Items.Add(" " + i + " info: " + results );
}
}
********* oci200.h ******************
/*******************************************************************************
Index struct
*******************************************************************************/
struct OIDATA
{
long lData[32]; // array of data, values depeds of index number
long lCheckAlarm; // when read request is done and this is > 0 user should check alarm
long lCategory; // when this is > 0 device configuration is changed
long lReadError; // read error is occured
char szData[128]; // raw index read data as comma separated
};
/*******************************************************************************
Function: OCIRead
Comments: Read index data from EHx device
Input: long lOIObject , connection handle
long lDevice, device index 0..x if more than 1 device in com line
long lIndex, index to read OCI_MIN_INDEX ... OCI_MAX_INDEX
struct OIDATA *pOIData, pointer to read data struct
Return: success, OCI_OK
failure, OCI_* error code
*******************************************************************************/
_EXPORT(long) OCIRead(long lOIObject,long lDevice,long lIndex,struct OIDATA *pOIData);
*******************************************************************************/
_EXPORT(long) OCIWrite(long lOIObject,long lDevice,long lIndex,struct OIDATA *pOIData);
/*******************************************************************************
Function: OCIGetIndexInfo
Comments: Get read/write index info
Input: long lIndex, index id value range OCI_MIN_INDEX ... OCI_MAX_INDEX
char ** pszInfo, pointer to description info
long *plRead, pointer to readable flag, if > 0 index can be read
long *plWrite, pointer to writable flag, if > 0 index can be write
Return: success, OCI_OK
failure, OCI_ERROR
*******************************************************************************/
_EXPORT(long) OCIGetIndexInfo(long lIndex,char **pszInfo,long *plRead,long *plWrite);
Programming is like sex:
One mistake and you have to support it for the rest of your life.
|
|
|
|
|
I need some detailed explanations about constructors using pointers.
|
|
|
|
|
Perhaps a specific question would be more appropriate?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
I am using VS 2010 Professional.
I am getting the error:
error C2143: syntax error : missing ';' before '*'
From:
Unmanaged *pu;
I assume there is something very simple that I am overlooking. This problem can be easily re-created. I re-created it by creating a Visual C++ CLR Class Librsry project. Then I used the Class Wizard to create an unmanaged class called Unmanaged. Then in the managed Class1 class I added the line shown above. Then I built that without any other changes and got the error. I do not understand why.
|
|
|
|
|
There is obviously something missing in your code such that the term Unmanaged is not being correctly interpreted by the compiler. Perhaps if you post your class definition also, someone can figure out what's wrong.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I am an idiot. I forgot to #include "Unmanaged.h". I definitely know better but for some reason I did not use my brain.
|
|
|
|
|
Sam Hobbs wrote: for some reason I did not use my brain.
You are now a certified developer; it's something we all do from time to time.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I have a simple function to check Totals on any table in my system (and similar ones for deleting and existence)
The parsed SQL is along these
Select Count(*) from AnyTable
Where ColumnA = 1
and ColumnB = 2
Written in C++/CLI as a command String
Select Count * from {0}
Where {1} = {2}
And {3} = {4}
Alternatively
And ({3} = {4} Or {3} is null} - This is controlled by an CallArgument driven switch construct.
~The function executing this statement takes the TableName, Column 1, Value 1, Column 2,Value 2 and CallArgument as parameters.
And this all works very well until I find I need a third Key/Value pair so I have to add to the parameters and recompile, amend my dynamic SQL etc.
I am thinking of passing in a list based on a class the members of which will be Key, Value, and NullAction.
Extending the parameter list and switch every time an extra clause has to be checked is a primitve and ugly looking approach by comparison to passing in the list and using a 'for each' loop to add a clause for what ever number of parameters are present.
This new approach has the added benefit of being low maintenance, in as far as possible, future proof.
But is it just style over substance?
Will there be a performance price to pay for passing in a list of key/values over specifiying each pair explicitly in the parameter list, subistuting in nullptr for the ones not required on any given call?
Note NullAction would controll whether or not a column needs to consider Null / not Null in an and / or capacity similar to the example above.
Ger
|
|
|
|
|
You shouldn't be building an SQL command string, instead use the SqlCommand class.
It has a Parameters property to which you can add whatever you consider relevant; in fact it does behave like a collection of key-value pairs. It also frees you from all the stringifying hassles, including DateTime format issues.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
I presume there is a MySQL equivalent...
It would be just what I need!
Ger
|
|
|
|
|
I don't know which data provider you are using, however even OdbcCommand has a Parameters property.
It is time for you to hit the documentation...
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Raided the hotpress last night and dug it out from its hiding place on the top shelf...
Ger
|
|
|
|