|
Hi world...
OS = Win2K with VC++6.0
I have some problem but I don't know who causes this problem (I suppose that's the use of exception)...!!!
The problem is that I catch a BSOD!
How the use of exception can gives me a BSOD???
Can I throw exceptions OR use return inside a catch statement?
Is that permitted?
Thanks in advance...
Hello World!!!
from Raphaël
|
|
|
|
|
If you can I don't know, but you may (at least this month).
If you return you should delete the exception, usually by calling e->Delete().
You may also throw this same exception again, or throw another one. In this case you also should Delete() the old exception.
If you throw the same exception it won't be caught by this code, because it is thrown outside the try block. In this case it acts like it is passed through.
G. Steudtel
|
|
|
|
|
G. Steudtel wrote:
If you can I don't know, but you may (at least this month).
Oops... Sorry... But I'm not an English expert...
I don't use CException of MFC!!! I use exception class from the C++ standard library. Thus, How to reproduce the delete method of MFC?
Re-thanks...
Hello World!!!
from Raphaël
|
|
|
|
|
You throw by value, and you catch by const reference .
No need to delete, you make these Exceptions on the stack, and if you re-throw it will get copied.
This way you can catch a derived exception as its base (say std::exception), re throw the std::exception object and catch again as a derived exception.
And NEVER EVER touch MFC exceptions....
I have a small hierarchy of exception classes, eventually derived from std::exeption, and their c'tors are filling the error-string with a sensible message, and then add filename and line number of the error to member strings, so I can have a look when debugging.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
I want to make sure that no one deleted my data files in my program . Is there a where i can write protect a folders or files so to prevent it from deleted . Also is it possible to set a folder to be a system folder so it can be invisible ?
|
|
|
|
|
Hi, I want to ask if I can have a variable in a namespace that all namespace's functions can hava access to it, for example:
<br />
namespace foo<br />
{<br />
int x;<br />
<br />
extern void yak();<br />
extern void bar();<br />
}<br />
<br />
void foo::yak()<br />
{<br />
x++;<br />
}<br />
<br />
void foo::bar()<br />
{<br />
x--;<br />
}<br />
Can I make both yak() and bar() to operate on x? I get a linking error this way, saying that I've multiple definitions of int foo::x.
Thank you, Themis
|
|
|
|
|
You can try something like:
namespace foo
{
extern int x;
void yak();
void bar();
}
(you dont need to define the functions as extern)
Then just make sure you instance the variable in one place only:
int foo::x = 0;
|
|
|
|
|
BoundsChecker v7 is reporting the error 'Argument 2 in ReleaseDC (HDC__ hdc = 0xE00105F5) still contains non default/stock objects.' in the d'tor for CClientDC in the code:
void CHListBox::updateWidth(LPCTSTR s)
{
CClientDC dc(this);
CFont * f = CListBox::GetFont();
CFont* pOldFont = dc.SelectObject(f);
CSize sz = dc.GetTextExtent(s, _tcslen(s));
dc.SelectObject(pOldFont);
sz.cx += 3 * ::GetSystemMetrics(SM_CXBORDER);
if (sz.cx > width)
{
width = sz.cx;
CListBox::SetHorizontalExtent(width);
}
}
I'm fairly confident that there is no leak. Do you agree?
Gavin
|
|
|
|
|
CFont* GetFont( ) const;
Return Value
A pointer to a CFont that contains the current font.
The pointer may be temporary and should not be stored for later use.
so maybe
CFont * f = new CFont( CListBox::GetFont() ); ??????
|
|
|
|
|
Gavin Jerman wrote:
I'm fairly confident that there is no leak. Do you agree?
Yes.
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
I need to find out if the currently logged in user has administrator access to their PC. Does anyone know how I can do this please?
I'm writing a custom installation app, and need to make sure the logged in user has administrator access to the PC otherwise some of the files, especially MFC dlls won't copy properly.
Thanks
I feel like I'm diagonally parked in a parallel universe
Jeremy Davis
http://www.astad.org http://www.jvf.co.uk
|
|
|
|
|
I'm making a small program (in MFC) that needs to play several wave-sounds at the same time. I tried to use PlaySound(), but with that it seems you can just play one file at the time (the previous played file stops and the new begins to play, or the second waits till the first have finished).
How do I play several wave-files simultaneous?
|
|
|
|
|
Hi,
I encounterd the same problem, and found no solution.
I think it's the system which locks the "loudspeaker" resource.
Well, actually it's the soundcard device.
The only workaround would be to switch the playing of the sound faster than the user can hear the tones. But this will be heard by cracks, and also the sum of the wav file times will be the total playing time, not the time of the longest wav file.
By considering the difficulties and drawbacks of this method I choose not to follow this way.
Instead now I try to find a tool for mixing two wavefiles outside the application, and later on play this mixed wave file in my application.
G. Steudtel.
|
|
|
|
|
DirectX DirectSound will do this for you.
search google for some helper classes that encapsulate DirectSound and DirectSoundBuffer unless you want to do a lot of low level coding.
|
|
|
|
|
Hi
I have created a very simple ActiveX, but I would like to send parameters from a HTML page to the ActiveX. I have found some information mentioning that I need to implement an "IPropertyBag" but I am new to MFC, (this is my first project), and I dont know where to implement it neither how.
Could anyone help me?
Thanks
"Learn from the mistakes of others.
You can't live long enough to make them all yourself."
"Failure doesn't mean I'm a failure, It does mean I have not yet succeeded;
Failure doesn't mean that I should give up, It does mean that I should try harder;
Failure doesn't mean that I will never make it, It does mean that I need more practice".
Thank you for helping.
|
|
|
|
|
Hi!
I need to serialize some GDI+ stuff and for that it seems I need to use the
IStream COM interface.
For the rest of the serialization I use CFile. I tried this but it throws a
memory exception:
<br />
void CViewCoverPage::Serialize(CArchive& ar)<br />
{<br />
...<br />
<br />
COleStreamFile* pOleStream = (COleStreamFile*)ar.GetFile();<br />
IStream* pIStream = pOleStream->GetStream();<br />
m_pLogo->Save(pIStream,...);
...<br />
}<br />
It seems any operation I try with the IStream object results in an access
violation.
Do I need to initialize it in some way??
What am I missing here??
thanks /Anders
|
|
|
|
|
On the wild assumption that your document class is dervied from COleDocument try COleDocument::EnableCompoundFile(TRUE)
else create a memory stream file and stream m_pLogo into it
then archive the resulting bytes
ar << (DWORD) size of memory stream
ar << contents of memory stream
and reverse the sequence for the restore obviously
using dynamic_cast<colestreamfile*> ar.GetFile() would probably have shown this up etc etc
|
|
|
|
|
I've had some luck with the CArchiveStream class declared in the <afxpriv2.h> header (at least in VC6.0, 7.0 and 7.1; also in eVC 3.0).
This class is what MFC uses for feeding ActiveX controls on dialog boxes. I don't expect it to change, but it might.
Using it is quite simple:
<br />
CFile file( );<br />
CArchive ar( &file, );<br />
CArchiveStream arStm( &ar );<br />
<br />
IStream* pStm = &arStm;<br />
<br />
<br /> Obviously if you need the stream object to have a longer lifetime, you'll need to create all the objects (arStm, ar, file) on the heap instead.
Minor edits - decided to make IStream more obvious
--
Mike Dimmick
|
|
|
|
|
Hi guys! Thanks for your help!
All suggested approaches actually workes.
Trouble though is that Gdiplus::Image::FromStream(IStream* pIstrem)
reads the whole stream to the end. This would have been good if the
stream contained only the image but... Therefore I had to create a new
IStream for the Image::FromStream(.....)
So this is how it came out and thanks aganig for your help:
<br />
Image* SerializeImage(CArchive&, Image*)<br />
{<br />
DWORD sizeOfStream;<br />
CFileException* pMemFileError = NULL;<br />
LPBYTE pMemSpace = NULL;<br />
DWORD dwPos;<br />
<br />
CLSID jpgClsid;<br />
GetEncoderClsid(L"image/jpeg", &jpgClsid);<br />
<br />
COleStreamFile pMemFile;<br />
if(!pMemFile.CreateMemoryStream(pMemFileError))<br />
throw pMemFileError;<br />
<br />
ar.Flush();<br />
dwPos = ar.GetFile()->GetPosition();<br />
<br />
if(ar.IsStoring())<br />
{<br />
TRACE("Starts storing Image contents -- pos = %d\n", dwPos);<br />
<br />
pImage->Save(pMemFile.GetStream(),&jpgClsid);<br />
<br />
sizeOfStream = pMemFile.GetLength();<br />
<br />
pMemSpace = (LPBYTE)CoTaskMemAlloc(sizeOfStream);<br />
<br />
pMemFile.SeekToBegin();<br />
sizeOfStream = pMemFile.Read(pMemSpace,sizeOfStream);<br />
<br />
ar << sizeOfStream;<br />
ar.Write(pMemSpace, sizeOfStream); <br />
<br />
dwPos = ar.GetFile()->GetPosition();<br />
TRACE("Image storing complete -- pos = %d\n", dwPos);<br />
}<br />
else
{<br />
ar >> sizeOfStream;<br />
<br />
pMemSpace = (LPBYTE)CoTaskMemAlloc(sizeOfStream);<br />
<br />
ar.Read(pMemSpace, sizeOfStream);<br />
<br />
pMemFile.Write(pMemSpace, sizeOfStream);<br />
<br />
pImage = Image::FromStream(pMemFile.GetStream()); <br />
<br />
<br />
dwPos = ar.GetFile()->GetPosition();<br />
if(pImage->GetLastStatus() != Ok)<br />
{<br />
AfxMessageBox( "Misslyckades att läsa in logotype till försättsblad",<br />
MB_ICONEXCLAMATION);<br />
delete pImage;<br />
pImage = NULL;<br />
TRACE("Image loading failed!! -- pos = %d\n", dwPos);<br />
}<br />
else<br />
TRACE("Image loading complete -- pos = %d\n", dwPos);<br />
}<br />
<br />
CoTaskMemFree(pMemSpace);<br />
pMemFile.Close();<br />
return pImage;<br />
}<br />
/Anders Sandberg
|
|
|
|
|
When I parse an FTP Server folder using an FtpFileFind::FindNext() .
Then Delete All The Files in the above parsed folder.
Now if I again parse the same folder (FtpFileFind::FindNext()) It returns the name of the successfully deleted files . Though the files are not there on the folder.
I used FLAGS for Reloading And not to cache etc but no luck
Anybody Pleaase help
|
|
|
|
|
hi
Close the current search and start a new search. I think it will work.
mahesh
|
|
|
|
|
Got it..
I was working with a very old,slow,with less free space system...
so though delete command was success it takes some time to be actually deleted physically
greatest thing is to do wot others think you cant suhredayan@omniquad.com
|
|
|
|
|
This is to prevent namespace collision???
I've encounter problems when deriving from an object and I wish to add some functionality to non-virtual functions I usually have done this:
class myClass{
void MyMethod()
{
printf("Something more");
CBase::MyMethod("Something");
}
};
It's to my understanding this is a normal and acceptable practice???
I've started playing around with mysqlapi++ available at source forge (NOT mysql++ at mysql.com) and have seen the following code fragment and I must say it kinda confuses me.
mysqlcppapi::Connection con;
con.connect();
con.select_database("mysql_cpp_data");
mysqlcppapi::Query query = con.create_Query();
I've noticed mysql++ (www.mysql.com) uses STL extensively (which i'm not that familiar with and I assume mysqlapi++ does too) and I often see the preceeding code syntax when looking at STL code. At first glance, I thought...Connection() was a static member, but how would it create an object??? I was confused...then I thought about it a little...
maybe Connection was actually an class inside the namespace mysqlcppapi or something to that effect...
Anyways...i'm kinda puzzled about this all...so if you can tell me i'm right about my last thought or even fill me in a little...i would appreciate it...thanks
p.s-don't explain the code...i'm just lost on syntax
Cheers
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
I think you are not quite understanding why the namespaces are used first of all. They are not to prevent function level name clashes ( well that too ) but also class name clashes. STL has a class called vector and on the off chance you have your own class called vector it doesn't want to clash. a namespace is just a thin scope wrapper around functions and types declare with in. whe you use the mysqlcppai:: all you are doing is specifying directly the scope of the class you want to use. for example lets say you have this code.
class CMyConnection
{
:
};
namespace MYAPI
{
class CMyConnection
{
:
};
}
void somefunc()
{
CMyConnection conn;
MYAPI::CMyConnection conn;
}
It's really just a container for all this stuff. There is a way in all this though to not have to prefix the function or type with the namespace name IF you know there are no classes in the file you're using. For example the stl namespace is std:: and there is a class called vector. To use it without declaring std:: over and over again at the top of your file somehwere you could do a
using namespace std;
Then you wouldn't have to do std:: everywhere. You could just do something like:
int main()
{
vector v;
:
:
}
now if you have something to the effect of
#include <stl.h>
class vector
{
:
};
int main()
{
vector v;
:
}
There are two problems. One since the class vector is in the same file you would get a redefinition of type error but even if it was in a different file you would have an ambiguity because there would be two possible types for the same vector. Thats where you would need to use std::vector instead.
Hope this helped. Cheers!!
Joseph Dempsey
joseph_r_dempsey@yahoo.com
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."
--anonymous
|
|
|
|
|
The C++ symbol "::" is the scope-resolution operator. It tells the compiler to look for the item on the right of the operator inside the scope on the left.
There are two kinds of scopes in C++: classes and namespaces. Your first example uses scope resolution to call the base class's implementation of MyMethod(). When using scope-resolution in this way, it forces the compiler to statically choose the version of the function to call, rather than dynamically (which normally results in a recursive call with this idiom).
Namespaces allow related classes, functions and data to be given a related name. Instead of naming your classes:
mysqlcppapi_Connection
etc, you can name them
mysqlcppapi::Connection
So far, not much benefit. But you can use a shorter name with the using declaration:
using mysqlcppapi::Connection;<br />
<br />
Connection con;
If you decide to write using directives:
using namespace mysqlcppapi;<br />
using namespace myOtherNamespace;
and a Connection class is declared in both, you will have to revert to indicating which one you mean with the :: operator.
Namespaces have another advantage over using static class members; the declaration of a namespace can be re-opened, that is, you can add members to a namespace in multiple files.
--
Mike Dimmick
|
|
|
|