|
fTest << (LPCTSTR)cstr;
TOXCCT >>> GEII power
|
|
|
|
|
When you typecast object of CString with LPCTSTR, internally overloaded operator LPCTSTR will get called. else explicily call function of CString class "operator LPCTSTR()"
This will convert CString object to Long Pointer To Constant String which is acceptable format for ofstream.
The chosen One
|
|
|
|
|
Hmmm, I tried your exact code (without the suggested cast) and it wrote "This is a test" to the file.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
You're using VS.NET 2002 or 2003, while the OP is using VC6. Something in either the standard library or in CString has changed enough to fix this issue between the two.
The changes to CString in MFC 7.x are extensive: it's now defined in an ATL header, for a start. It's also a template class: CString is a typedef for CStringT< StrTraitMFC< TCHAR, ChTraitsCRT< TCHAR > > >.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Mike Dimmick wrote:
You're using VS.NET 2002 or 2003, while the OP is using VC6...
Actually, I've never even seen VS.NET 2002 or 2003, let alone used either of them. I am using VS6.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I copied the OP's code into a new Win32 Console project in VC6 (selecting 'An application that supports MFC' from the Wizard). It produced the original output. Opening the project in VS.NET 2003, converting it and rebuilding produced the correct output.
The fault is that the compiler appears to be selecting the class member (of basic_ostream ) operator<<(const void*) for some reason. It's definitely calling CString::operator LPCTSTR to get the pointer whether you include the explicit cast or not.
Have you upgraded to Visual Studio 6.0 Service Pack 6, and could this be a solution to the problem?
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Mike Dimmick wrote:
Have you upgraded to Visual Studio 6.0 Service Pack 6...
Yes, I have SP6.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
You have to cast the CString to an LPCTSTR ala
fTest << (LPCTSTR)cstr;
So that the insertion operator uses the right overload.
If you're using unicode, (e.g., L"This is a test" or, _T("This is a test") and unicode is turned on), then you'll want to use a std::wofstream instead of std::ofstream. But you'll still need to cast cstr to LPCTSTR.
If you, like me, tried testing this with cout, try using wcout instead (the cast to LPCTSTR is still required).
|
|
|
|
|
Dear friends,
My brother's company have a PABX within their premises. They have asked me to develop a telephoning system for them.
i) How do I access the PABX,
ii) How do I recognise telephone numbers from the PABX
iii)How do I read from the PABX
iv) How do I write to the PABX
v) How do I connect an inside caller to the ouside reciept
Just using the computer and the PABX with no operator intervention.
I need both logic and syntax answers.
Yours
Lloyd.
|
|
|
|
|
Wisdom2004 wrote:
i) How do I access the PABX,
ii) How do I recognise telephone numbers from the PABX
iii)How do I read from the PABX
iv) How do I write to the PABX
v) How do I connect an inside caller to the ouside reciept
Just using the computer and the PABX with no operator intervention.
First you need to know the make of PABX. Then visit the manufactuers web-site to find out what development tools are available.
Most PABX's today, either connect to a server via USB or TCP/IP.
Some PABX's support TAPI, others have their own custom API. The first thing to do is contact either the supplier or the manufactuer and find out what they support.
Michael
CP Blog [^]
|
|
|
|
|
Hi guys
It's possible to take benefit of serialize on a Single document app. but changing the filename and not having to go to Save_as dialog? I mean,just clicking a button?
Best Regards
Doc
|
|
|
|
|
Sorry guys
It's just calling OnSaveDocument(myfilename) ?
Best Regards
Doc
|
|
|
|
|
Hai guys,
Sorry I must have kind of misformed yu, on my request. Previously I wrote Dailogue Boxes but I meant Dialogue forms.
The point is, I'am able to develop database applications using document forms/views. But I would like to develop them using Dialogue forms/views. When using Document forms, the procedure is clear as there is a provision to specify the Database name,tables e.t.c. But for Dialogue forms, my book says I type some C++ codes(forgive me dont have it here)amongst the header files. But when I compile the program, I have errors and the program can not access the Database/tables.
Please what is the specific code I need to add to my dialogue form application and in which files. Also what changes do I need to make to the Dialogue form properties in order to be able to retrieve a Recordset from a database.
Your friend and partiner
Lloyd
|
|
|
|
|
I using GDI+ to display text but cannot display text with specific character spacing
aaaaaa
bbbbbb
cccccc
dddddd
eeeeee
|
|
|
|
|
After many hours of playing around with the new UI of VS7, I've finally figured out how to add a control member variable to the project.
But is there an automated way to remove said class variables like VS6's classwizard used to be able to do?
I Dream of Absolute Zero
|
|
|
|
|
Visual Studio .NET 2002? I am interested about this, too.
Maxwell Chen
|
|
|
|
|
I'm using VS.NET 2003 (V7.1), but I'm sure the solution (if any) will apply to 2002 also.
So if any VS geniuses outthere knows the answer....
I Dream of Absolute Zero
|
|
|
|
|
Consider an add in?
http://www.codeproject.com/macro/classwizardnet.asp
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
Hi
In VC7, there is this compile option /RTCu which helps you detect use of an unintialised variable in debug builds. I tried turning it off in projects properties>C++>Code generation, and rebuilt the solution but the error message still pops up.
Does any one know what I am missing?
Thanks!
|
|
|
|
|
Do you see the /RTCu in your command line?
(I will usually change the *.dsp manually using notepad if the IDE doesn't do it for me. But this is not advisable of course)
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
I have an MFC application which creates a thread to receive a stream of data from another application in bursts.
Now the thread is started by the main MFC program via:-
m_DisplayTextThread = ::AfxBeginThread(CTestGUI1Dlg::DisplayTextThread, (LPVOID) &m_DisplayThreadData);
and passed the pointer (this) of the main MFC application in the structure m_DisplayThreadData in order for it to access the methods/properties of the main MFC application that require updating.
This causes an Assertion fault, and it was suggested (in a previous post) that PostThreadMessage be used to communicate from the thread to the main application.
My question is - what is the scheme to use for this type of activity, where the GUI needs to reflect data received, but when the receive processing is done in a different thread.
How would this be done? I have looked up PostThreadMessage but dont see how to use it.
I have tended to pass into the thread the neccessary data/pointer the thread required, but this time I have problems.
If I use a smple timer in place of the thread all is well, but have to run slow to ensure that I do not loose data.
|
|
|
|
|
I would suggest using PostThreadMessage just to signal to the main thread (MFC application) that something happened in the receive thread.
The receive thread updates the (pointer of the) data passed and just signal to the main thread to do his work.
I personnaly would go for events.
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
OK, but how do you use PostThreadMessage in the thread to arrange a routine to run in the main application.
Also, you said use Events, but that means another thread waiting on the event and needs to arrange the main MFC application to do something.
I dont understand how to get something running in the main MFC application from a thread other than the use of the 'this' pointer passed into the thread. But thats causing a problem.
|
|
|
|
|
try PostMessage in place of PostThreadMessage.
As I understand, Here you want to notify the main application when the data is received by the thread. so it would be the right option to use PostMessage for posting the messages to the main application window. You can you the pointer to the Main application windows/ Dialog whatever the UserInterce Object to which you want to be updated.
You can implement it easily - the steps is as follows
1. define a user defined Message.
2. provide the handler associated with that message in the UserInterface object (Application Window/ Dialog)
3. use PostMessage as you receive the data in Thread.
enjoy
Jitendra
|
|
|
|
|
sweep123 wrote:
Now the thread is started by the main MFC program via:-
m_DisplayTextThread = ::AfxBeginThread(CTestGUI1Dlg::DisplayTextThread, (LPVOID) &m_DisplayThreadData);
and passed the pointer (this) of the main MFC application in the structure m_DisplayThreadData in order for it to access the methods/properties of the main MFC application that require updating.
Regarding thread startup...
Without exceptions I pass the this-pointer when spawning threads since I consider it good modeling and encapsulation. It also simplifies my life since I can use PostMessage from my thread in the way that you want/need. My header files looks something like this:
class CMyDialog : public CDialog
{
.....
protected:
static UINT MyThreadFn( LPVOID pThis ) { return ((CMyDialog*)pThis)->MyThreadFn(); }
UINT MyThreadFn();
volatile BOOL m_bStopMyThread;
CWinThread* m_pMyThread;
....
}; This way I get access to member variables from the thread function MyThread() without polluting the code with a lot of type casting.
sweep123 wrote:
My question is - what is the scheme to use for this type of activity, where the GUI needs to reflect data received, but when the receive processing is done in a different thread.
How would this be done? I have looked up PostThreadMessage but dont see how to use it.
If you use the thread solution above you can forget about PostThreadMessage and use PostMessage instead from your thread since the thread function is a member of a CWnd derived class.
All you need is to define a message ID for your message, declare a message handler, add a message entry in the message map and implement your message handler. In code it would look something like this for the header file:
#define UWM_MY_MESSAGE (WM_APP + 1)
class CMyClass : public CDialog
{
....
afx_msg LRESULT OnMyMessage( WPARAM wParam, LPARAM lParam );
....
}; ...and for the cpp file:
....
BEGIN_MESSAGE_MAP(CMyClass, CDialog)
....
ON_MESSAGE( UWM_MY_MESSAGE, OnMyMessage )
....
END_MESSAGE_MAP()
....
....
LRESULT CMyClass::OnMyMessage( WPARAM wParam, LPARAM lParam )
{
return 0;
} If you want you can send the length and a pointer to data from your thread using the two parameters wParam and lParam. The memory allocation is done in your thread and deallocation is done in the message handler. Something like this for the thread:
UINT CMyClass::MyThreadFn()
{
WORD wLength;
BYTE* pData;
....
while( !m_bStopMyThread )
{
....
pData = new BYTE[wLength];
PostMessage( UWM_MY_MESSAGE, (WPARAM)wLength, (LPARAM)pByte );
....
}
....
} and for the message handler...
LRESULT CMyClass::OnMyMessage( WPARAM wParam, LPARAM lParam )
{
WORD wLength = (WORD)wParam;
BYTE* pData = (BYTE*)lParam;
....
delete pData;
return 0;
}
Hope this helps
--
Roger
|
|
|
|