|
Vtable initiazation takes place in constructor of base class,its obvious that base class function will get called
|
|
|
|
|
Simply, C++ has a different order of construction than C# or Java. It was a design decision, not a bug.
Take a look at this article[^] for more details.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
I am in a project that aims to build a opos driver, a species of intermediary between application and opos devices that support the standard. The opos driver is divided in two parts: The Control Object(CO), that makes the interface with application and the Service Object(SO), that makes the interface with the devices. The CO makes methods calls in the SO.
My problem is the following one: The CO are ActiveX controls(ocx) and SO are dlls. I am not knowing that type of project I must create in the Visaul c++ and how do I link the CO and the SO? I need them( ocx and dll) will be invisible at runtime. I would like that somebody help about that. Somekind of help is welcome. I wait reply! Grateful! Helio
P.S.: for more information about opos standard "monroecs.com/opos.htm"
|
|
|
|
|
Friends there are two simple C++ classes Car and Engine . I am getting the following error in the function Start of class Engine
d:\Car\Car.cpp(19): error C2027: use of undefined type 'Car'
Please tell me why i am getting this error. Code is here:
class Car;
class Engine
{
public:
Engine(Car *pCar)
{
m_pCar = new Car();
}
void Start()
{
m_pCar->OnStart();
}
private:
Car *m_pCar;
};
class Car
{
public:
Car()
{
}
void OnStart()
{
}
};
Ahsan
|
|
|
|
|
you must declare class Car before using it...
precede your class Engine definition with : class Car;
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
You beat me!
Anyway, he declared the class Car before he used it. You must define the class before you try to use it however.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Sorry, forward declaration is there in my code. Please look it again
class Car;
class Engine
{
public:
Ahsan
|
|
|
|
|
Hello,
Your problem is that you did not define Car before you used it! Try the following:
class Car
{
public:
Car() {}
void OnStart() {}
};
class Engine
{
public:
Engine(Car *pCar)
{
m_pCar = new Car();
}
void Start()
{
m_pCar->OnStart();
}
private:
Car *m_pCar;
};
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Some how your Foward Declaration doesn't help.
try this:
//class Car; // Forward Declaration
class Car
{
public:
Car()
{
}
void OnStart()
{
}
};
class Engine
{
public:
Engine()
{
m_pCar = new Car();
}
void Start()
{
m_pCar->OnStart();
}
private:
Car* m_pCar;
};
Vote if help is of use.
|
|
|
|
|
If you want to have both Car and Engine classes in separate files (previous post gave solution to your problem but you have to put both classes in one file), the easiest solution is to move the code m_pCar->OnStart(); in the cpp file and include Car.h in the top of it:
In the cpp file:
void Engine::Start()<br />
{ m_pCar->OnStart(); }
But I have a little problem with your design (if you really use these classes in your project). It must be the opposite: this is the car that has an engine and not the engine that has a car
-- modified at 7:56 Tuesday 20th September, 2005
Sorry, and also move the code from your constructor in the cpp file
|
|
|
|
|
I bet you have an error reported in the constructor as well:
m_pCar = new Car();
Anyway, the problem is that you can't create instances (objects) of incomplete types. To work around this, separate member function implementations in a cpp file.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
My application is SDI Application and it has two views( i used CSplitterWnd) class mainview is derived from CListView and class logview is derived from CFormView. logview contains only one listbox, and i have a public member function DisplayInListBox();. Now the problem is, I have no way to access DisplayInListBox(); from outside(mainview class) the logview class. I cannot create an object of class logview, its constructor is protected. If i change the access specifier to public i get an assertion failure.
Can You help?
Thanks
|
|
|
|
|
Hello,
It's not allowed to create views yourself. Somewhere in your header file, you'll read: //Create from serialisation only! . You have to create the views the following way:
CRuntimeClass* pClass = RUNTIME_CLASS(CLogView);
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Thanks for replying.
I didn't create CLogView myself I used the class wizard to create the view. And i added a member function DisplayInListBox(); and I want to access this function from CMyAppView Class.
|
|
|
|
|
Have the splitterwnd object as a member variable of mainframe and wherever you are, get the mainframe and use GetPane of the splitterwnd to get your view and there you go! You can call the function!
Regards,
Satish
|
|
|
|
|
Hi,
I am writing an client-server application with networking in c#.
For the client part, I am using a synchronous network connection, that is,
when the client request the server, all the client features will be
hanged until the server response. So is it a common strategy in
implement client ? I am considering using threading or asynchronous
network connection, but it seem too complex and hard to maintain
the user logic. So any other good methodology to handle the problem ?
Thanks
|
|
|
|
|
Hello,
If you modelled it right, it's even more easy from a maintainance point of view. You should devide your app in the view (form) and the control (app logic). From the logic, you fire events to the view and do your tricks from there. This allows easy multithreading and ensures a better user experience!
IMHO you should go for multithreading!
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
See if these code snips help at all - then from your main location you just create one of these and got xx.run. Just an example, hope it helps
Glenn
///
/// Summary description for ThreadEx.
///
/*
***************************************************************************
**
** Class: ThreadEx
**
** Description:
** This is our thread class
**
** Notes:
**
*/
public class ThreadEx
{
/*
** Local Variables
*/
protected Thread m_thread = null;
protected ThreadStart m_start = null;
protected bool m_bStopped = true;
/*
***************************************************************************
**
** Property(bool): Stop
*/
///
/// Set the Stop Flag
///
///
public bool Stop
{
get{return m_bStopped;}
set{m_bStopped = value;}
}
/*
***************************************************************************
**
** Property(bool): isStopped
*/
///
/// Check to see if it is stopped - redundant
///
///
public bool isStopped
{
get{return Stop;}
}
/*
***************************************************************************
**
** Function: Start
*/
///
/// Start the Thread (Run) on the form
///
///<returns>void
///
public void Start()
{
Stop = false;
m_start = new ThreadStart(Run);
m_thread = new Thread(m_start);
m_thread.Start();
}
/*
***************************************************************************
**
** Function: WaitTillDone
*/
///
/// Wait till the thread is done (Infinitely)
///
///<returns>bool - True if thread is done
///
public bool WaitTillDone()
{
return m_thread.Join(Timeout.Infinite);
}
/*
***************************************************************************
**
** Function: WaitTillDone
*/
///
/// Wait for iMilli milliseconds for thread to complete
///
///<param name="iMilli" type="int" />
///<returns>void
///
public void WaitTillDone(int iMilli)
{
m_thread.Join(iMilli);
}
/*
***************************************************************************
**
** Function: IsDone
*/
///
/// Check to see if the thread is completed
///
///<returns>bool
///
public bool isDone
{
get{return m_thread.Join(0);}
}
/*
***************************************************************************
**
** Function: Kill
*/
///
/// Kill the thread
///
///<returns>void
///
public void Kill()
{
m_thread.Abort();
}
/*
***************************************************************************
**
** Function: Run
*/
///
/// This is the overloaded run function
///
///<returns>void
///
public virtual void Run()
{
}
}
public class RFC868TimeClient : ThreadEx
{
/*
** Local Variables
*/
protected string m_strTimeServer;
protected int m_iInterval;
#region SystemTime in Kernel32
/*
** Import the Kernel32 Function
*/
[DllImport("kernel32.dll", SetLastError=true)]
protected static extern int SetLocalTime(IntPtr ptrSystemTime);
/*
***************************************************************************
**
** Class: CSystemTime
**
*/
///
/// Class to behave like the SYSTEMTIME Structure in win32
///
///
public class CSystemTime
{
protected enum Var
{
Year = 0,
Month = 1,
DayOfWeek = 2,
Day = 3,
Hour = 4,
Minute = 5,
Second = 6,
Millisecond = 7,
AllocCount = 8
}
protected System.UInt16[] auData = new UInt16[(int)Var.AllocCount];
public System.UInt16[] Data
{
get{return auData;}
}
public System.UInt16 Year
{
get{return auData[(int)Var.Year];}
set{auData[(int)Var.Year] = value;}
}
public System.UInt16 Month
{
get{return auData[(int)Var.Month];}
set{auData[(int)Var.Month] = value;}
}
public System.UInt16 Day
{
get{return auData[(int)Var.Day];}
set{auData[(int)Var.Day] = value;}
}
public System.UInt16 DayOfWeek
{
get{return auData[(int)Var.DayOfWeek];}
set{auData[(int)Var.DayOfWeek] = value;}
}
public System.UInt16 Hour
{
get{return auData[(int)Var.Hour];}
set{auData[(int)Var.Hour] = value;}
}
public System.UInt16 Minute
{
get{return auData[(int)Var.Minute];}
set{auData[(int)Var.Minute] = value;}
}
public System.UInt16 Second
{
get{return auData[(int)Var.Second];}
set{auData[(int)Var.Second] = value;}
}
public System.UInt16 Millisecond
{
get{return auData[(int)Var.Millisecond];}
set{auData[(int)Var.Millisecond] = value;}
}
}
/*
***************************************************************************
**
** Function: SetLocalTime
*/
///
///
///
///<param name="SystemTime" type="TimeService.RFC868Service.RFC868TimeClient.CSystemTime" />
///<returns>bool
///
protected bool SetLocalTime(CSystemTime SystemTime)
{
/*
** Local Variables
*/
bool bOk = true;
GCHandle gch = GCHandle.Alloc(SystemTime.Data, GCHandleType.Pinned);
if(0 == SetLocalTime(gch.AddrOfPinnedObject()))
{
bOk = false;
}
gch.Free();
return bOk;
}
#endregion SystemTime in Kernel32
/*
***************************************************************************
**
** Property(string): TimeServerAddress
*/
///
/// Store the Server Address we want to connect to
///
///
public string TimeServerAddress
{
get{return m_strTimeServer;}
set{m_strTimeServer = value;}
}
/*
***************************************************************************
**
** Property(int): Interval
*/
///
/// Set the Time Interval to wait between client updates
///
///
public int Interval
{
get{return m_iInterval;}
set{m_iInterval = value;}
}
/*
***************************************************************************
**
** Function: Run
*/
///
/// This is the Time Server
///
///<returns>void
///<exception cref="System.Exception">Thrown
///<remarks>
///
///<example>How to use this function
///
<br />
///
///
public override void Run()
{
/*
** Till we have to stop process here
*/
while(!isStopped)
{
/*
** Local Variables
*/
TcpClient tcpClient = new TcpClient();
NetworkStream sClient = null;
TimeInfo Info = new TimeInfo();
TimeSpan tsWait = new TimeSpan(0, 0, Interval, 0, 0);
DateTime dtWait = DateTime.Now + tsWait;
CSystemTime SystemTime = new CSystemTime();
DateTime dtNow;
try
{
/*
** Connect to the Server
*/
tcpClient.Connect(m_strTimeServer, RFC868PORT);
sClient = tcpClient.GetStream();
sClient.Read(Info.Array, 0, Info.Array.Length);
tcpClient.Close();
/*
** Get us a Date Time thingie
*/
dtNow = TimeInfo.GetDateTime(Info.UTC);
/*
** Here we have to set the Time of the system
*/
SystemTime.Year = (ushort)dtNow.Year;
SystemTime.Month = (ushort)dtNow.Month;
SystemTime.Day = (ushort)dtNow.Day;
SystemTime.DayOfWeek = (ushort)dtNow.DayOfWeek;
SystemTime.Hour = (ushort)dtNow.Hour;
SystemTime.Minute = (ushort)dtNow.Minute;
SystemTime.Second = (ushort)dtNow.Second;
SystemTime.Millisecond = (ushort)dtNow.Millisecond;
/*
** Set the time and hope that it works
*/
SetLocalTime(SystemTime);
}
catch(Exception)
{
}
finally
{
}
/*
** Wait till it is time to do it again
*/
while(!isStopped && (dtWait > DateTime.Now))
{
System.Threading.Thread.Sleep(1000);
System.Windows.Forms.Application.DoEvents();
}
}
}
}
|
|
|
|
|
Hi all,
I have three questions about changing an edit box BG color:
I am trying to change the background color of a multi line edit box, I use the WM_CTLCOLOR message and it works but:
First:
initially, when the color changes, the area that changes is only the first line of the edit box (the first line has the desired background color, while the other lines have the white(default) background color), and as I add lines (Enter Key) the following line changes color and so on.
how to solve this situation? I want the whole control to be painted with the desired bg color.
Second, Even when I change the color of a single line edit box, the color changes, but there still small rectangles of the default bg color in the bottom and the right side of the edit box, it really doesnt exactly have the same effect as writing in VB:
Text1.BGColor=vbBlack
Why?!!!
Thrid and last,
When I use the WM_CTLCOLOR message to change my edit box bg color, if the Locked state of the edit box is set, the color is not changed at all, I dont think its wrong to have a locked edit box with a black bg color.
how to solve this?
I hope I will find some help here.
Regards,
Mohammad Gdeisat
|
|
|
|
|
I think sheet of the pages is the place, but how can a page save a value in a variable in the sheet? Or , any other good ways? Thanks.
|
|
|
|
|
followait wrote:
I think sheet of the pages is the place, but how can a page save a value in a variable in the sheet?
What are you talking about ????
|
|
|
|
|
cedric moonen wrote:
What are you talking about ????
Tequila ?
hum, maybe he was saying - in his bad word - that he wanted to save in a property Sheet one variable that is to be shared between its property pages...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hello!
I wonder if there is some way or some trick to gather some info during compile time and using it at runtime ?
example1:
We have many cpp files. We have some #define CPP_COUNTER 0. There would be some code (macro?) at the begining of every cpp file which would increase this counter for 1. When linking the project, CPP_COUNTER would hold the number of cpp files. In runtime I would be aware of cpp files in the project by reading CPP_COUNTER definition.
example2:
We have many files in the project, but functionaly they are divided in few modules (dsp, writter, reader, etc). At compile time every cpp file would have at the begining some code which would register (to some global variable) to which module it belongs. Something like
REGISTER_MODULE(_FILENAME_, "disk writter")
In runtime I would be aware of all the modules in the system by looking at the global variable of all registered modules.
I would need something like example2 shows. Is it even possible? Is there some way?
Best regards,
Rostfrei
|
|
|
|
|
I have generated a window using AppWizard with a default DOC View classes. now i split my window into two. In the new pane i want to display log activities. how should i do it?
What i did was i derived a runtime class from CFormView and Created a Listbox in the form and using it. But the thing is i cannot access the memberfunctions of CFormView derived class because its constructor is private. And If I change it to Public it Gives assertion failure. Now if i want to access member function how can i do it.
One solution i thought is if i am able to access the only object crteated, i can use it. But i don't know how to get that object
|
|
|
|
|
CFrameWnd has a method GetActiveView().
Try using that to get a pointer to your view object.
|
|
|
|