|
You beat me to it.
I must refresh my browser more often.
|
|
|
|
|
You should test for the end of the file using the result from ReadString method of CStdioFile . ReadString returns a NULL pointer when the end of file has been reached. See here[^] for additional details.
A little change for your code:
if(fileread.Open("C:\\Test.txt", CFile::modeRead | CFile::modeNoTruncate))
{
CString readstring="";
fileread.Seek(0,CFile::begin);
while(fileread.ReadString(readstring))
{
}
fileread.Close();
}
|
|
|
|
|
Happens to the best of us.
|
|
|
|
|
Hi,
I have an application developed using wxWidgets(C++ based) with Visual C++ 2008 standard edition. The application runs fine without any problem. But when it comes to closing of an application, it throws and exception message stating
An unhandled win32 exception has occurred in myapp.exe [892]
the number in [] keeps on changing every time.
How do i come out of this exception.? Or can anyone one tell me what leads to such exception??
Thanks in advance
|
|
|
|
|
It could be a lot of things. I suggest you use your debugger to track down the problem, that's one of the best way to retrieve more information about the error.
|
|
|
|
|
The number you see is the process identifier. This is likely to be a new number every time your application is running.
|
|
|
|
|
Did you try to debug the cause after you try to close the window?
If not, it would be a good idea to do that. Alternatively you can take a minidump of the application and use a tool like windbg to analyze the crash.
I am a HUMAN. I have that keyword (??? too much) in my name........
_AnsHUMAN_b>
|
|
|
|
|
The most common cause I've seen of an exception when you close an application is that someone's been way too clever and generously used pointers mixed with a soupcon of manual memory management. The most common results have been:
- damaging the heap by overwriting something you shouldn't
- double deletion of an object
- using a deleted object
The best way of avoiding this sort of problem is to not have it in the first place. Don't play with pointers and manual memory management unless you really have to. If you do make sure you use all the facilities of the language and runtime library to help you.
Anyway, that's advice for next time... in the meantime have a look at the documentation for structured exception handling (SEH) and how to convert win32 structured exceptions into C++ exceptions. That might help you work out what's happening by decoding what the win32 exception is in the first place.
Another thing you could do is start building earlier versions of the code until you find one that the problem didn't happen in and start working forwards again until you find the first version that caused the problem. The diffs between the versions might give you an idea of what's happening that caused the error.
Cheers,
Ash
|
|
|
|
|
Hi all, i want to play Media player in application im using VC++ 2005,i have added Windows Media Player via COM, and added buttons play stop and pause.
In VC++ 6 there is options like
m_player.SetUrl ("c:\\abc.wmv");
m_player.GetControls().play();
But in VC++ 2005 I am not Getting those options? plz help me.
I wanted to play the WMP in Windows CE?
So please Help me. I have no Idea how to play a Vedio files?
Thanks in advance.
|
|
|
|
|
if you are using .NET framework, please post it in Managed C++/CLI forums
|
|
|
|
|
I too am looking to do the same thing in an existing large Visual Studio 2005 MFC C++ Application.
- Have added the Windows Media Player Control but can't seem to find the way at runtime to add a URL to point to a local file or point to an http:// Address.
So some details would be helpful for the person that originally asked the question and those that are looking for similar answers.
In a Visual Studio 2005 C# project it is very simple to do... just add the Windows Media Player Control to the form. Call the Control "MediaPlayer". Then in your code set the URL to a file or a http:// value as needed.
MediaPlayer.URL = "C:\Windows\Media\FileToBePlayed.avi";
It is quite a bit different in Visual Studio 2005 MFC C++... the Windows Media Player Control objects that are exposed in C# are not exposed in C++... perhaps there is something that got missed along the way.
My search goes on...
-- Modified Tuesday, April 5, 2011 3:48 PM
|
|
|
|
|
Hi,
I already have three registry values (type=REG_SZ):
HKEY_CURRENT_USER\SOFTWARE\FARM\ValueName1
[Value1=I like]
HKEY_CURRENT_USER\SOFTWARE\FARM\ValueName2
[Value2=Apples]
HKEY_CURRENT_USER\SOFTWARE\FARM\ValueName3
[Value3=NULL]
I need a piece of code that reads Value1 and Value2, combine them together and write them to Value3 so Value3 becomes:
HKEY_CURRENT_USER\SOFTWARE\FARM\ValueName3
[Value3=I like Apples]
That's all! simple no? but I have been trying all the day but nothing seems to want to work!
Any help would be very appreciated
|
|
|
|
|
RegOpenKeyEx /RegCloseKey will open and close registry keys.
RegQueryValueEx will read values from the registry key.
RegSetValueEx will write values to the registry key.
For combining values use string functions like _tcscat or the CString + operator .
|
|
|
|
|
Thank you but I know all that staff, my problem is how to make it work!
Here's a code I use (ignored error checking)
unsigned long type=REG_SZ, size=1024;
char iLike[1024]="";
char Apples[1024]="";
char iLikeApples[1024]="";
LONG rV;
HKEY hKey = NULL;
// reading the first value
rV = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\FARM\\ValueName1", 0, KEY_ALL_ACCESS, hKey);
rV = RegQueryValueEx(hKey, "Value1", NULL, type, (LPBYTE)iLike, size);
RegCloseKey(hKey);
// reading the second value
rV = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\FARM\\ValueName2", 0, KEY_ALL_ACCESS, hKey);
rV = RegQueryValueEx(hKey, "Value2", NULL, type, (LPBYTE)Apples, size);
RegCloseKey(hKey);
// combining values
[code?]
// writing the third value
rV = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\FARM\\ValueName3", 0, KEY_ALL_ACCESS, hKey);
rV = RegSetValueEx(hKey, "Value3", 0, REG_SZ, [parameter1?], [parameter2?]);
RegCloseKey(hKey);
Please tell me what I should put in the the place of [code?], [parameter1?] and [parameter2?]
please do not advice me to use this or use that, if you want to help me just complete the code above.
Thank you VERY for you help
|
|
|
|
|
[code?]
_tcscpy_s(iLikeApples, 1024, iLike);
_tcscat(iLikeApples, Apples); [parameter1?]
(LPBYTE)iLikeApples
[parameter2?]
_tcslen(iLikeApples)
|
|
|
|
|
I love you man
|
|
|
|
|
Here's a code I use (ignored error checking)
unsigned long type=REG_SZ, size=1024;
char iLike[1024]="";
char Apples[1024]="";
char iLikeApples[1024]="";
LONG rV;
HKEY hKey = NULL;
// reading the first value
rV = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\FARM\\ValueName1", 0, KEY_ALL_ACCESS, hKey);
rV = RegQueryValueEx(hKey, "Value1", NULL, type, (LPBYTE)iLike, size);
RegCloseKey(hKey);
// reading the second value
rV = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\FARM\\ValueName2", 0, KEY_ALL_ACCESS, hKey);
rV = RegQueryValueEx(hKey, "Value2", NULL, type, (LPBYTE)Apples, size);
RegCloseKey(hKey);
// combining values
[code?]
// writing the third value
rV = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\FARM\\ValueName3", 0, KEY_ALL_ACCESS, hKey);
rV = RegSetValueEx(hKey, "Value3", 0, type, [parameter1?], [parameter2?]);
RegCloseKey(hKey);
Please tell me what I should put in the the place of [code?], [parameter1?] and [parameter2?]
please do not advice me to use this or use that, if you want to help me just complete the code above.
Thank you VERY much for your help
|
|
|
|
|
I'm basically curious about the heap, and how the operating system manages this type of memory.
I have a couple of applications, in which I have created and allocated alot of data which resides in a single C++ class instance, and I have not used any explicit heap memory allocation functions. This seems to work fine, and I'm not likely to have any security-related problems (these objects are NOT COM objects, nor, are they shared resources nor accessed externally from my local machine).
The size of these objects are in the range of 100 KB to about 350 KB. I'm wondering if this is a good idea, to just let the memory manager allocate this data, or should I explicitly allocate a private heap? These objects are usually used just as single instances,...occasionally, it will be deleted and re-allocated, but typically they are just single use class objects.
Of course, I could break up the objects into alot of smaller components, but, then again, is this necessarily a good idea?
I'd appreciate any suggestions. Thanks.
|
|
|
|
|
How are you allocating the objects? Using new ? new allocates its memory from the heap. You're almost certainly better off leaving the memory allocation details to the system.
Steve
|
|
|
|
|
Global variables kill optimization opportunities. Unless you understand memory well and will do all work from this class, you do not want to manage your own pool of memory like that. If you did chose to manage your own memory, then you may use C functions instead of new (especially if the data types are all primitive like double, long, int, etc.). This means that you have to handle construction, destruction properly yourself, but you can get speedups by bypassing unnecessary initializations.
|
|
|
|
|
It depends on your compilers runtime library but generally the operating system doesn't have a lot to do with the C++ heap. As a first approximation what happens for new ing objects is that the runtime allocates a big chunk of memory and then suballocates objects out of that block. When it runs out of that block it allocates another and starts allocating out of that.
However the real world of C++ allocators and operating system heaps is rarely that simple anymore. For example Windows 2000 (I think, haven't got my reference books to check so I could well be wrong) introduced a small object heap that allocated chunks of memory for objects of different size ranges to avoid fragmentation of the heap. At least one C++ compiler I've used used a similar set of blocks for different sizes for the same reasons.
Other optimisations I've seen include different heaps or blocks per thread. Most programmers don't want their threads blocking if a memory allocation is attempted and then there's the whole issue of using garbage collection for recovering memory for the heap rather than doing it when the program deletes an object. If you defer memory recovery to a garbage collector you end up avoiding one of the bottle necks in multithreaded code if the heap is shared between threads.
So basically only worry about it if you find that you can't create the objects you need or if you've profiled your app and found that it's spending way too much time in the memory allocator.
Cheers,
Ash
PS: There's no such thing as "class objects" in C++. Classes are just things the compiler sees, once the program is compiled classes don't really exist anymore, unlike Java or Smalltalk where everything's an object including classes.
|
|
|
|
|
Yes, the objects are created with the new operator, that way I can just call delete on the object pointer. It's mostly for convenience.
...And, I only have one main thread in these applications,...the sequence of operations are not all that complicated. The end result is to write alot of the data to file.
I had thought that for small objects, they would somehow live on the stack. (Shows you how ignorant I am of memory management.)
The term "class objects" I just use to describe what is a contiguous block of data. You seemed to get the idea pretty clearly.
Thanks for the information. I'll play around with it a little, just to get a better idea of how it works.
|
|
|
|
|
I am facing a problem where i dont receive the MSMQ events on 64 bit machine. The same code works fine on a 32 bit server but not on 64. Below is how the Sink mapping is done.
BEGIN_SINK_MAP(CMailQueueServer)
SINK_ENTRY_EX(0, DIID__DMSMQEventEvents, 0, Arrived)
SINK_ENTRY_EX(0, DIID__DMSMQEventEvents, 1, ArrivedError)
END_SINK_MAP()
I can queue up messages but the event doesnt get fired, the items in the queue remains unprocessed. Does it have to be handled differently in 64 bit server?
Any help will be greatly appreciated!!!
Hariharan.T
|
|
|
|
|
Hi,
I am trying to figure out a way to draw a polygon directly onto a dib. Currently when the user selects points on the image(view) I draw it directly onto the DC until the user click right mouse button at which point I would like to actually update it on the bitmap that I am displaying. My bitmap is a DIB derived by my own class which has access to bitmap handle (HBITMAP) and bitmap data etc.
One way is to draw a polygon manually by computing all the indices and update pixel by pixel, but for bigger polygons it gets tedious and I am not in favor of doing this way.
Any help is greatly appreciated.
thanks
PT
|
|
|
|
|
See the competitors (funny enough, it is a returning link...) [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|