|
CFile::Open uses CreateFile internally, to create file on disk. This function fails in two scenario, first one is obviously failure of CreateFile API, second one is if there is problem with file path( too long ,etc.).
It uses _AfxFullPath2 for converting relative path to absolute path. Failure of this function may also be reason.
If you debug CFile::Open , these are three places from where, function is retuning FALSE .
I'm assuming, in your case, execution doesn't reach till CreateFile , as you are not getting useful information from exception object.
|
|
|
|
|
I have indeed looked at the source for CFile :: Open in the MFC (for VC98) but I do not get these 3 places where FALSE can be returned. Only 1 and after the CreateFile...
Thanks for your help but I still do not know where to look next.
|
|
|
|
|
Ooops ! I looked at VS2005. Seeing your post, I looked in to VC 6.
Did you mentioned earlier that, exception object doesn't tell you anything ?
|
|
|
|
|
It may be you are missing a share flag. An open mode and share flag (at least 1 of each) are
required.
try
if ( !filXML.Open(strFile, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary | CFile::shareDenyWrite, &e ) )
{
...
|
|
|
|
|
I have a question about typecasting incompatible types. I have two handles to objects, the handle class is a template class that functions as a smartpointer implementation.
Handle<A> ahandle(new B);
Handle<B> bhandle;
What I want is to cast from Handle<A> to Handle<B>. B derives from A and as such I can cast between them. The only problem is, I can't cast the handles directly.
I have come up with a solution involving some dirty hacking, but I am unsure if this is going to work and what it will do at runtime.
void* blankhandle = (void*)&ahandle;
Handle<B> bhandle = *(reinterpret_cast<Handle<B> >(blankhandle));
Hope anyone can shed some light on this.
WM.
What about weapons of mass-construction?
"You can always try to smash it with a wrench to fix that. It might actually work" - WillemM
|
|
|
|
|
WillemM wrote: B derives from A and as such I can cast between them
If this is truly the case then you should have no problem casting between them.
Therefore, you can use the safer dynamic_cast operator to perform the cast.
void* blankhandle = (void*)&ahandle;
Handle<B> *pBHandle = dynamic_cast<Handle<B>*>(blankhandle);
if (pBHandle)
{
Handle<B> bhandle = *pBHandle;
...
} Note I checked the return from dynamic_cast. If the object wasn't created as a B type handle
then it would fail as it should.
>
|
|
|
|
|
Cool, thanks for the information, then that trick should solve my problem quite nicely.
WM.
What about weapons of mass-construction?
"You can always try to smash it with a wrench to fix that. It might actually work" - WillemM
|
|
|
|
|
Cool maybe, except for the fact it won't work with a void pointer.
Instead of a void* you'd have to use a base class (handle A) pointer to use dynamic_cast.
If this doesnt work for your needs (you HAVE to use a void*) then use static_cast instead and
eliminate the check for NULL pointer since static_cast will perform the cast whether it's safe
or not.
Sorry about that!
Apparently I haven't had enough caffeine yet this morning
|
|
|
|
|
No problem, will keep that in mind. Somehow I get myself into a lot of trouble today, because this thing with the handles isn't the only problem in C++
WM.
What about weapons of mass-construction?
"You can always try to smash it with a wrench to fix that. It might actually work" - WillemM
|
|
|
|
|
WillemM wrote: this thing with the handles isn't the only problem in C++
For clarity, here's the updated code using a void *
void* blankhandle = (void*)&ahandle;
Handle<B> bhandle = *static_cast<Handle<B>*>(blankhandle);
...
|
|
|
|
|
Handle<A> and Handle<B> are distinct types: you can not safely cast between them. Any time you have to use reinterpret_cast or C-style casts (I never use C-style casts and would not allow any in code under my control) alarm bells should ring.
Say we have a template like this:
template <typename T>
class MyTemplate
{
};
Then MyTemplate<int> and MyTemplate<double> are distinct types and not related by inheritence. This is a basic property of C++ templates.
-- modified at 21:30 Thursday 7th December, 2006
Even if the representation happens to be the same an explicit specialisation added later could silently break this assumption. In short, don't be reckless with casting.
Can you elaborate on what you're trying to achieve? Perhaps there is a better type-safe mechanism to achieve it. For example consider the following:
template <typename T>
class MyTemplate
{
public:
MyTemplate(const T &data);
template <typename O>
MyTemplate(const MyTemplate<O> &other);
};
Steve
|
|
|
|
|
Hello friend,
I want to know about how programatically we can create backup/Recovery Utility for MS Exchange Server 2003. I want to do it in VC++.
Any help will be grately appreciated.
VJ
|
|
|
|
|
Hi all,
if you open windows explorer (i am using winXP), and you try to highlight (select) some items with the mouse, there is only one column that if the selection rectangle passes it begins to highlight.
i have a my inherite list control, but only the first column responds to this highlight...i need that the second column to respond and not the first...
can any1 help?
thanks in advanced
Yaron
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
let the list control object be m_myListCtrl
for full row select set the style as follows
m_myListCtrl.SetExStyle( m_myListCtrl.GetExStyle() | LVS_EX_FULLROWSELECT);
or
m_myListCtrl.SetExStyle( m_myListCtrl.GetExStyle() | LVS_FULLROWSELECT);
This will set full row selection.;P
Sunil
|
|
|
|
|
Hi all,
I am using pure c++ functions in visual studio 2005 to create a window which behaves similar to a dialog.
I have the handle to this window. Does anyone know how to load an image to this window? the image can be either a gif/bmp format???
Sunil
|
|
|
|
|
Do you want to show an image ?
|
|
|
|
|
ya display an image(gif/bmp format) on a window. I just have the HWND of this window. Is it possible?
Sunil
|
|
|
|
|
sunilpv1982 wrote:
ya display an image(gif/bmp format) on a window. I just have the HWND of this window. Is it possible?
look at IPicture interface
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
You can use of CImage class for load and show images(gif/bmp/jpg,...)
|
|
|
|
|
Hi,
I have developed a project containing ActiveX controls (ATL COM Servers)with drag and drop of these controls. Now I need Scrolling in this project. What is the most suitable way to add scrolling in an SDI project containing ATL COM servers. If anyone knows about any article about it then plz give the link of that article.
Waiting for your replies.
Best regards.
Cyber Friend
|
|
|
|
|
I have question.
well ,i have made a MDI application without documents view architecture. i am trying to create
the modeless dialog from menu file -> new.For that i have create dialog in childview class.but its gives assert failure error. even i have created it with child frame class even its not working .
yes its work with CMainframe but that i dont want.
what shoud i do ?
Thanks in advance.
amitmistry_petlad
software engineer
vadodara
india
|
|
|
|
|
This is because he childframe is not yet created.
Try implementing the same code in the mainframe class or the app class.
Sunil
|
|
|
|
|
There are many details to change to do what you need to do. I hope I understand what you are trying to do. I assume you want to use CFormView.
It is easier to create a new class that is derived from CFormView. Then use that class instead of the class that the wizard generates derived from CView. You can delete the old child view when you are sure you don't need it; you probably won't use it when you have made all the changes.
One place you might need to change is the call to LoadFrame, but I forget the details. I don't use MDI very much so these instructions might need to be modified for MDI; I am trying to do all this from memory so some of what I say might be the SDI way. One modification is that it helps to have a document, so you probably want to create a document class. Then allocate a new instance of the document for every child window. There is probably a LoadFrame or it's equivalent in the child frame window. Then put the address of the document in a CCreateContext and pass the instance of it to LoadFrame.
|
|
|
|
|
|
Hi all -
I am using Visual Studio .net 2003 for development on Win XP. My application picks up dll from PATH variable. But when I run the application (Double clicking the application in the Release or Debug folder), it is able to find the dll. But when I debug from the environment, it fails to find the dll from the PATH variable.
Any ideas?
Regards
Misha Grewal
Be the change you want to see.
|
|
|
|