|
A CP sample has:
BOOL CADOTestDlg::DestroyWindow()
{
if ( (m_pConn->State & adStateOpen) == adStateOpen)
m_pConn->Close();
CoUninitialize();
return CDialog::DestroyWindow();
}
If I wanted to close in case the conn was open, I would just do:
if ( (m_pConn->State == adStateOpen)
m_pConn->Close();
Why do we have the & there? I tried to look up State on the MSDN but it didnt point me to the Connection State. For that matter doing F1 on Connection didnt land me in any databasey link either.
So I assumed State is the property which holds a particular value like open or closed or whatever.
So why do we have (m_pConn->State & adStateOpen) == adStateOpen
Thanks,'
ns
|
|
|
|
|
ns wrote:
So why do we have (m_pConn->State & adStateOpen) == adStateOpen
testing for a bit mask
|
|
|
|
|
it's a bitwise-AND it takes the bits from the left side and the bits from the right side, lines them up and does an AND on each pair.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
I read about & and understand the math operation, but I'm trying to figure out in English what it accomplishes, if its possible.
Like if the right side is 010101, and the left side is 111111, then the result of & is 010101. This can also result from the left side being 01101 and many other such combinations. I just dont understand what it means. I dont even know if I should try....
Aaargh!
ns
|
|
|
|
|
it means that m_pConn->State can be in more than just the "open" state at any time.
imagine m_pConn->State = 010101 and adStateOpen = 000100. your test: m_pConn->State == adStateOpen will fail, because m_pConn->State is actually in two other states besides the "open" state. the "&" test knocks out all bits except the one representing the "open" state, before testing.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
Many thanks! Precisely the sort of answer I was needing - its clear now!
Appreciate your help,
ns
|
|
|
|
|
It's checking if a specific bit is set.
In the following example, uMask can hold up to 32 distinct flags (since it's a 32 bit quantity). To check if bit 2 (i.e. decimal value 4) is set, we do:
unsigned long uMask = ...;
unsigned long uTest = 0x04;
if (uMask & uTest) {
printf ("Bit 2 is set");
}
You wouldn't want to simply compare uMask with uTest using the == operator, because that simply tests if they are identical. So in your ADO example (btw I know nothing about ADO), you're checking if the connection happens to be open. If so, you're closing it.
You could write a function to do this check, thereby making the code more readable and maintainable. For example:
bool isAdoConnectionOpen
(CAdoConnection* pConn)
{
ASSERT (pConn != NULL);
return ((pConn->State & adStateOpen) == adStateOpen)
}
You'd use the function in this manner:
if (isAdoConnectionOpen (pConn)) {
pConn->Close();
}
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
In addition to what others have said:
This construct also checks for multiple bits (ie adStateOpen is a combination of bits)
11001111 - State
& 01000100 - adStateOpen
----------
01000100 - result == adStateopen
and
00001111 - State
& 01000100 - adStateOpen
----------
00000100 - result != adStateOpen but is not false either
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
I have to develop an application in Visual C++
that must connect itself to any type of LAN in order
to open a shared database.
This application must run on Win2K.
It can be not foreseen if the remote PC, where
the database is stored, manages a work group,
a domain or other rules.
I only know that the database is contained by a shared
folder.
What have I to foresee in my application ??
Which services or protocol have I to install in my PC ??
|
|
|
|
|
Hello all,
I've been reading the MSDN library stuff to try to figure out how GetActiveDocument works and I can't figure it out.
I have a string in my CDocument class called m_Filename.
I can access this variable in my View class with a GetDocument like this
CDisplayDIBDoc* pDoc = (CDisplayDIBDoc*)GetDocument();
if (pDoc)
{
(LPCTSTR)pDoc->m_Filename);
}
So I want to access this same variable in my CMDIChildWnd class that I made.
And I did this
CDisplayDIBDoc* pDoc = (CDisplayDIBDoc*)GetActiveDocument();
if (pDoc)
{
(LPCTSTR)pDoc->m_Filename);
}
Assuming it would work the same. I didn't override GetActiveDocument. Should I have?
I also rechanged that code with a !pDoc and a AfxMessageBox, and voila, the Message Box shows up, which means that I KNOW that pDoc is returning as a NULL.
How can I get to my m_Filename (a CString) variable in my Doc class from tmy CMDIChildWnd class?
Thanks a bunch
|
|
|
|
|
Here is the magic bullet I found works:
CTtDoc *pDoc=(CTtDoc *)((CMainFrame *)AfxGetApp()->m_pMainWnd)->GetActiveFrame()->GetActiveDocument();
It came from a discussion on these message boards just a few days ago.
In your case, you can then access, of course, by:
pDoc->m_Filename
Good luck!
JennyP
|
|
|
|
|
Ok so I tired it like this:
CMyDoc *pDoc = (CMyDoc *)((CMainFrame *)AfxGetApp()->m_pMainWnd)->GetActiveFrame()->GetActiveDocument();
if(pDoc)
{
pDoc->m_Filename;
}
And this doesn't work.
I put
if(pDOc == NULL)
{
AfxMessageBox("pDoc is NULL");
}
and this worked, so pDoc is still Null and not the String in m_Filename
So either the string in m_Filename gets erased somewhere and set back to NULL, or I am doing something still wrong.
Any ideas?
NickOne
|
|
|
|
|
Hello again,
Well I tried the code that I wrote above in a Dialog Window class that I added to the project.
In the Dialog window, it works correctly. Everytime, the m_Filename is accessed correctly.
BUT, in the CMDIChildWnd class that I added, it still shows up as a NULL. Why would this be??
i am really lost on this, and I really want to figure this out.
Thanks,
Nick
|
|
|
|
|
Dear memebers,
I'm searchnig for a source code of a "dwonload manager" program with pause/resume and multipart download capabilities.Please help me if know konw
any open source program in C/C++ or any document that could help me
thank you in advance
|
|
|
|
|
I have a .cpp file that compiles fine when used in a console app but gets errors when I include it in a MFC App.
d:\Visual C++.NET In 21 Days\Day 06 Dialogs\CMatrixTest.cpp(588): fatal error C1010: unexpected end of file while looking for precompiled header directive
I look up error 1010 and I get the increadibly useful result "The configuration registry key is invalid."
The file consists of a class definition that uses the standard template library. No main() or WinMain() function. I haven't included it yet in any other files.
Anyone have a clue as to what's going wrong because I sure don't.
|
|
|
|
|
Raskolnikov,
I've had problems with a similar message before. Go to the offending file and delete any and all characters at the end after your last statement. When I have done this, it usually clears it up.
Good luck!
Rich
|
|
|
|
|
I looked and every other file in a MFC app had this line so I added it and the program compiled.
<br />
#include "stdafx.h"<br />
I hate Microsoft.
What does "The configuration registry key is invalid." have to do with no including "stdafx.h"?
Can anyone know why I need to add this header file to all my .cpp files?
|
|
|
|
|
Raskolnikov wrote:
Can anyone know why I need to add this header file to all my .cpp files
THe simple answer: Precompiled headers
It makes a huge difference in compile times, however it is not hte most logical thing to use in the settings
You can turn it off for the whole project if you go to "Project Settings" and click the "C++ tab" and the "Precompiled Headers" category.
If you click on "Not using procompiled headers" it will get rid of this problem but considerably slow things down.
If you just want to shut it off for the file, then you can click on the file (still in the project settings dialog) and for the precompiled header settings just turn them off ONLY for the offending file.
If you are doing MFC stuff it is worth leaving them on
|
|
|
|
|
I don't mind the feature now that I know what it does, but the error message bites. "must #include stdafx.h when using precompiled headers" or any error message that mentioned either stdafx.h or precompiled header would be better than a cryptic message about an invalid registry configuration key.
Maybe the message makes sense to the implementers, but error messages should be written at the users level of abstraction!
|
|
|
|
|
The message was
fatal error C1010: unexpected end of file while looking for precompiled header directive
and it is not at ALL cryptic. Your precompiled header does not need to be called stdafx.h, and it's reasonable to consider that the user of a C++ compiler will either know what a precompiled header is, or be able to find out.
BTW you can also tell the compiler to automatically use precompiled headers with stdafx.h, and it will simply not use the precompiled headers where stdafx.h is not included. But it's usually better to include it everywhere, stdafx is a good central point to include libraries you want visible through the project, etc. For example, you'll find my stdafx is always going to include string, iostream, sstream, fstream, vector and algorithm with appropriate using statements as a minimum
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
|
|
|
|
|
The compiler error was fine, what I was upset about was the result I got when I tried to find further informaiton about the error using the error lookup tool, which I know now has nothing to do with compiler errors.
Anyway I have been using C++ compilers for years, mainly with compand line compilers like gcc but I have never heard of precomiled headers or precomiled header directives. The Visual C++ .NET book I am just read fails to mention them.
|
|
|
|
|
Hi,
Can anyone tell me how to make a Splash Screen using VC++ ?
I am used to the Visual Basic style :
frmSplash.show
do our initialization work
frmSplash.hide
With VC++, when I create a splash screen dialog box, then write:
CSplashDialog dialog;
dialog.DoModal();
Sleep(1000); /* or do my init stuff */
dialog.EndDialog();
It seems like the system gets stuck in the dialog.DoModal() function.
How to change the code ? Do I have to do my stuff inside my splash dialog ?
Thanks a lot
|
|
|
|
|
|
If you're using VC6, go to Project/Add to project/Components and controls/Visual C++ components. There's a Splash Screen component which is ready to use.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
All,
I was wondering if anyone has had issues with FtpGetFile. This behavior is rather odd; the file is there but cannot be downloaded. I have had my remote user check out the file security/privileges; they appear to be in order. I would like to be able to provide more information. However, since this is happening at a remote site, I do not have more information. Does anyone have any ideas?
Thanks in Advance,
Rich
|
|
|
|