|
|
Thank you all for your replys. my program now changed as below:
#include <afx.h> // once include this afx.h, cannot include windows.h
#include <wininet.h>
#include <afxdisp.h>
#include <iostream>
CWinApp theApp;
int main()
{
if( FAILED(CoInitialize(NULL)) )
return -1;
IActiveDesktop* pIAD = 0;
... ...
CoUninitialize();
return 0;
}
it can be complied now, but there is another question, it that means the COM must require the MFC support in Win32.
|
|
|
|
|
Erik Funkenbusch wrote:
Use the MSDN Luke!
ROFL.
Michael
|
|
|
|
|
Hi !!!!
Please suggest me good resource on Internet from where I can learn the concept of I/O completion ports??? Please tell me any other method you know (excluding I/O completion port) which we can use to create a scalable server that can handle too many connections.
I am a winsock newbie. I started learning about Winsock API (without MFC ) few days ago. Initially I learnt about making servers that accept one connection at a time. In sencond step I learnt about creating the servers that can handle multiple connections with the help of Multithreading model. In this step, I came to know that creating one dedicated thread per client is a way to kill windows machine. I came to know that in order to create a good scalable server we should use I/O completion ports (Win2k)
So, in the third step i am planning to learn about I/O completion ports. I found 2 articles at CP, but i can't understand them properly. Please suggest me any other good resource on Internet where I can get good newbie information regarding I/O completion ports.
SamadAA
|
|
|
|
|
Unfortunately IO Completion ports are Microsoft best kept secret, very few articles and even less real world samples.
I can only suggest trawling thru the 'net looking for bits and pieces and then building the big picure yourself. There's a good book by Microsoft Press on Network Programming, that touches brief on IOCP.
Also depending on your application I/O Completion ports may not be the solution, there are many ways to implement a server depending on its workload and other factors. Learn the basics of Network programming then look at overlapped I/O, also you must be prepared to learn multithreading/synchronisation techniques.
Good luck on your quest.
Normski. - Professional Windows Programmer
|
|
|
|
|
You might find some stuff at sysinternals.
http://www.sysinternals.com/ntw2k/info/comport.shtml
|
|
|
|
|
Check out "Programming Applications for Microsoft Windows" by Jeffrey Richter or "Programming Server-Side Applications for Windows 2000" also by Jeffrey Richter and Jason Clark. These two books give great insight to IO Completions Ports.
|
|
|
|
|
*****************
//File: MyForm.h
public:
int number;
*******************
//File: Something.cpp
#include MyForm.h
void CSomething::OnBnClickedButton()
CMyForm myNew;
myNew.number = 3
AfxMessageBox(myNew.number);
*******************
When I run this and I click button1 I receive a
Debug Assertion Failed,
File: appui1.cpp
Line: 144
I press ignore and then my AfxMessageBox dispays empty.
*******************
I got this problem before when trying from a form1 to call the m_editBox.SetWindowText() function of a control on a form2, and someone suggested that the form2 was not yet created and to call the Create() function before.
I tought that with this simple int the things should be easier.
It wasn't so!
"Nelle cose del mondo non e' il sapere ma il volere che puo'."
|
|
|
|
|
If you want to display a number in a messagebox, you first have to convert the number to a string. See itoa() or sprintf() or CString::Format (to name a few). Your code now is trying to load a string with the ID of 3 from your string table, but it is unable to find a string with that ID, thus the error.
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Within you lies the power for good - Use it!
|
|
|
|
|
Yes, this works, i used a CString.
I tried this to solve this problem:
**********************************
//File MyForm.h
public:
CEdit m_editUserName;
**********************************
//File SomethingForm.cpp
#include MyForm.h
void CSomethingForm::OnBnClickedButton1()
{
CMyForm myNew;
myNew.m_editUserName.SetWindowText("ciao");
}
**********************************
Debug Assertion Failed!
file: winocc.cpp
line: 247
Someone suggested that the CMyForm is not yet created, and that I should call
Create() first.
My program features a Window menu for switch between the two Forms, and they are both active when I press the button.
I would like to press the button in the first form and change the windowtext of the edit in the second form.
"Nelle cose del mondo non e' il sapere ma il volere che puo'."
|
|
|
|
|
laphijia wrote:
My program features a Window menu for switch between the two Forms, and they are both active when I press the button.
If they are both active, why are you declaring a new instance of CMyForm in your OnBnClickedButton1() handler? You should instead get a pointer to the existing CMyForm.
You should learn how to use the debugger. When you get an assertion failure, you should be able to doubleclick on the message line in the output window, and visual studio will open the correct file at the line that caused the assertion. The line will read "ASSERT (SomethingOrOther)". Using that clue, you will be able to figure out which variable has an invalid value, and by using the call stack, you can trace backwards in the program until you get to your own code.
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Within you lies the power for good - Use it!
|
|
|
|
|
PJ Arends wrote:
If they are both active, why are you declaring a new instance of CMyForm in your OnBnClickedButton1() handler? You should instead get a pointer to the existing CMyForm.
You should learn how to use the debugger. When you get an assertion failure, you should be able to doubleclick on the message line in the output window, and visual studio will open the correct file at the line that caused the assertion. The line will read "ASSERT (SomethingOrOther)". Using that clue, you will be able to figure out which variable has an invalid value, and by using the call stack, you can trace backwards in the program until you get to your own code.
Thank you very much for helping me.
I changed the code to:
CMyForm* prova;
prova = new CMyForm;
prova->str = "ciao";
AfxMessageBox(prova->str);
delete prova;
This works!
CMyForm* prova;
prova = new CMyForm;
prova->m_edit.SetWindowText("ciao");
delete prova;
This still doesn't work.
I learnt what you said so:
void CWnd::SetWindowText(LPCTSTR lpszString)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
if (m_pCtrlSite == NULL)
::SetWindowText(m_hWnd, lpszString);
else
m_pCtrlSite->SetWindowText(lpszString);
}
WHAT THIS MEANS?
|
|
|
|
|
laphiji wrote:
CMyForm* prova;
prova = new CMyForm;
prova->m_edit.SetWindowText("ciao");
delete prova;
That won;t work. The edit control has not been created yet!!!
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
laphiji wrote:
void CWnd::SetWindowText(LPCTSTR lpszString)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
if (m_pCtrlSite == NULL)
::SetWindowText(m_hWnd, lpszString);
else
m_pCtrlSite->SetWindowText(lpszString);
}
WHAT THIS MEANS?
ASSERT(::IsWindow(m_hWnd) will cause a debug assertion if the window that you are trying to set the text for does not exist. You have declared the CWnd object, but you have yet to create the actual window at the system level.
Also :
laphiji wrote:
CMyForm* prova;
prova = new CMyForm;
prova->m_edit.SetWindowText("ciao");
delete prova;
Even if this did work, (which it won't for the above reason) the prova form would only briefly flash on the screen because it is created, then destroyed within your function call. it is not persistant beyond the beyond the length of time it takes the computer to process the message.
You need something like this:
{
CMyForm *prova;
prova = Get_The_Address_Of_The_Already_Existing_CMyForm_Object();
prova->m_edit.SetWindowText("ciao");
}
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Within you lies the power for good - Use it!
|
|
|
|
|
Hi,
i have some problem to use StrRetToBuf function. I use it like this :
StrRetToBuf(&strDispName, pidlItems, szParseName, MAX_PATH);
before using this function i included necessary header files :
#include <shlobj.h>
#include <shlwapi.h>
#pragma comment(lib,"shlwapi.lib.")
but i obtain the following error message :
error C2065: 'StrRetToBuf' : undeclared identifier
Can anybody help me
Thanks in advance
|
|
|
|
|
How to create top-level window transparent for mouse clicks? I.e. when user clicks the window, it doesn't ACTIVATES, it must seens like window not exist, but it must be visible... ?I tried to use WM_NCHITTEST and to return HTTRANSPARENT, then I tried to handle WM_MOUSEACTIVATE, but in vain.
Help!!
|
|
|
|
|
just write a hook and hook the mouse mesages as u like...
mm i am not sure but u try the follow
in the PreTranslateMessage()
check the message is mouse message and then u handle that message as u like..just trap themm ...
Renjith Pandalam
The TRUE CP -ian
|
|
|
|
|
Hi, pals!
I want to change variable type from CInternetFile* to FILE*.
I am using the following statments,
file2=(FILE*)file1;
Here, the type of file1 is CInternetFile*, and the type of
file2 is FILE*.
I want to know whether my method of type cast (from
CInternetFile* to FILE* ) is correct and safe?
My purpose is to convert from CInternetFile* to FILE*.
Best regards,
George Ma
|
|
|
|
|
Try this :-
Assume m_ifile is a CInternetFile*
FILE *fp = (FILE*) m_ifile->m_hFile;
I am not at all sure whether it will work! But try it anyway!
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
No, a CInternetFile* is not a FILE*. CInternetFile* is a pointer to a class called CInternetFile, while a FILE* is a structure (not a class) for the C Runtime Library. They are two entirely different things, and casting one to the other will do nothing but crash your program (if you're lucky).
There are only three cases where you can cast one pointer to another kind of pointer safely.
1) When the pointer you cast to is a base class of the first pointer.
2) When the class provides a conversion cast to the pointer type you want
3) When a structure (or class without virtual functions) has as it's first member the type you are casting to (this is used often for bitmap headers and such)
Of course this is a generalization, and there are ways around these rules, but if you don't know what you're doing they are good rules to follow.
--
Where are we going? And why am I in this handbasket?
|
|
|
|
|
Thanks, Erik!
Regards,
George
|
|
|
|
|
Hi.
I have a question about the use of LOGFONT with CFontDialog. I would like to have an option to change the font including size, weight, etc. I implemented a feature with CFontDialog support. I pass a pointer to a LOGFONT object when I instantiate the CFontDialog. Upon DoModal() == IDOK, I create a new LOGFONT object and assign it the value from CFontDialog. The program works sometimes. I am experiencing some weird reactions. First, the size of the font rarely comes out correctly. The size seems to be 10x *smaller* than the actual size of whatever the user selects from CFontDialog. Vice versa, when CFontDialog first starts up, I am able to pass it a LOGFONT of the current font. Again, it reads and interprets the font size incorrectly. For example, all default font size is 110 (11 points). However, when CFontDialog starts up, it interprets 110 as 83.
Here is a concise example.
-----
LOGFONT *mLFont = new LOGFONT;
memset(mLFont, 0, sizeof(LOGFONT);
mLFont->lfHeight = 110;
strcpy(mLFont->lfFaceName, "Microsoft Sans Serif");
CFont *myFont = new CFont;
myFont->CreatePointFontIndirect(mLFont);
// Everything is good up to this point.
CFontDialog myFDlg(mLFont);
if (myFDlg.DoModal() == IDOK)
{
// I am not sure if I need to create a new (clean) LOGFONT object
if (mLFont != NULL)
{
delete mLFont;
mLFont = NULL;
}
mLFont = new LOGFONT;
memset(mLFont, 0, sizeof(LOGFONT));
myFDlg.GetCurrentFont(mLFont);
}
-----
Okay. For some reason, the actual font that GetCurrentFont(...) passes back is 10x smaller than the actual size or the size that the user actually thought it want it to be
I am using CEditView. I use GetEditCtrl().SetFont() to set the font. I use GetEditCtrl().SetWindowText(...) to set the text.
I mentioned about deleting a LOGFONT object and allocating a new object each time I make a change to an LOGFONT object. Is that necessary?
Thanks,
Kuphryn
|
|
|
|
|
Try setting the height like this:
lfHeight = -MulDiv(11, GetDeviceCaps(hDC, LOGPIXELSY), 72);
This comes from the LOGFONT entry in MSDN.
Like it or not, I'm right.
|
|
|
|
|
Okay. The solution is to use CreateFontIndirect() instead of CreatePointFontIndirect(). I have no idea why that is.
Also, when I first instantiate a CFontDialog and pass in a reference of a LOGFONT object of the current font, for some reason CFontDialog does not recognize its height. It only recognizes the height after the user makes changes via CFontDialog.
Kuphryn
|
|
|
|
|
can anyone tell me the software name that i can create avi file please
i downloaded, videdit but i can't install it. it is keep asking missing sample.avi
so i search one avi file and change the name as sample.avi but another error message, " the same is not the same" pop up..
i want to create my own .avi file so i can use animation control of MFC.
thanks
|
|
|
|