|
Windows 7, Visual Studio MFC, C++, dialog based project
A dialog is to have a status display area. The code will add lines of text. My preference is for each new line of text to be added to the bottom and have the display scroll up. The user will not be able to edit the text, but it would be nice to be able to capture it with ctl-c to paste somewhere else.
I tried an edit control but each update wipes out the previous text.
List box seems to be the simplest control, yet still has many user accessible features.
I would like to read your reccomendations.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
|
Windows 7, Visual Studio 2008, MFC, CPP, std::map
I am trying to get an std::map working. I have tried several permutations and patterned it after some tutorials found with a search. Still I am unable to get it right and to decipher the error message.
Please assist with this problem.
The setup
typedef struct
{
unsigned int identifier_location;
unsigned int count_found;
CString key;
CString token[ MAX_TOKEN_COUNT ];
} td_tmats_attributes_definitions;
td_tmats_attributes_definitions m_one_definition_record;
std::map < CString, td_tmats_attributes_definitions > m_tmats_definition_map;
// ^ the key ^the data to store
// below is an alternate declaration.
std::map < string, td_tmats_attributes_definitions > m_tmats_definition_map_string;
And now the code
CString the_key;
…
The code:
m_tmats_definition_map.insert( the_key, m_one_definition_record );
string str_key = the_key;
Neither of the two options will compile.
I was prepared to post the error message, but I have a strong suspicion that reader will know my error with little effort and the long text from VS output box will only clutter things up. Let me know if you want to see the error text.
Please tell me what I need to change.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
modified 9-Jun-13 12:44pm.
|
|
|
|
|
m_tmats_definition_map.insert( std::make_pair(the_key, m_one_definition_record) );
OR
m_tmats_definition_map[the_key] = m_one_definition_record;
std::make_pair should be in the <utility> include.
|
|
|
|
|
As you already know, that compiles. I see the second option as being a bit more clear and used it.
Thank you for your time.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
Windows 7, 64 bit, Visual Studio 2008, MFC, C++
After a long series of searches looking for a nice method of reading from a text file into CString I arrived at the following:
<br />
CStdioFile definition_file;<br />
try<br />
{<br />
definition_file.Open( m_definition_file_name, CFile::modeRead );<br />
}<br />
catch( CFileException e )<br />
{<br />
e.m_cause;<br />
}<br />
This is from the VS help utility:
<br />
catch( CFileException* e )<br />
{<br />
if( e->m_cause == CFileException::fileNotFound )<br />
printf( "ERROR: File not found\n")<br />
e->Delete();<br />
}<br />
This leads to the concept
<br />
if( e->m_cause == CFileException::fileNotFound )<br />
printf( "ERROR: File not found\n");<br />
elseif( e->m_cause == CFileException::generic )<br />
printf( "ERROR: An unspecified error occurred.\n");<br />
elseif etc etc<br />
Is there a better way of capturing the text of the error rather than an if/else/else/else sequence?
Note: I am open to any type of suggestion. The goal is to read a CSV text file and parse it into a std::map.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
|
Cool.
Thank you.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
Oops, I have a follow up on this.
Declarations:
CFileException get_error_message;
const unsigned int ERROR_MAX = 64;
char char_error_text[ ERROR_MAX ];
LPTSTR ptr_error_text = &char_error_text[0];
CString final_error_message = "";
Code:
m_definition_file_name += "x";
try
{
m_definition_file.Open( m_definition_file_name, CFile::modeRead );
get_error_message.GetErrorMessage( ptr_error_text, ERROR_MAX, NULL );
final_error_message = char_error_text;
error_number = GetLastError();
}
catch( CFileException e )
{ code }
catch( ... )
{ code }
{
The line m_definition_file_name += "x" forces the file name to be incorrect.
Char array char_error_text winds up with "No error occurred." while error_number gets 0 (zero)
When the line error_number = GetLastErrror is moved directly beneath the open command, it get the value 2 (two). But that consumes the last error and get_error_message does not get anything.
Nothing is thrown and neither catch is activated.
What do I need to change to use this CFileException?
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
I don't understand what you are doing here; it should be:
try
{
}
catch (CFileException ce)
{
TCHAR message[132];
if (ce.GetErrorMessage(message, 132, NULL)
{
}
}
Use the best guess
|
|
|
|
|
Hello,
I don't see what you have different. Second, when the file does not exist, this Open method does not throw an exception, so none of the try/catch matters. I had a catch(...) at the bottom and it was not entered.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
If the open function does not throw an error then you need to check the return value and call GetLastError() to find out why, as described here[^]. Alternatively you can throw a new exception like:
try
{
if (!m_definition_file.Open(m_definition_file_name, CFile::modeRead))
{
DWORD error_number = GetLastError();
throw new CFileException::OsErrorToException(error_number);
}
}
catch( CFileException e )
{
}
Note that when calling GetLastError() you must call it immediately after the failing API function call, otherwise its return may not be valid.
Use the best guess
|
|
|
|
|
I have also tried this.
Declarations:
const unsigned int ERROR_MAX = 64;
char char_error_text[ ERROR_MAX ];
LPTSTR ptr_error_text = &char_error_text[0];
CString final_error_message = "";
With this code
m_definition_file.Open( m_definition_file_name, CFile::modeRead );
error_number = GetLastError();
format_message_return = FormatMessage( 0, // dwFlags
NULL, // lpSousrce
error_number, // dwMessageID
NULL, // dwLanguageId
ptr_error_text, // lpBuffer
ERROR_MAX, // nSize
NULL ); // Arguments
final_error_message = char_error_text;
The error number is 2 (two). char_error_text ends up with nothing. I am uncertain of the arguments for FormatMessage. The file name is forced to be incorrect and an error is expected.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
I have yet to get a text based error code for opening a file. Here is the simplified code:
m_definition_file_name = Select_Definition_File.GetPathName();
m_definition_file_name += "x"; m_definition_file.Open( m_definition_file_name, CFile::modeRead );
get_error_message.GetErrorMessage( ptr_error_text, ERROR_MAX, NULL );
final_error_message = char_error_text;
The Open method does not throw an exception. When GetLasError() is used, the error code is 2 (two).
The GetErrorMesssage yields No error returned, which is incorrect. The file could not be opened because it does not exist.
GetErrorMessage(...) is has three arguments about formatting the error message, but the error message is not an argument. I presume it gets the error message like GetLastError() does, but this appears incorrect.
How do I get a text string describing this error?
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
I gave you a suggested solution at http://www.codeproject.com/Messages/4583835/Re-CFileException-discover-reasons.aspx[^], which should throw an exception whose value would be CFileException::fileNotFound (error code 2). Did you try it, and if so what result did you get?
In response to your comment about FormatMessage , you need to tell the function where to look for the mappings of error codes to messages thus:
format_message_return = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error_number, NULL, ptr_error_text, ERROR_MAX, NULL );
This is explained in full detail in the documentation[^].
Use the best guess
|
|
|
|
|
My apologies for no replying sooner. I followed your advice and now have that FormatMessage method working. Thank you.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
You're welcome.
Use the best guess
|
|
|
|
|
I have thousands lines of C++ codes which work well on small text files, but crashes on huge text files (such as 2 GB size). Crash reason: app eats up memory.
Is it possible to allocate memory from disk? Because in most case, hard disk space is much bigger than physical memory. If I can borrow some space from hard disk for my app and return them back after use, then my app has little chance to crash.
Here are my design thoughts:
1.Create a temporary file for file mapping(CreateFileMapping, OpenFileMapping)
2.Force my app to allocate memory from the temporary file
3.Do some clean up work: CloseFileMapping and delete the temporary file
Because I have so much existing code, if my design thought is reasonable, I don't want to redesign my project.
I'm not sure if the design thought is possible to implement. Anybody can help me?
PS: I'm using Visual C++ 2010.
|
|
|
|
|
The most elegant approach is to use MapViewOfFile to only map a smaller piece of the file at any one time, one that does fit into your address space, and then shift the view by Unmap/Map-ing.
In conjunction with this, a way to slightly extend the limit of what can fit in your address space is to set the /LARGEADDRESSAWARE compiler switch, which can be found under the properties. This tells the compiler that you are aware of that 32 bits pointer can use the full range of 0 - 2^32-1, rather than only half that range 2^31-1. With this, you might be able to reach up to ~3GB, depending on system configuration and your application. However, this only slightly shifts the available memory.
Using the above approach, you map the piece of file that you want to use into your address space, and as soon as you are done with the current piece you map the next, etc.
|
|
|
|
|
thank you for your advice, i will have a try. 
|
|
|
|
|
We have a method using ippiFFT to perform forward and inverse FFT of an Image. This method calls ippiFFT 3 times. We try apply cilk_spawn with purpose improve performance of FFT processing, but processing speed of the method is slower than source without cilk_spawn (decreased about 1.5 times). We don't known what is the problem, please help us!
I will describe shortly here:
void performFFT(int start, int end, Ipp32fc[] image)
{
for(int i = start; i < end; i++)
{
ippiFFTInv(Image[i])....
ippiFFTInv(Image[i])....
ippiFFTFwd(Image[i])....
}
}
Source calls method performFFT without cilk_spawn:
Image[10];
performFFT(0, 10, Image);
Source calls method performFFT with cilk_spawn: (which is performance decrease 1.5 times)
Image[10];
cilk_spawn performFFT(0,5, Image);
performFFT(5,10,Image);
cilk_sync;
|
|
|
|
|
How to remove COM objects In-placed of regular DLLs in vc++ projects?
Prashant Gupta
|
|
|
|
|
Your question is not clear, please explain what problem you are trying to solve.
Use the best guess
|
|
|
|
|
Actually we are implementing a VC++ based application that use few COM objects, COM objects create problem when I think register them(not sure) during compilation.
So we want to replace COM objects by regular DLLs from our application.
I want to know the process that how to remove COM objects.

|
|
|
|
|
Prashant Gupta 241 wrote: So we want to replace COM objects by regular DLLs from our application.
I want to know the process that how to remove COM objects. There is no "process", you just need to rewrite the code where it makes calls to the COM interfaces, such that it uses regular function calls. I am not aware of any simplified method of doing this.
Use the best guess
|
|
|
|
|