|
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
|
|
|
|
|
I use this code to send email with SMTP server but althuogh WSAGetLastError() return 0 always,there is no mail in the mailbox after these codes:
WSAStartup(0x0101,&wsa);
sendsocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
HOSTENT *hp1 = gethostbyname("mail.parsonline.net");
sendsin.sin_addr.s_addr=*((unsigned long*)hp1->h_addr);
sendsin.sin_family=AF_INET;
sendsin.sin_port=htons(25);
connect(sendsocket,(struct sockaddr*)&sendsin, sizeof(sendsin) );
char *buff = "HELLO server \r\n";
send(sendsocket,buff,strlen(buff),0);
char *buff1 = "MAIL FROM: <mazdakmansouri@mymail.net>\r\n";
send(sendsocket,buff1,strlen(buff1),0);
char *buff2 = "RCPT TO: <mazdakmansouri@mymail.net>\r\n";
send(sendsocket,buff2,strlen(buff2),0);
char *buff3 = "DATA \r\n";
send(sendsocket,buff3,strlen(buff3),0);
char *buff4 = "SUBJECT:LLLL\r\nBBBBBB.\r\n";
send(sendsocket,buff4,strlen(buff4),0);
send(sendsocket,"QUIT \r\n",strlen("QUIT \r\n"),0);
Any idea?
Mazy
No sig. available now.
|
|
|
|
|
It's not valid SMTP. You must always wait for a proper response (or error code) from server before sending commands or data to the server. The initial command must be "HELO", not "HELLO". The addresses are missing from "MAIL FROM" and "RCPT TO". The DATA isn't correctly terminated with a \r\n.\r\n .
|
|
|
|
|
Thanks.
Mazy
No sig. available now.
|
|
|
|
|
As markkuk says, it's not valid SMTP, and no server would ever save it.
You should take a closer look at http://faqs.org/rfcs/rfc2821.html[^]
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
thanks.
Mazy
No sig. available now.
|
|
|
|
|
I have a problem on using CopyFileEx().
I want to let Progress-Bar progress by using CopyFileEx() to show progress of copying files.
But Progress-Bar is not created.
On Debugging, CopyProgressRoutine() is not called.
There are no problem on compiling and copying files.
Please advise...
*******************************************************************************************
*******************************************************************************************
// Declaration of CopyProgressRoutine() in header file
static DWORD CALLBACK CopyProgressRoutine( LARGE_INTEGER TotalFileSize,
LARGE_INTEGER TotalBytesTransferred,
LARGE_INTEGER StreamSize,
LARGE_INTEGER StreamBytesTransferred,
DWORD dwStreamNumber,
DWORD dwCallbackReason,
HANDLE hSourceFile,
HANDLE hDestinationFile,
LPVOID lpData );
*******************************************************************************************
*******************************************************************************************
// The part of using CopyFileEx() in source file
for (i = 0; i < tmpwd; i++)
{
sTmp3.Format("DepFile%d", i+1);
sTmp = sAppPath + "\\" + pApp->GetProfileString(sSection, sTmp3);
sTmp2 = sPrnDrvDir + sTmp.Mid(sTmp.ReverseFind('\\'));
CopyFileEx(sTmp, sTmp2, CopyProgressRoutine, NULL, &b_cancel, COPY_FILE_RESTARTABLE);
}
*******************************************************************************************
*******************************************************************************************
// Definition of CopyProgressRoutine()
DWORD CALLBACK CSetupDlg::CopyProgressRoutine( LARGE_INTEGER TotalFileSize,
LARGE_INTEGER TotalBytesTransferred,
LARGE_INTEGER StreamSize,
LARGE_INTEGER StreamBytesTransferred,
DWORD dwStreamNumber,
DWORD dwCallbackReason,
HANDLE hSourceFile,
HANDLE hDestinationFile,
LPVOID lpData )
{
AfxMessageBox("Is it called?");// MessageBox for knowing of CopyProgressRoutine() being called
// But MessageBox is not output.
// So CopyProgressRoutine() was not called.
CSetupDlg *pDlg = (CSetupDlg*)lpData;
pDlg->m_InstProgress.SetPos( (StreamBytesTransferred.QuadPart / pDlg->TotalSize) * 100 );
// pDlg->TotalSize : Total sizes of all files that will be copied;
return PROGRESS_CONTINUE;
}
|
|
|
|
|
Have you tried it with "large" files. I don't think it bothers with the progress stuff for small quick to copy files.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
hello
when i compile i meet a strange mistake and i havn't idea when it cam come:
Compiling...<br />
creatfoufou.cpp<br />
c:\program files\microsoft visual studio\myprojects\essai\mfcopengl\opengl.h(22) : fatal error C1001: INTERNAL COMPILER ERROR<br />
(compiler file 'msc1.cpp', line 1786) <br />
Please choose the Technical Support command on the Visual C++ <br />
Help menu, or open the Technical Support help file for more information<br />
foufou.cpp<br />
c:\program files\microsoft visual studio\myprojects\essai\mfcopengl\opengl.h(22) : fatal error C1001: INTERNAL COMPILER ERROR<br />
(compiler file 'msc1.cpp', line 1786) <br />
Please choose the Technical Support command on the Visual C++ <br />
Help menu, or open the Technical Support help file for more information<br />
OpenGlView.cpp<br />
c:\program files\microsoft visual studio\myprojects\essai\mfcopengl\opengl.h(22) : fatal error C1001: INTERNAL COMPILER ERROR<br />
(compiler file 'msc1.cpp', line 1786) <br />
Please choose the Technical Support command on the Visual C++ <br />
Help menu, or open the Technical Support help file for more information<br />
Generating Code...<br />
Error executing cl.exe.<br />
Creating browse info file...<br />
BSCMAKE: error BK1506 : cannot open file '.\Debug\creatfoufou.sbr': No such file or directory<br />
Error executing bscmake.exe.<br />
<br />
OpenGl.exe - 4 error(s), 0 warning(s)<br />
|
|
|
|
|
Everytime or occasionally?
I have seen this on my VC++6 two years ago when I was compiling a very large project. It might be VC++6 too busy... Just rebuild. You don't have to call Microsoft.
BuggyMax
|
|
|
|
|
I don't know anything about Open GL. But there are occations where templates can produce internal compiler errors.
Probably you find some help through Google. You are not the first do encounter this...
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
I had this problem the other day. The debug build was OK, the release caused a Internal Compiler Error.
Try turning off all compiler optimizations and see if it build then. If it does, try enabling one at a time until you identify the one causing the problem.
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
We saw something similar a few months ago and for us the solution was to apply the latest Visual Studio service pack, 6 I think. Good luck.
|
|
|
|
|
I want to trigger a function every 30 minutes. I understand that this can be done by using timers. But a timer object needs DispatchMessage() function for TimerProc() to get called.
Is it possible to provide a message loop in a windowless DLL? If yes, where should the message loop be defined?
(I tried providing a message loop in the DLL but the DLL started showing strange behavior. Is it at all possible?)
Windows ce does not support Timer Queues or Waitable timers. Is there any other option?
Any suggestions would be highly appreciated.
Thanks,
Ruchika
|
|
|
|
|
Instead of using a TimerProc() you might consider using a thread. Look up CreateThread() (Windows CE 1.01 and later) in the MSDN Library.
Oooh! Do not forget to look at the totorials on threading.
Trust in the code Luke. Yea right!
|
|
|
|
|
You can do something like this:
Init fcn:
{
...
theApp.m_sAlertParamStruct.hThread = ::CreateThread(NULL,0,BackgroundAlertThread,(LPVOID)&theApp.m_sAlertParamStruct,0,&dwThreadID);
...
}
DWORD WINAPI BackgroundAlertThread(LPVOID pParams)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
BACKGROUNDPARAMSTRUCT *pParamStruct = (BACKGROUNDPARAMSTRUCT *)pParams;
char caBuf[21];
if (pParamStruct->pApplication->GetUserTagValue("AlertBackgroundThreadRunFrequency",caBuf))
iRunFrequency = atoi(caBuf);
// check not more frequent than every 30 seconds..
if (iRunFrequency < 30)
iRunFrequency = 30;
int iSeconds = 0;
while (!pParamStruct->bTerminateThread)
{
iSeconds++;
if (iSeconds >= iRunFrequency)
{
// do your thing here......
iSeconds = 0;
}
Sleep(1000);
}
if (!pParamStruct->bTerminateThread)
pParamStruct->hThread = NULL;
return 0;
}
|
|
|
|
|
Thank you so much for the suggestions.
I am leaning more towards not adding a background thread mainly becz I already have three threads in my module. So, I am thinking of modifying one of the threads that I have to wait for RETRANSMIT_TIME, do the job and again wait.
Ruchika
|
|
|
|
|
Exactly what I had in mind!
Trust in the code Luke. Yea right!
|
|
|
|
|
Hello,
I am working on a suite which needs to launch small file processing applications once a while. As my suite application spawns the small helper application, it losses the focus, and not regain it until the helper application complete and exit.
I wonder anyone knows how to launch an application (no UI) in background? I am using function ShellExecuteEx() right now.
Regards,
--jC
|
|
|
|
|
Search codeproject for ShellExecuteEx() and or CreateProcess(). There is an example around here some where, a similar example is out on the web [some where].
Also do the same search on the MSDN Library.
Sorry I could not be more helpful, but that is how I found imformation you are looking for last month.
Trust in the code Luke. Yea right!
|
|
|
|
|
Hello ,
Iam doing a MFC project.Iam displaying Animated GIFs with CDhtmlDialog class.This method works but the problem is that it works like a IE explorer.FOr example ,if i right click on the image a menu appears which is same as the IE right click menu .
Is there a way to get rid of this menu and similar such default IE message handlers??
|
|
|
|
|
I've never used VC++NET and I don't know if it is the same, but in a HTML Web page you can weite down this and the popup disappears...
<html><body oncontextmenu="return false"> ...
Hope this helps...
|
|
|
|
|
ACtually iam dispaling images here .ANyway i wil try ur suggestion .Thanks for it .
I solved it by getting the child window and disabling the user input to it !!!( Wnd->Enable Window(FALSE))
|
|
|
|