|
Your code verbatim compiles fine for me.
Larry Mills Sr wrote: CString s = NULL;
What is this line for?
The assignment is unnecessary as well - the default CString constructor
will create an empty string.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
CString s = NULL; I'm setting up a CString for exchanging characters from the file to past to a vector. I think maybe something nis wrong with the compiler if your compiler had no trouble with it. Any ideas?
I've tried everything I know(which isn't much grant you) and I still get the same errors.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: LPTSTR lpsz = new TCHAR[sizeOfString];/// gives error here
Have you tried:
LPTSTR lpsz = new TCHAR[67]; just to narrow the problem down?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I gu have a "Some-Timey" compiler. Everything works now and I haven't changed anything. Thanks
A C++ programming language novice, but striving to learn
|
|
|
|
|
I am trying to close a COM port if no data is received. My current appraoch is to use the CreateThread function to call a watchdog thread, the thread locks up when it executes the CloseHandle function, it is using the correct handle.
Any suggestions?
Thanks, for your help.
|
|
|
|
|
jonsey29847 wrote: the thread locks up when it executes the CloseHandle function
CloseHandle never returns?
What's going on at the time on the read thread?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You are correct my thread locks at the CloseHandle function. The read is part of WinMain. Mt thinking was to start a thread at the read function, then time for response and if no response within watchdog, close handle to return control to WinMain. Where is my defective thinking?
Thanks...
|
|
|
|
|
Sorry I did not completely read your question. The application is attempting to read from the COM port using the ReadFile function.
DWORD ReadFromCOMPort(HANDLE hCOM, TCHAR *tcRecdData, int nBytesToRead)<br />
{<br />
DWORD dwEventMask;<br />
if(!SetCommMask(hCOM, EV_RXCHAR))<br />
{<br />
SetLastError(SETCOMMMASK_FAILED);<br />
return 0;<br />
}<br />
<br />
if(WaitCommEvent(hCOM, &dwEventMask, NULL))<br />
{<br />
char *cTempString;<br />
int nLen, nStart;<br />
DWORD dwBytesRead;<br />
DWORD dwSize = 0;<br />
<br />
if(ReadFile(hCOM, tcRecdData, nBytesToRead, &dwBytesRead, NULL) != 0)<br />
{<br />
return dwBytesRead;<br />
}<br />
}<br />
return 0;<br />
}<br />
<br />
|
|
|
|
|
AFAIK, only Vista+ gives you the ability to cancel a synchronous read operation
from another thread (see the CancelSynchronousIo() function).
The correct way to handle this would be to use overlapped I/O.
That would eliminate the need for a second thread as well.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes, as I dig into this I am coming to accept the inevitable.
Thank you once again for your help.
|
|
|
|
|
I am trying to restrict operation to a single instance of my program (per user). Specifically, I create a shortcut in the "Send To" folder. If the program (an MDI program based on the MFC Doc/View architecture) is NOT running, right-clicking on a file in the Send-To context menu correctly runs the program with the file name as a command line argument. It I select the program again from the context Send-To menu a new instance of my program starts. What I would like to happen is that the new file is opened by the running instance of the program in a new MDI window.
Could someone point me in the right direction for this? I did find code that prevents a second instance of the program from running. Unfortunately, it doesn't default to the OpenDocument option in the running instance of my program. (I'm using VS 2005, C++, MFC)
TIA
Ron
|
|
|
|
|
First, maybe check this out: Avoiding Multiple Instances of an Application[^]
Once you determine an instance of your application is already running,
you'll need a way to pass the commandline parameters from the
process launched by the Windows shell to the already-running process.
Some form of interprocess communication can do this, like a named pipe
or sockets. See Interprocess Communications[^]
When the already-running instance of the application receives a command
from the shell-launched instance, then it can open the file as usual.
The shell-launched instance can terminate.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I have a FormView based SDI App with three modeless dialogs embedded in a CTabCtrl. Sometimes I am getting the Program Shutdown while the mouse pointer placed on toolbar. Though this is not happening always, but sometimes the program halts by displaying illegal operation. I know that this happens bcoz of the modeless dialog. It happens that since the focus is changed from child window to toolbar some wierd things are happening.
Any help in this regard is highly appreciated. To give you more info, The Codeproject's CHyperbar Control in Ultimate Toolbox explain this scenario, but I could n't find out any solution.
I remain,
Shanmukha
|
|
|
|
|
hi all
I want to make a search engine using VC++, can any one help me please by any information about this subject?
Thank you
|
|
|
|
|
Do you want to search on the computer?
|
|
|
|
|
hi guys
i have a dialog which has a background image, there is a button and a listctrl, i want to make the button and listctrl semi transparent or transparent so that the dialog background will be visible through listctrl, i can set a background image in list ctrl but tht i dont want.
Swarup
|
|
|
|
|
swarup wrote: ...i want to make the button...transparent...
See here.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hi guys
i have a dialog based application, when i run a time consuming operation, the dialog box hang, becas unless the operation completes my dialog box wont have any focus or will nt be able to recieve any message.
Example: i have a listctrl where i add 10000 records, so unless all records are added my dialog will nt respond. where as while those records being added i want my dialog box to be responsive, i cant let the user to wait till the operation gets over,
any idea,
there is a code sample called backgroundtask dialog here CP, i dont want that way.
Swarup
|
|
|
|
|
|
Doing your lengthy process on a separate thread is the recommended way
to go.
If you don't want to use multiple threads, then your lengthy process needs
to periodically pump all Windows messages so the UI will remain
responsive.
Here's an example MFC message pump (implemented in the application class)
void CMyWinApp::PumpWaitingMessages()
{
MSG msg;
while ( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if ( !PumpMessage( ) )
{
break;
}
}
}
A Win32 message pump could be something like
MSG msg;
while ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
Note that you'll want to disable any UI components that you don't want the user
to mess with during the lengthy process.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello everyone,
In the case when function in derived class is virtual, but function in base class is not virtual, when we make base class pointer pointing to derived class' instance, the function in base will be invoked.
I am confused why not the function in Derived class is invoked (this is my question).
When making base pointer pointing to derived class' instance, the layout of derived class should begin with vtable of functions of derived class (virtual function of foo in Derived class in the sample), and the base pointer is pointing to the layout, so when invoking the derived class version function could be found in vtable and it should be invoked. How compiler process this situation internally?
class Base {
public:
void foo()
{
cout << "Base foo " << endl;
}
};
class Derived: public Base {
public:
virtual void foo()
{
cout << "Derived foo " << endl;
}
};
int main()
{
Derived d;
Base* pb = dynamic_cast<base*>(&d);
pb->foo();
pb = static_cast<base*>(&d);
pb->foo();
pb = &d;
pb->foo();
return 0;
}
</base*></base*>
thanks in advance,
George
|
|
|
|
|
Hi,
If my memory serves me well,
Because the foo function of the base class isn't virtual, the address isn't placed in the virtual function table. So when te linker needs to link all functions it knowns to uses the known base::foo address. So when you cast an derived object back to the base class it behaves as an object of the base class. It doesn't matter whether there is a function Derived:foo in the vtable the compiler/linker is hardlinked to Base::Foo.
codito ergo sum
|
|
|
|
|
It's nothing to do with the linker. The pointer pb is a pointer to a Base and in Base the foo function isn't virtual .
Steve
|
|
|
|
|
I agree, thanks Steve!
regards,
George
|
|
|
|
|
Thanks BadKarma,
My question is answered.
regards,
George
|
|
|
|