|
|
Thanks Igor. I'll check these out.
Mark
|
|
|
|
|
What do you think if I implement my classes in .h files instead of dividing the declarations in .h files and the implementation in .cpp?
Is this a bad programming style or it will bother the compiler?
|
|
|
|
|
For me it seems strange,
I know that AppWizard makes the reverse for CAboutDlg of
a single/multidocument app
It inserts the declaration in .cpp before the implementation
I think it's better the usual way
|
|
|
|
|
it wont bother that much the compiler if you do it correctly.
however, it is a bad habit to do so.
we generally put into headers only declarations, other includes, class definitions, and the implementation code into deparated .cpp files...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20]
|
|
|
|
|
toxcct wrote: it wont bother that much the compiler if you do it correctly.
It doesn't bother the compiler, but it bothers the linker.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hello,
It's a bad (C/C++) programming practice and it will bother the linker if you include the header in more than one place. (Multiple defined symbols...). Besides that, if you place all your code in header files (no *.cpp file(s)) you'll not be able to create object files and executable code...
If you are talking about templates (I assume you are not), then you have to put all the code in a *.inl document or in the header file.
Hope this helps you.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
bad idea, if you change the implementation all file dependant on that header file will be recompiled.
Also, I don't think the debugger will be able to step in the code.
anyway, bad idea, I sure others will give you other reasons why.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
|
Hello i am using datagrid control in Vc++.net.
when i set a float value to a cell, it returns the fol error.
my code is
***********
Datagrid->set_Item(1,1,System::Convert::ToSingle(textBox1->Text) );
Error
********
error C2664: 'void System::Windows::Forms::DataGrid::set_Item(int,int,System::Object __gc *)' : cannot convert parameter 3 from 'float' to 'System::Object __gc *'
The datagrid columns are of float type.
otherwise if i use toString function,
Datagrid->set_Item(1,1,System::Convert::ToSingle(textBox1->Text) );
it compiles well but, returns runtime error, cannot convert from target type to primitive type..
Pls help me
Salai
|
|
|
|
|
Hi to all,
I've got a big problem with the code below
CWorkRecordset::CWorkRecordset(CDaoDatabase* pdb)
: CDaoRecordset(pdb)
{
//{{AFX_FIELD_INIT(CWorkRecordset)
m_lUser = 1;
m_lCode = 0;
m_lDept = 0;
m_lWork = 0;
m_lSource = 0;
m_oStartTm = COleDateTime::GetCurrentTime();
m_nFields = 6;
//}}AFX_FIELD_INIT
m_nDefaultType = dbOpenDynaset;
}
The problem occours during the creation of the obj,
and only if:
- I'm running in debug mode
- The PC where Visual C++ Professional 6.0 (no service pack) is installed has Win XP as OS
Program crashes when it execute:
m_oStartTm = COleDateTime::GetCurrentTime();
If I run in release mode, no crash occours
If I run in debug/release mode in a Win 2000 PC, no problem
The state of obj m_oStartTm is "valid" before assignment
Can anybody help me?
Thanks in advance
Cristian
|
|
|
|
|
Have you stepped into COleDateTime::GetCurrentTime() to see what is causing the crash?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Have you stepped into COleDateTime::GetCurrentTime() to see what is causing the crash?
As I try to step into using F11 the program crashes, the debug window says:
Debug assertion failed!
File: winctrl5.cpp
line: 189
Before calling that function obj m_oStartTm.dt = 0.0000 & m_oStartTm.status = valid
I don't understand...
|
|
|
|
|
misturas wrote: File: winctrl5.cpp
line: 189
Hmm, this is inside of the CDateTimeCtrl::GetTime() method. Can you set a breakpoint in it and then check the call stack once that breakpoint is reached? I'm curious how you got there from COleDateTime::GetCurrentTime() .
Another suggestion would be to change the initialization to:
m_oStartTm = COleDateTime(0); and see what that produces.
Also, what does CWorkRecordset::DoFieldExchange() look like?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
So, using m_oStartTm = COleDateTime(0); causes a compiling error(0);
DoFieldExchange is:
pFX->SetFieldType(CDaoFieldExchange::outputColumn);
DFX_Long(pFX, _T(cRSsbUser), m_lUser);
DFX_Long(pFX, _T(cRSsbCode), m_lCode);
DFX_Long(pFX, _T(cRSsbDept), m_lDept);
DFX_Long(pFX, _T(cRSsbWork), m_lWork);
DFX_DateTime(pFX, _T(cRSsbDateHour), m_oStartTm);
DFX_Long(pFX, _T(cRSsbSource), m_lSource);
where cRSsbUser is the name of a access table column
And finally, if I set a breakpoint in winctrl5.cpp, when i run the debug Visual C++ disable that brakpoint
Now in italy is quite late, i think I'll go sleepin an hour, if i apologize if i don't reply immediately
Thanks in advance, tomorrow i will try again
-- modified at 16:34 Thursday 1st December, 2005
|
|
|
|
|
misturas wrote: So, using m_oStartTm = COleDateTime(0); causes a compiling error(0);
What about this instead:
m_oStartTm = (DATE) 0; Even if this does pacify the compiler, I feel the underlying problem still exists. I just created a test program with a class derived from CDaoRecordset , and an Access table having a date/time column. The constructor looked liked yours and I got no assertion. At this point, I would suggest you do the same thing, and then start adding bits and pieces of code until the problem shows up. Make sense?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: What about this instead:
m_oStartTm = (DATE) 0;
Even if this does pacify the compiler, I feel the underlying problem still exists. I just created a test program with a class derived from CDaoRecordset, and an Access table having a date/time column. The constructor looked liked yours and I got no assertion. At this point, I would suggest you do the same thing, and then start adding bits and pieces of code until the problem shows up. Make sense?
I apologize if i reply only now, I had problems with internet connection
I just want to ask if you have the same configuration I submit in my first msg, because if I use win 2000 I have no problem!
|
|
|
|
|
I am using Windows XP SP2.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Hello, I searched this message board and I did not find anything about changing the color of the scrollbar in my edit box so I decided to ask. In my dialog box I have 4 edit boxes and I want to modify the style of the scrollbar (CSS does this in webdesign). See an example here of CSS scrollbar style modification
|
|
|
|
|
Problem Context: I am writing 2 functions in a dll namely "Fun1" and Convert(thread function).
I am creating a thread within a Function "Fun1" which is called from a tool.
The code for this as follows:
Fun1(Long lChannelNos )
{
HANDLE h1;
NumberOfChn(/*declared at file level of long type*/) = (long)lChannelNos ;
LPDWORD dwTh ;
LPVOID data ;
data = (void *)NULL ;
h1= CreateThread(NULL, // default security attributes
0, // use default stack size
Convert, // thread function
data, // argument to thread function
0 , // use default creation flags
dwTh) ; // returns the thread identifier
if(h1 == NULL)
{MessageBox((HWND)hDIAdemWndGet(),"Failed to create thread","Failure
Thread",MB_OK);
return ;
}
CloseHandle(h1);
return ;
}
DWORD WINAPI Convert(LPVOID lpTh)
{
Here I create linked list, dynamically on heap, using pointers to structure of data type given below.
Thus depending on size of "NumberOfChn",(any value between 1 to 200) the memory requirement varies.
For NumberOfChn = 1 the linked list would consume memory of 40503 bytes(40.5Kb).
}
Problem facing:
1) For NumberOfChn = 1 to 10 (any value) I do not get any error after executing function "Fun1". But if I happens to close the tool, the following error is received
Error: Debug assertion failed
Program: c:\Program Files\National Instruments\Diadem 9.1\Diadem.exe
(This is the Tool from which i make call to "Fun1")
File : dbgheap.c
Line:1011
Expression: _CrtIsValidHeapPointer(pUserData)
2) If the value of NumberOfChn goes beyond 15 it gives
MEMORY ACCESS VIOLATION error.
thats all....
waiting for any solution.
typedef struct tag_VECTOR
{
char lpszVectorDescription[5] ; //1) Vector description as a variable length string.
char lpszVectorName[7] ; //2) Vector name as a variable length string.
char lpszEquation[5] ; //3) Equation as a variable length string. I read but ignore this value.
long int lNoOfPoints ; //4) Number of points in vector as a four-byte integer.
long int lNoOfBytes ; //5) Number of bytes in each point, either four or eight for single and double precision. The GM Safety Lab data uses single precision.
long int lBinaryFlag ; //6) Binary flag as four-byte integer, always set to one.
float lpDataValue[10000] ; //7) The four or eight byte binary, floating-point data values. The total number of bytes in this section is the product of the values read in four and five, above.
}VECTOR, *LPVECTOR;
//**************************************************************************************************************
//The request description is made up of the channel name, anomaly error (if any), channel description,
//channel number, units, filter, and file name. For example:
//aa001a, ANOMALY = Data Affected by Accelerometer Rotation, CTR FRT C/MBR ON SENSOR LONGITUDINAL ACCEL, G'S, Channel = 123, Units = G's, Filter = 1000, File = c12001a
//To model this sequence I am writing following structure
//**************************************************************************************************************
typedef struct tag_REQUEST_DESCRIPTION
{
char lpszChannelName[25] ; //1) Channel name and is assigned as Request name
char lpszAnomalyError[20] ; //2) Anaomaly Error if any.
char lpszChannelDescription[25] ; //3) Channel Description
char lpszChannelNumber[4] ; //4) Channel Number
char lpszUnits[15] ; //5) Channel units
char lpszFilter[10] ; //6) Filter
char lpszFileName[15] ; //7) FileName
}REQUEST_DESCRIPTION, *LPREQUEST_DESCRIPTION ;
//***************************************************************************************************
// Request Structure: This structure is used to emulates "Requests" section of ABF file.
//***************************************************************************************************
typedef struct tag_REQUEST
{
REQUEST_DESCRIPTION RequestDescription ; //1) Request description as a variable length string.
char lpszRequestName[35] ; //2) Request name as a variable length string.
char lpszRequestNameRe[35] ; //3) Request name, repeated, as a variable length string. I read but ignore this value.
char lpszTotalDescription[240] ; //4) Total description is string formed by concating all elements of "RequestDescription" element
tag_REQUEST *NextRequest ; //5) This points to next request of same data type. If no next request is available it is NULL
LPVECTOR lpVector ; //6) This points to vector
}REQUEST, *LPREQUEST;
//****************************************************************************************************
// Data Type Structure: This structure is used to emulate "Data Types" section of ABF file
//****************************************************************************************************
typedef struct tag_DATA_TYPE
{
char lpszDataTypeDescription[25] ; //1) Data Type description as a variable length string.
char lpszDataTypeName[25] ; //2) Data Type name as a variable length string.
long int lDefaultTimeDataType ; //3) Flag indicating if this is the one and only default time Data Type. This is a four-byte integer,1 = true, 0 = false. At most only one Data Type in each file may set this to true.
long int lNoOfRequests ; //4) Number of requests as a four-byte integer. This number denotes the number of channels, in given data set, of same data type
long int lNoOfComponents ; //5) Number of components as a four-byte integer.
tag_DATA_TYPE *NextDataType ; //6) This points to next data type.
LPREQUEST lpRequest ;
}DATA_TYPE,*LPDATA_TYPE ;
|
|
|
|
|
Amol Ravatale wrote: Here I create linked list, dynamically on heap, using pointers to structure of data type given below.
Are you using new and delete for this?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Yes I am using new and delete for this.
|
|
|
|
|
Show the code that adds to, and deletes from, the list.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Contents : -Data Structures used in Linked List
-Class namely 'DataType' having properties and methods to
create linked list
-the function in which linked list is created
//***************************************************************************************************
// Vector structure: This structure is used to emulate "Vectors" section of ABF file.
//**************************************************************************************************
typedef struct tag_VECTOR
{
char lpszVectorDescription[5] ; //1) Vector description as a variable length string.
char lpszVectorName[7] ; //2) Vector name as a variable length string.
char lpszEquation[5] ; //3) Equation as a variable length string. I read but ignore this value.
long int lNoOfPoints ; //4) Number of points in vector as a four-byte integer.
long int lNoOfBytes ; //5) Number of bytes in each point, either four or eight for single and double precision. The GM Safety Lab data uses single precision.
long int lBinaryFlag ; //6) Binary flag as four-byte integer, always set to one.
float lpDataValue[10000] ; //7) The four or eight byte binary, floating-point data values. The total number of bytes in this section is the product of the values read in four and five, above.
}VECTOR, *LPVECTOR;
//**************************************************************************************************************
//The request description is made up of the channel name, anomaly error (if any), channel description,
//channel number, units, filter, and file name. For example:
//aa001a, ANOMALY = Data Affected by Accelerometer Rotation, CTR FRT C/MBR ON SENSOR LONGITUDINAL ACCEL, G'S, Channel = 123, Units = G's, Filter = 1000, File = c12001a
//To model this sequence I am writing following structure
//**************************************************************************************************************
typedef struct tag_REQUEST_DESCRIPTION
{
char lpszChannelName[25] ; //1) Channel name and is assigned as Request name
char lpszAnomalyError[20] ; //2) Anaomaly Error if any.
char lpszChannelDescription[25] ; //3) Channel Description
char lpszChannelNumber[4] ; //4) Channel Number
char lpszUnits[15] ; //5) Channel units
char lpszFilter[10] ; //6) Filter
char lpszFileName[15] ; //7) FileName
}REQUEST_DESCRIPTION, *LPREQUEST_DESCRIPTION ;
//***************************************************************************************************
// Request Structure: This structure is used to emulates "Requests" section of ABF file.
//***************************************************************************************************
typedef struct tag_REQUEST
{
REQUEST_DESCRIPTION RequestDescription ; //1) Request description as a variable length string.
char lpszRequestName[35] ; //2) Request name as a variable length string.
char lpszRequestNameRe[35] ; //3) Request name, repeated, as a variable length string. I read but ignore this value.
char lpszTotalDescription[240] ; //4) Total description is string formed by concating all elements of "RequestDescription" element
tag_REQUEST *NextRequest ; //5) This points to next request of same data type. If no next request is available it is NULL
LPVECTOR lpVector ; //6) This points to vector
}REQUEST, *LPREQUEST;
//****************************************************************************************************
// Data Type Structure: This structure is used to emulate "Data Types" section of ABF file
//****************************************************************************************************
typedef struct tag_DATA_TYPE
{
char lpszDataTypeDescription[25] ; //1) Data Type description as a variable length string.
char lpszDataTypeName[25] ; //2) Data Type name as a variable length string.
long int lDefaultTimeDataType ; //3) Flag indicating if this is the one and only default time Data Type. This is a four-byte integer,1 = true, 0 = false. At most only one Data Type in each file may set this to true.
long int lNoOfRequests ; //4) Number of requests as a four-byte integer. This number denotes the number of channels, in given data set, of same data type
long int lNoOfComponents ; //5) Number of components as a four-byte integer.
tag_DATA_TYPE *NextDataType ; //6) This points to next data type.
LPREQUEST lpRequest ;
}DATA_TYPE,*LPDATA_TYPE ;
class DataType
{
private:
LPDATA_TYPE m_Node ; //This acts as a Base Node
public:
DataType();
~DataType();
void AppendDataType(LPDATA_TYPE) ; //adds a new node at the end of the linked list
void AddDataTypeatBeg(LPDATA_TYPE) ; //add a new node at the begining. this way the, after adding the first node becomes second node
void AddDataTypeAfter(LPDATA_TYPE, int Num) ; //add a new node after nth node(2nd argument)
LPDATA_TYPE FindDataType(LPDATA_TYPE) ; //find node with desired data type
LPDATA_TYPE GetDataType(int Num) ; //get the nth node
int GetTotalDataTypes() ; //get total number of data types available:this is equal to number of nodes in link list
LPDATA_TYPE GetNewDataType() ; //This creates a new pointer to DATA_TYPE structure on HEAP and returns the same
LPREQUEST GetNewRequest() ; //This creates a new pointer to REQUEST structure on HEAP and returns the same
LPVECTOR GetNewVector(int DataPoints, int NoOfBytes=4) ; //This creates a new pointer to VECTOR structure on HEAP and returns the same
void AppendRequest(LPREQUEST,LPDATA_TYPE) ; //Append request to the last request of data type given as second argument
};
DataType::DataType()
{
m_Node = NULL ;
}
//**************************************
// Destroy the link list objects
//**************************************
DataType::~DataType()
{
LPDATA_TYPE Tempdata; LPREQUEST TempRequest ; LPVECTOR TempVector;
if(m_Node==NULL)
return;
while(m_Node != NULL)
{
if(m_Node->NextDataType !=NULL)
{
TempRequest = m_Node->lpRequest ;
while(TempRequest != NULL)
{
LPREQUEST temprequest1 = TempRequest->NextRequest ;
//delete TempRequest->lpVector->lpDataValue ;
delete TempRequest ;
TempRequest = temprequest1 ;
}
Tempdata = m_Node->NextDataType ;
delete m_Node;
m_Node = Tempdata;
}
else //if there is only one link list object or if there are n nodes, then the above "if" condition deletes (n-1), for deleting last this else condition is written.
{
TempRequest = m_Node->lpRequest ;
while(TempRequest != NULL)
{
LPREQUEST temprequest1 = TempRequest->NextRequest ;
//delete TempRequest->lpVector->lpDataValue ;
delete TempRequest ;
TempRequest = temprequest1 ;
}
delete m_Node ;
m_Node = NULL ;
}
}
}
//******************************************
// Purpose: adds a new code of DATA_TYPE
//******************************************
void DataType::AppendDataType( LPDATA_TYPE NewNode)
{
LPDATA_TYPE Temp1, Temp2;
NewNode->lNoOfComponents =1;
NewNode->lNoOfRequests =1 ;
NewNode->lDefaultTimeDataType =0 ;
if(m_Node ==NULL) //If Base node in NULL.
{
//Create the First Base Node
m_Node = NewNode ;
m_Node->NextDataType = NULL;
}
else
{
//Go to the Last Node
Temp1 = m_Node ;
while(Temp1->NextDataType != NULL)
Temp1 = Temp1->NextDataType ;
//Add Node at the End
Temp2 = NewNode ;
Temp2->NextDataType = NULL;
Temp1->NextDataType = Temp2 ;
}
}
//************************************************************************************************
// This Function adds a NewRequest, passed as 1st argument, to the given DataType, 2nd argument.
//************************************************************************************************
void DataType::AppendRequest(LPREQUEST NewRequest,LPDATA_TYPE ToThisDataType)
{
LPDATA_TYPE TempDataType; LPREQUEST TempRequest ;
if(ToThisDataType->lpRequest == NULL) //If immediate pointer to request, an element of DataType, is NULL.
{
ToThisDataType->lpRequest = NewRequest ;
ToThisDataType->lpRequest->NextRequest = NULL ; //recent
}
else
{
TempRequest = ToThisDataType->lpRequest;
while(TempRequest->NextRequest != NULL ) // Move to last request
TempRequest = TempRequest->NextRequest ;
TempRequest->NextRequest = NewRequest ;
TempRequest->NextRequest->NextRequest = NULL ; //recent
}
}
//************************************************************
// This Functions makes passed argument as the Base node
//************************************************************
void DataType::AddDataTypeatBeg(LPDATA_TYPE NewNode)
{
LPDATA_TYPE Temp ;
//add new node
Temp = NewNode ;
Temp->NextDataType = m_Node ;
m_Node = Temp ;
}
//*************************************************************************************
// This Function adds new node of DATA_TYPE, after Num(2nd argument) no of nodes
//*************************************************************************************
void DataType::AddDataTypeAfter(LPDATA_TYPE NewNode, int Num)
{
LPDATA_TYPE Temp1, Temp2; int count ;
for(count=0,Temp1=m_Node;count < Num;count++)
{
Temp1 = Temp1->NextDataType ;
if(Temp1 == NULL)
return ;
}
//insert new node
Temp2 = NewNode ;
Temp2->NextDataType = Temp1->NextDataType ;
Temp1->NextDataType = Temp2;
}
//************************************************************************************
// This Function returns datatype node of nth num(which is passed as 2nd argument)
//************************************************************************************
LPDATA_TYPE DataType::GetDataType(int Num)
{
LPDATA_TYPE Temp ; int count ;
Temp=m_Node ;
if(Num==1)
return Temp ;
for(count=2;count <=Num;count++)
{
Temp = Temp->NextDataType ;
if(Temp == NULL)
return NULL;
}
if(Temp ==NULL)
return NULL;
else
return Temp;
}
//***************************************************************************************
// Purpose : Searches datatype node
// Searching Criteria : DataTypeName, which is an element of DATA_TYPE node.
// Return Value : If desired node of same Data Type name is found in Linked list,
// then the node passed as argument to this function is delete, as
// already DataType node of data Type Name exists, and the pointer
// to the available node is returned back.
// If no node is present, NULL is returned.
//***************************************************************************************
LPDATA_TYPE DataType::FindDataType(LPDATA_TYPE Node)
{
LPDATA_TYPE Temp = m_Node ; int count ;
while(Temp != NULL)
{
if(strcmp(Temp->lpszDataTypeName,Node->lpszDataTypeName)==0) //If you find a data type, delete new created data type object
{
delete Node ;
return Temp ;
}
Temp = Temp->NextDataType ;
}
return NULL ;
}
//*****************************************************************************************
// Purpose : Total number of data type nodes that are available in the Linked List
// Return Value: Total No of Data types
//*****************************************************************************************
int DataType::GetTotalDataTypes()
{
LPDATA_TYPE Temp = m_Node ; int Total=0;
while(Temp != NULL)
{
Temp = Temp->NextDataType ;
Total++;
}
return Total ;
}
//*************************************************************************
// Purpose : Function creates object of structure DATA_TYPE on Heap.
// Sets Request & NextdataType element of its as NULL.
// Return Value : Pointer to DATA_TYPE.
//*************************************************************************
LPDATA_TYPE DataType::GetNewDataType()
{
LPDATA_TYPE NewDataType ;
NewDataType = new DATA_TYPE ;
NewDataType->NextDataType = NULL ;
NewDataType->lpRequest = NULL ;
return NewDataType ;
}
//*************************************************************************
// Purpose : Function creates object of structure REQUEST on Heap.
// Sets NextRequest & Vector element of its as NULL.
// Return Value : Pointer to REQUEST.
//*************************************************************************
LPREQUEST DataType::GetNewRequest()
{
LPREQUEST NewRequest ;
NewRequest = new REQUEST ;
NewRequest->NextRequest = NULL;
NewRequest->lpVector = NULL ;
return NewRequest ;
}
//**************************************************************************************
// Purpose : Function creates object of structure VECTOR on Heap.
// Creates memory on heap for data points
// Parameters : 1st argument - denotes number of data points available in the channel
// : 2nd argument - denotes number of bytes for each data point.
// Return Value : Pointer to REQUEST.
//**************************************************************************************
LPVECTOR DataType::GetNewVector(int DataPoints,int NoOfBytes)
{
LPVECTOR NewVector ;
NewVector = new VECTOR ;
//NewVector->lpDataValue = new float[sizeof(DataPoints*NoOfBytes+5)];
return NewVector ;
}
Inside function body:
{
int StringLen ; //Used to get the lenght of any string and use it for any purpose such as allocationg memory of same lenght
float ActualValue ; //Used to store value retrived from channel
Units cUnit ; //
DataType *lpcDataType ; //To create Linked List
int TotalNoOfRequest=0 ; //Total requests irrespective of data type
int ChannelLen=0 ; //data Points in Channel
register int Index=1 ; //Used in For Loop , register storage class makes the processing faster
register int RowCount ; //Used in For Loop , register storage class makes the processing faster
TDataDouble dValueT ; // Local double variable
TDataChannelLenInfo DataChannelLenInfoT ; // Local length information for a data channel
//Set how many channels are there.
ABFFile.SetNoOfChannels(unsigned int (lChannelNos)) ; //This is neccessory to set the upper bound of array of datatypes, requests and vectors
// Request object channel length info for the first data channel using the property function
lDataObjProperties(lChannelNos,eChannelLenGet,sizeof(TDataChannelLenInfo),&DataChannelLenInfoT);
ABFFile.SetChannelLength((int)DataChannelLenInfoT.lLen) ;
//ABFFile.SetChannelLength((int)25) ;
ChannelLen = ABFFile.GetChannelLength() ;
if( ChannelLen <=0 )//If channel len <=0 return
{
MessageBox((HWND)hDIAdemWndGet(),"Invalid Channel Lenght/Data Points in channel","Invalid Data Points",MB_OK);
return ;
}
if (ChannelLen > 0) //VALIDATION NO 1:- this check will ensure that given channel number, as argument of this function contains data rows/data points. This instruction assumes that data for channels below channel number given as argument exists
{
lpcDataType = new DataType ;
FILE *pTxtFile ;
pTxtFile = fopen("ABFChnPro.txt","r");
if(pTxtFile == NULL)
{
MessageBox((HWND)hDIAdemWndGet(),"Failed to Open Text file ","Channel Properties File",MB_OK) ;
return ;
}
//details about data types
int k; int i=0; char data1[50], data2[50], data3[50], data4[50] ;
TDataObjHeader DataObjHeaderT ;
DataObjHeaderT.lSize = sizeof(TDataObjHeader) ;
//try
//{
k = fgetc(pTxtFile) ;
while('\n'!= (char)k)
{
LPDATA_TYPE TempDataType ; LPREQUEST TempRequest ; LPVECTOR TempVector ;
TempDataType = lpcDataType->GetNewDataType() ;
if(TempDataType == NULL)
{
MessageBox(NULL,"Enough memory is not available","Low memory",MB_OK);
return ;
}
TempRequest = lpcDataType->GetNewRequest();
if(TempRequest == NULL)
{
MessageBox(NULL,"Enough memory is not available","Low memory",MB_OK);
return ;
}
TempVector = lpcDataType->GetNewVector(ABFFile.GetChannelLength()) ;
if(TempVector == NULL || TempVector->lpDataValue == NULL)
{
MessageBox(NULL,"Enough memory is not available","Low memory",MB_OK);
return ;
}
i=0;
while('\n'!= (char)k) //This is name of channel
{
data1[i] = (char) k ;
i++;
k = fgetc(pTxtFile) ;
}
data1[i] = '\0' ;
i=0;
k = fgetc(pTxtFile) ;
while('\n'!= (char)k) //This is data type name
{
data2[i] = (char) k ;
i++;
k = fgetc(pTxtFile) ;
}
data2[i] = '\0' ;
strcpy(TempDataType->lpszDataTypeName,data2) ;
strcat(TempDataType->lpszDataTypeName,"\0");
i=0;
k = fgetc(pTxtFile) ;
while('\n'!= (char)k) //This is units of channel
{
data3[i] = (char) k ;
i++;
k = fgetc(pTxtFile) ;
}
data3[i] = '\0' ;
//request unit name ;
strcpy(TempRequest->RequestDescription.lpszUnits,data3); //aRequests[Index].RequestDescription.lpszUnits = new char[StringLen] ;
strcat(TempRequest->RequestDescription.lpszUnits,"\0") ; //strcpy(aRequests[Index].RequestDescription.lpszUnits,data3) ;
//data type description
strcpy(TempDataType->lpszDataTypeDescription,cUnit.GetDataDescription(data3)); //strcpy(aDataTypes[Index].lpszDataTypeDescription,cUnit.GetDataDescription(data3) ) ;
strcat(TempDataType->lpszDataTypeDescription,"\0");
strcpy(TempRequest->RequestDescription.lpszUnits,cUnit.GetDataDescription(data3));
strcat(TempRequest->RequestDescription.lpszUnits,"\0");
i=0;
k = fgetc(pTxtFile) ;
while('\n'!= (char)k) //This channel number
{
data4[i] = (char) k ;
i++;
k = fgetc(pTxtFile) ;
}
data4[i] = '\0' ;
strcpy(TempRequest->RequestDescription.lpszChannelNumber,data4) ;
strcat(TempRequest->RequestDescription.lpszChannelNumber,"\0") ;
k=(char )fgetc(pTxtFile) ;
k=(char )fgetc(pTxtFile) ;
nDataObjHeaderGet(Index,&DataObjHeaderT) ; //GPI SERVICE ROUTINE
//REQUEST NAME:-The request name is set to the channel name
strcpy(TempRequest->lpszRequestName,DataObjHeaderT.szName) ;
strcat(TempRequest->lpszRequestName,"\0") ;
strcpy(TempRequest->lpszRequestNameRe,DataObjHeaderT.szName) ;
strcat(TempRequest->lpszRequestNameRe,"\0") ;
strcpy(TempRequest->RequestDescription.lpszAnomalyError,"NA") ;
strcat(TempRequest->RequestDescription.lpszAnomalyError,"\0") ;
strcpy(TempRequest->RequestDescription.lpszChannelName,DataObjHeaderT.szName);
strcat(TempRequest->RequestDescription.lpszChannelName,"\0") ;
strcpy(TempRequest->RequestDescription.lpszChannelDescription,"NA");
strcat(TempRequest->RequestDescription.lpszChannelDescription,"\0");
strcpy(TempRequest->RequestDescription.lpszFileName,"NA");
strcat(TempRequest->RequestDescription.lpszFileName,"\0");
strcpy(TempRequest->RequestDescription.lpszFilter,"NA");
strcat(TempRequest->RequestDescription.lpszFilter,"\0");
if(TempRequest->RequestDescription.lpszChannelName != NULL)
{
strcpy(TempRequest->lpszTotalDescription,TempRequest->RequestDescription.lpszChannelName) ;
}
if(TempRequest->RequestDescription.lpszAnomalyError != NULL)
{ strcat(TempRequest->lpszTotalDescription,",") ;
strcat(TempRequest->lpszTotalDescription,"ANOMALY=");
strcat(TempRequest->lpszTotalDescription,TempRequest->RequestDescription.lpszAnomalyError );
}
else
{ strcat(TempRequest->lpszTotalDescription,",");
}
if(TempRequest->RequestDescription.lpszChannelDescription!=NULL )
{ strcat(TempRequest->lpszTotalDescription,",") ;
strcat(TempRequest->lpszTotalDescription,TempRequest->RequestDescription.lpszChannelDescription);
}
else
{ strcat(TempRequest->lpszTotalDescription,",");
}
if(TempRequest->RequestDescription.lpszChannelNumber !=NULL )
{ strcat(TempRequest->lpszTotalDescription,",");
strcat(TempRequest->lpszTotalDescription,"Channel=");
strcat(TempRequest->lpszTotalDescription,TempRequest->RequestDescription.lpszChannelNumber);
}
else
{ strcat(TempRequest->lpszTotalDescription,",");
}
if(TempRequest->RequestDescription.lpszUnits != NULL)
{ strcat(TempRequest->lpszTotalDescription,",");
strcat(TempRequest->lpszTotalDescription,"Units=");
strcat(TempRequest->lpszTotalDescription,TempRequest->RequestDescription.lpszUnits);
}
else
{ strcat(TempRequest->lpszTotalDescription,",");
}
if( TempRequest->RequestDescription.lpszFilter !=NULL)
{ strcat(TempRequest->lpszTotalDescription,",");
strcat(TempRequest->lpszTotalDescription,"Filter=");
strcat(TempRequest->lpszTotalDescription,TempRequest->RequestDescription.lpszFilter);
}
else
{ strcat(TempRequest->lpszTotalDescription,",");
}
if(TempRequest->RequestDescription.lpszFileName != NULL )
{ strcat(TempRequest->lpszTotalDescription,",");
strcat(TempRequest->lpszTotalDescription,"File=");
strcat(TempRequest->lpszTotalDescription,TempRequest->RequestDescription.lpszFileName );
}
else
{ strcat(TempRequest->lpszTotalDescription,",");
}
strcat(TempRequest->lpszTotalDescription,"\0");
//Vectors
for(RowCount=1 ; RowCount <=ChannelLen ; RowCount++)
{
lpdDataObjChannelValueGet(Index,RowCount,&dValueT) ;
ActualValue = (float)dValueT ;
TempVector->lpDataValue[RowCount-1] = ActualValue ;
}
strcpy(TempVector->lpszVectorDescription,"---") ; //1) Vector description as a variable length string.
strcat(TempVector->lpszVectorDescription,"\0") ;
strcpy(TempVector->lpszVectorName,"---") ; //2) Vector name as a variable length string.
strcat(TempVector->lpszVectorName,"\0") ;
strcpy(TempVector->lpszEquation ,"\0") ; //3) Equation as a variable length string. I read but ignore this value.
TempVector->lNoOfPoints = ABFFile.GetChannelLength() ; //4) Number of points in vector as a four-byte integer.
TempVector->lNoOfBytes = 4 ; //5) Number of bytes in each point, either four or eight for single and double precision. The GM Safety Lab data uses single precision.
TempVector->lBinaryFlag = 1 ; //6) Binary flag as four-byte integer, always set to one.
TempRequest->lpVector = TempVector ;
//process data type details
LPDATA_TYPE Temp1 ;
Temp1= lpcDataType->FindDataType(TempDataType) ;
if(Temp1==NULL) //If Data Type node do not exist
{
TempDataType->lpRequest = TempRequest ;
lpcDataType->AppendDataType(TempDataType) ;
TotalNoOfRequest++;
}
else //If data type node already exist
{
Temp1->lNoOfRequests++ ;
lpcDataType->AppendRequest(TempRequest,Temp1);
TotalNoOfRequest++; //This number denotes total requests ir-respective of data types
}
Index ++ ;
if(Index>lChannelNos)
{
fclose(pTxtFile) ;
break ;
}
}
//}
//catch(...)
//{
// MessageBox((HWND)hDIAdemWndGet(),"Error while porting channels","Error",MB_OK);
//}
//HeaderInfo info
TDataSet DataSetT ; //Local Data Set parameter data structure
char Filename[25] ;
DataSetT.lSize = sizeof(TDataSet) ;
nDataSetGet(&DataSetT) ; //Call service routine to get Data set properties
ABFFile.SetTitle((char *)DataSetT.szDataSetTitle) ; // Get Title of Data Set
ABFFile.SetDateOfTest((char *)DataSetT.szDataSetDate); // Get the Data of Data Set
//These values are set arbitrarily for time being
ABFFile.SetTypeOfTest("Car to Car, 50% Offset") ;
ABFFile.SetTypeOfSubtest("Sub-Car to Car, 50% Offset");
ABFFile.SetRegulation("NOVALUE") ;
ABFFile.SetLabName("Lab Example") ;
ABFFile.SetLabContactName("Mr. Safety") ;
ABFFile.SetLabContactEmail("lab@example.com") ;
ABFFile.SetLabContactPhone("0123-450") ;
ABFFile.SetDescription() ; // to concat title, dateof test....
//Datermine No of data types & requests
ABFFile.SetNoOfDataTypes((long)lpcDataType->GetTotalDataTypes()); //for time being
ABFFile.SetNoOfRequests((long)TotalNoOfRequest) ;
strcpy(Filename,DataSetT.szDataSetTitle) ;
strcat(Filename,".th") ;
if (! ABFFile.FileOpen(Filename,"wb") )
return ; //in case of failure
ABFFile.WriteHeader() ;
//write all parts
for(int DataTypeNo=1;DataTypeNo<= lpcDataType->GetTotalDataTypes() ; DataTypeNo++)
//for(int ChannelCount=1;ChannelCount<=lChannelNos;ChannelCount++) // Channel Loop
{
LPDATA_TYPE TempDataType ; LPREQUEST TempRequest ; LPVECTOR TempVector ;
TempDataType = lpcDataType->GetDataType(DataTypeNo) ;
//Write data type data
StringLen = strlen(TempDataType->lpszDataTypeDescription);
ABFFile.Write(&StringLen,1,2) ;
ABFFile.Write(TempDataType->lpszDataTypeDescription,1,strlen(TempDataType->lpszDataTypeDescription));
StringLen = strlen(TempDataType->lpszDataTypeName);
ABFFile.Write(&StringLen,1,2) ;
ABFFile.Write(TempDataType->lpszDataTypeName,1,strlen(TempDataType->lpszDataTypeName)) ;
ABFFile.Write(&TempDataType->lDefaultTimeDataType,1,4);
ABFFile.Write(&TempDataType->lNoOfRequests,1,4);
ABFFile.Write(&TempDataType->lNoOfComponents,1,4 );
TempRequest = TempDataType->lpRequest ;
while(TempRequest !=NULL)
{
//write Request data
StringLen = strlen(TempRequest->lpszTotalDescription);
ABFFile.Write(&StringLen,1,2);
ABFFile.Write(TempRequest->lpszTotalDescription ,1,(unsigned int)StringLen);
//ABFFile.Write("\n",1,1);
StringLen = strlen(TempRequest->lpszRequestName);
ABFFile.Write(&StringLen,1,2);
ABFFile.Write(TempRequest->lpszRequestName,1,(unsigned int)StringLen) ;
//ABFFile.Write(",",1,1);
//ABFFile.Write("\n",1,1);
StringLen = strlen(TempRequest->lpszRequestNameRe);
ABFFile.Write(&StringLen,1,2);
ABFFile.Write(TempRequest->lpszRequestNameRe,1,(unsigned int)StringLen) ;
//ABFFile.Write(",",1,1);
//ABFFile.Write("\n",1,1);
TempVector = TempRequest->lpVector ;
//write vector details
StringLen =strlen(TempVector->lpszVectorDescription) ;
ABFFile.Write(&StringLen,1,2);
ABFFile.Write(TempVector->lpszVectorDescription,1,3);
StringLen = strlen(TempVector->lpszVectorName);
ABFFile.Write(&StringLen,1,2);
ABFFile.Write(TempVector->lpszVectorName,1,3);
StringLen =strlen(TempVector->lpszEquation) ;
ABFFile.Write(&StringLen,1,2);
ABFFile.Write(TempVector->lpszEquation,1,StringLen);
StringLen =TempVector->lNoOfPoints ;
ABFFile.Write(&StringLen,1,4);
StringLen = TempVector->lNoOfBytes ;
ABFFile.Write(&StringLen,1,4);
StringLen = TempVector->lBinaryFlag ;
ABFFile.Write(&StringLen,1,4);
StringLen = TempVector->lNoOfBytes * TempVector->lNoOfPoints ;
ABFFile.Write(TempVector->lpDataValue,1,StringLen);
TempRequest = TempRequest->NextRequest ;
}
}
//MessageBox((HWND)hDIAdemWndGet(),"End Of Porting Channels","End",MB_OK) ;
ABFFile.FileClose() ;
delete lpcDataType ;
}
else
{
MessageBox((HWND)hDIAdemWndGet(),"The Channels do not contain data, Conversion to ABF will be stopped!!!","Abort",MB_OK) ;
}
return ;
}
|
|
|
|
|
Amol Ravatale wrote: strcat(TempVector->lpszVectorName,"\0") ;
What are you expecting this to do? These type of statements can be removed as they do nothing.
There's too much code here to wade through. Have you tried scaling the problem down to something more manageable? A few dozen lines of code is all you'd need to make a linked list that can easily be debugged. After you are certain that you can add to, and delete from, the simplest of lists, only then should you add all of the other code.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|