|
Try this:
_Application app;
_NameSpace ns;
MAPIFolder folderOutbox;
_Items itemsMessages;
_MailItem mi;
long olFolderOutbox((long) 4);
COleVariant vtOptional((long) DISP_E_PARAMNOTFOUND, VT_ERROR),
vtTrue((short) TRUE);
if (app.CreateDispatch("Outlook.Application") == TRUE)
{
ns = app.GetNamespace("MAPI");
ns.Logon(vtOptional, vtOptional, vtTrue, vtTrue);
folderOutbox = ns.GetDefaultFolder(olFolderOutbox);
itemsMessages = folderOutbox.GetItems();
mi = itemsMessages.Add(vtOptional);
mi.SetTo("global_com2000@yahoo.com");
mi.SetSubject("Test...");
mi.SetBody("Hi Mapi\n\n");
mi.Send();
ns.Logoff();
}
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
the initialization below ,why to written like this?
CStudent(const char* szName, int nGrade) : m_strName(szName)
{
m_nGrade = nGrade;//m_strName,m_nGrade are both the membe of the class C
}
but i written like this:
CStudent(const char* szName, int nGrade)
{
m_strName=*szName;
m_nGrade = nGrade;
}
the program still run normally,why the original don't write as the same as mine,i want to when to write like the first style rather than the second style?
|
|
|
|
|
|
be careful on such code... you are copying a string, but in fact, just copying the address of that string. this can be so dangerous !
for example, if that string come from a variable (dynamically allowed), you execute such code (CStudent()), and then you destroy the first, you m_strName will point then a free area.
What you have to do is to copy the entiere string while constructing your object :
<font style="color:blue;">#include</font> <string.h> <font style="color:green;">
CStudent::CStudent(<font style="color:blue;">const char</font>* szName, <font style="color:blue;">int</font> nGrade) {
strcpy(m_strName, szName); <font style="color:green;">
m_nGrade = nGrade;
}
what happens when you do CStudent(const char* szName, int nGrade) : m_strName(szName) , it is that call a constructor that allocates a new object for fou, and then, copies m_strName with it. In this case, are you sure it really works ?
TOXCCT >>> GEII power
|
|
|
|
|
VERY WRONG m_strName = szName is not coping the address of the string, unless m_szName is a pointer. You can not copy use strcpy, unless the m_strName object already contains a string that is as long or longer than the string you are coping to it. He has various choices:
CStudent::CStudent(const char* szName, int nGrade) : m_strName(szName), m_nGrade(nGrade)
{}
CStudent::CStudent(const char* szName, int nGrade) : m_strName(szName)
{ m_nGrade = nGrade; }
CStudent::CStudent(const char* szName, int nGrade) : m_nGrade(nGrade)
{ strName = strName }
CStudent::CStudent(const char* szName, int nGrade)
{ m_strName = szName; m_nGrade = nGrade; }
But strcpy is not one of them. Of course your answer and mine have nothing to do with the actual question.
Sorry, but you scared me with your answer.
INTP
|
|
|
|
|
sorry but, szName and m_strName are char* , so they are pointers ! pointers contain addresses...
and when you use the operator=() on such type, it won't duplicate the string, but only what is inside the variables, here, the address of the C-string !
TOXCCT >>> GEII power
|
|
|
|
|
He did not give the definition of m_strName. Therefore we can conclude that it is a char*. If m_strName was a char* then you could not use m_strName(szName) in the initilization list, which is what the question was about. If he can use it in the initilization list then m_strName is not a char*.
INTP
|
|
|
|
|
ok, there we agree
well, thanks for him for your precision, that was parhaps not so clear to him.
TOXCCT >>> GEII power
|
|
|
|
|
i have a try in this way ,run well,the code is below:
class CStudent : public CObject
{
DECLARE_DYNAMIC(CStudent)
public:
CString m_strName;
int m_nGrade;
CStudent()
{
m_nGrade = 0;
}
CStudent(const char* szName, int nGrade) : m_strName(szName),m_nGrade(nGrade)
{ //strcpy(m_strName, *szName); //if this way ,it doesn't run well
//m_nGrade = nGrade;
}
CStudent(const CStudent& s) : m_strName(s.m_strName),m_nGrade(s.m_nGrade)
{
// copy constructor
//m_nGrade = s.m_nGrade;
}
i wonder m_strName,m_nGrade are only the member variable of the class CStudent,why in constructor to write : CStudent(const char* szName, int nGrade) : m_strName(szName),m_nGrade(nGrade)
?
whether this case still satisfy the other cases.
|
|
|
|
|
m_strName is a CString. You cannot 'strcpy' to a CString, this is a complete blind alley.
CStudent(const char* szName, int nGrade) : m_strName(szName)
{
}
calls the CString constructor that takes a const char * .
CStudent(const char* szName, int nGrade)
{
m_strName = szName ;
}
calls the default CString constructor to initialise an empty string, and then calls the operator= function to set the CString to the string pointed to by szName.
In other words the former is more efficient and explicit, the string gets directly initialised with its contents. Additionally you could declare m_strName as 'const', assuming it isn't allowed to change during the lifetime of the class instance.
Paul
|
|
|
|
|
What is the windows message that notifies every new application opened
Shenthil
|
|
|
|
|
I dont think there is any windows message for this purpose.
|
|
|
|
|
If a new window is created it is WM_CREATE. No idea about application.
|
|
|
|
|
How Can I use functions such as "ConnecntIpc,disconnectipc,netscheduljobadd"in Visual C++? Why Visual C++ regarded them as "undeclared identifier "?Thanks!
|
|
|
|
|
Hello,
I use Source Insight at work and enjoy the interface (large c/c++ tree for embedded systems built on a mounted unix box). I do some MFC work at home using the VC++ 6.0 interface and find that I long for the Source Insight style.
Is the new .net C++ code browser a great improvement over 6.0 and will it offer similar features to Source Insight?
Or, if you use Source Insight with VC++ 6.0, how can I make Source Insight call the MFC compiler locally (if there's a way).
Also, I'd like to implement some souce control for my home projects. Any recommendations?
thanks,
JennyP
|
|
|
|
|
Browser: SourceNavigator from RedHat. It is free and runs on Windows plus Linux. google for "Source Navigator".
Version Control: CVS is the "standard". Also free. Also runs on Windows or Linux. Used for version control on internet-developed programs. Simple to learn; plenty of docs available. LinCVS is a GUI version that I like. Runs on Windows too.
|
|
|
|
|
I tried to declare IHTMLDocument2 interface (IHTMLDocument2 *pDoc=NULL;) but the compiler says that IHTMLDocument2 is an undeclared identifier.
What header/project setting should i use be able to use this ?
|
|
|
|
|
I want to use MFC in a win32 prog what should I do?
|
|
|
|
|
Open the "Project Setting", and choose "Use MFC ....".
Maxwell Chen
|
|
|
|
|
When u say a Win32 application, its understood that its a C program and not C++ program.
Strictly speaking, MFC calls cannot be made from Wni32 program.
If still u wanna use, go to project setting and specify 'Use MFC'
Rahul
|
|
|
|
|
Rahul200676 wrote:
When u say a Win32 application, its understood that its a C program and not C++ program.
Win32 apps: 32-bit Windows applications. Can be written in C, C++, ASM, VB, Delphi, Java, etc.
Rahul200676 wrote:
Strictly speaking, MFC calls cannot be made from Wni32 program.
MFC is in C++, therefore C programs can not invoke MFC.
Rahul200676 wrote:
If still u wanna use, go to project setting and specify 'Use MFC'
Should reply to tank1025, not to me...
Maxwell Chen
|
|
|
|
|
I want to write a NULL DACL which will allow access to everyone,but I know the Security issue so little.who can give me some examples to study?(not use CServieModule)
appreciate any help!!
|
|
|
|
|
I want to write a MFC Activex .
I use a worker Thread.In this Thread i get data from socket and raise some Events,but some Events failed.
(
Unhandled exception in Project1.exe (MSVBVM60.DLL): 0xC0000005: Access Violation.
)
i find error occur in COleDispatchDriver::InvokeHelperV,but i don't why it occur.
Can you help me?
zhangfang
|
|
|
|
|
I'm using WebBrowser control in my app and I've read that you can get an access to the DOM of the page u're loading, or at least the document..
but in msdn there are no actual samples (source code about it). Let's say that I want to access the value of a input text in my page.
Is there a tutorial/samples bout this ??
|
|
|
|
|
Hey does anybody have code that does a recursive search for a certain folder name?
-Ryan M.
|
|
|
|