|
Have you looked in shlobj.h to see what other constraints might be keeping IActiveDesktop from being defined? You've indicated that _WIN32_WINNT has been defined, but was it defined before shlobj.h was included?
yingkou wrote:
the symbols of < and > can not be shown here
Sure they can. Have you not been seeing them in other's posts?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
#define _WIN32_WINNT 0x0500
#include afxwin.h // MFC core and standard components
#include wininet.h
#include shlobj.h // IActiveDesktop
|
|
|
|
|
Consider this code extract:
.
:
.
m_hLocal = ::LocalAlloc(LHND, sizeof(DLGTEMPLATE) + (sizeof(WORD) * 2) + sizeof(szDlgCaption));
if(!m_hLocal)
return FALSE;
pOut = pBuffer = (BYTE *)::LocalLock(m_hLocal);
if(!pBuffer)
{
::LocalFree(m_hLocal);
return FALSE;
}
memcpy((void*)pOut, (void*)&DlgTemplate, sizeof(DlgTemplate));
pOut += sizeof(DlgTemplate);
*(WORD*)pOut = 0;
*(WORD*)(pOut + 1) = 0;
pOut += (sizeof(WORD) << 1);
memcpy((void*)pOut, (void*)szDlgCaption, sizeof(szDlgCaption));
if((bRetVal = CreateIndirect((DLGTEMPLATE*)pBuffer)))
{
m_pPrompt = new CXDebugPrompt;
m_pConsole = new CXConsole(0x0000d200, 0x00000000);
ASSERT(m_pPrompt != NULL);
ASSERT(m_pConsole != NULL);
GetClientRect(&rect);
if(!m_pConsole->Create(IDD_DEBUG_CONSOLE, this, &rect))
bRetVal = FALSE;
if(!::LocalUnlock(m_hLocal))
XDEBUG_INFO("CXDebugConsole::Setup could not unlock Local Memory used in dialog creation\n");
else
.
:
.
In this extract you can see I am requesting Windows for Local memory allocation and locking (at the beginning). If it allocates and locks flawlessly, it then proceeds with what its meant to do, and, when the memory is finally no longer needed, it attempts to free it.
This is where it goes wrong!
Not only can I not Unlock the memory but also I can't Free it.
My question is, seeing I am creating a modeless-dialogbox, would it be possible, somehow, that CreateIndirect() (or a low-level Win32 API method) be already deallocating the memory for me? I am confused because CreateIndirect does not receive the memory handle held by m_hLocal , although it does receive a pointer to the dialog template...
Thank you so much!
David Nimrod
|
|
|
|
|
dNimrod#X wrote:
Not only can I not Unlock the memory but also I can't Free it.
This is because you are incrementing pOut (which is supposed to point to the memory block that was allocated) to some invalid address.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi, I've written a class that is used by an MFC app and a standard win32 dll.
The MFC app requires: #include "stdafx.h" //mfc precompiled headers
The standard win32 dll does not and it will cause problems if it is included.
Rather than have two copies of the class, i want to conditionaly include based on a #define
I have tried
#ifdef MFC
#include "stdafx.h"
#endif
but the compiler says: fatal error C1020: unexpected #endif
There must be a simple solution for this, please advise - thanks
Carl
|
|
|
|
|
Turn off precompiled headers in the project settings.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
That's not really the solution i am looking for.
Carl
|
|
|
|
|
Which implies that you already know of a solution and are just looking for confirmation. If your project has constraints, it helps to convey those so that you don't receive help that is of no value to you.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
DavidCrow wrote:
Which implies that you already know of a solution
Well not really, i think your somewhat tactless with your comments. What i am trying to achieve would mean someone with and existing MFC app that uses pre compiled headers AND someone that has no need for MFC could equally use my class by simply adding an MFC #define.
I don't know for sure that this is possible, but it does seem logical.
Carl
|
|
|
|
|
crandall wrote:
Well not really, i think your somewhat tactless with your comments.
Perhaps you misunderstood. A suggestion was given to you and you stated that "That's not really the solution i am looking for." That implies, at least to me, that you already know of a solution.
If you've been on the CP forums for any amount of time at all, you will have noticed a trend among posters where they provide as little information as possible about their problem, and the thread drags on for several dozen posts. If they had laid the problem out in as much detail as possible from the beginning, a lot of time/posts/questions could have been avoided. That is what was meant by my "If your project has constraints, it helps to convey those so that you don't receive help that is of no value to you." reply. I do not see how you can consider that "tactless."
crandall wrote:
...someone that has no need for MFC could equally use my class by simply adding an MFC #define.
If someone had no need for MFC, why would they add an MFC #define? That does not seem logical.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I have a class.
I want to use the class in a standard win32 dll and a project built with MFC.
If i don't include the stdafx.h in the class, the MFC project complains i can't see the precompiled headers.
I would prefer not to turn off precompiled headers in the MFC project.
I don't want to include them for applications that will usr the class that do not rely on MFC.
I am hoping to find a preprocessor command i can include in the class to minimize the class user changing anything.
thanks - Carl
|
|
|
|
|
thanks for that Christian, if it comes to it i'll have to resort to this but i'm trying to find a way to avoid it and primarily put the burden on the class itself.
Regards
Carl
|
|
|
|
|
try
#if defined MFC
#include "stdafx.h"
#endif
|
|
|
|
|
exactly the same error message
Carl
|
|
|
|
|
What is the problem that you're having with the standard DLL? I have MFC projects that link in outside DLLs without any problems. The MFC apps all use precompiled headers and include stdafx.h. Then later in the stdafx.h I include the appropriate header file for the standard DLL without any issues.
I don't think conditionally including stdafx.h is the answer. More likely you will want to keep this for all builds and fix the underlying problem elsewhere.
|
|
|
|
|
There is no problem with the standard dll.
I have a class.
I want to use the class in a standard win32 dll and a project built with MFC.
If i don't include the stdafx.h in the class, the MFC project complains i can't see the precompiled headers.
I would prefer not to turn off precompiled headers in the MFC project.
I don't want to include them for applications that will usr the class that do not rely on MFC.
I am hoping to find a preprocessor command i can include in the class to minimize the class user changing anything.
thanks - Carl
|
|
|
|
|
What environment are trying to use the class? First of all there is the class, its definition and the user of the class. These three may all reside in the same application/build and they might not.
There a few possibilities. Which are you using?
1. Class and user within same MFC project.
2. Class and user within same non-MFC project.
3. Class in MFC Extension DLL. Users must be an MFC project.
4. Class in MFC Regular DLL. Users can either be MFC or non-MFC.
5. Class in non-MFC regular DLL. Users can either be MFC or non-MFC.
|
|
|
|
|
Hi,
i have an application that creates controls on the fly on a dialog. Say a button and a combo box. I wan to handle the events in the pretranslate message of the parent(dialog in my case)so what i do is override the mydialog::PreTranslateMessage(MSG *pMsg) as below:
if(pMsg->message==WM_KEYDOWN)
{
if(pMsg->wParam==VK_RETURN)
{ pMsg->wParam=VK_TAB;
AfxMessageBox(_T("return was pressed"));
}
else
{
AfxMessageBox(_T("some key was pressed"));
}
}
else if(pMsg->message==WM_COMMAND)
{
if(HIWORD(pMsg->wParam) == BN_CLICKED)
{
CString Tmp = _T("Button Clicked was :");
Tmp.Format(_T("%s%d"),Tmp , LOWORD(wParam) ) ;
AfxMessageBox(Tmp);
}
else if (HIWORD(pMsg->wParam) == CBN_SELCHANGE)
{
CString Tmp = _T("Button Clicked was :");
Tmp.Format(_T("%s%d"),Tmp , LOWORD(wParam) ) ;
AfxMessageBox(Tmp);
}
}
return CDialog::PreTranslateMessage(pMsg);
}
Now if the child control - a button is clicked which is an object of CButton ( no subclassing done) should nt the dialog recieve a notification and therefore shouldnt the pretranslatemessage be invoked??
Thanks in advance,
|
|
|
|
|
Nope!
Child controls are also windows. So when you click a CButton control, the control will handle the message rather then passing it on to the parent window.
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
thanks for the answer.
But this is what i understand about the message handling mechanism of MFC.
When a control say a button is clicked it invokes its own wndproc which does what ever is required( say showing it in depressed state). Thiis because every control is actually a window.And then it sends anotification to the parent WM_COMMAND( in this case with msg as BN_CLICKED). Right? If this was the case then i Should be able to handle BN_CLICKED in parent.
Please correct me if i am wrong.
|
|
|
|
|
I think I got it, BN_CLICKED is a notification, not a command, and will be received into a WM_NOTIFY message.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
You can process the message in the parent window. The only thing you have to do is map a message handler to the desired action in your windows message map:
<br />
BEGIN_MESSAGE_MAPE(YourWindow, DerivedFrom)<br />
ON_BN_CLICKED(IDD_YOUR_BUTTON_ID, memberfxn)<br />
END_MESSAGE_MAP()<br />
Hope this helps
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
"You can process the message in the parent window. The only thing you have to do is map a message handler to the desired action in your windows message map:
BEGIN_MESSAGE_MAPE(YourWindow, DerivedFrom)
ON_BN_CLICKED(IDD_YOUR_BUTTON_ID, memberfxn)
END_MESSAGE_MAP() "
That is correct but my requirement is slightly different. I dont want to provide a static macro like the one above. Because my application reads what controls are to be rendered from datastructure. It reads from the datastructure that it need to create a button with xyz style , a textbox with some wdth and style etc.
Now i cannot use static statemenst as above. So what i wanted to do was intercept the default message handling mechanism. I wanted to override the pretranslate message for this and then from the MSG structure get what was the event fired and who fired it process it in pretranslatemessage and return.
|
|
|
|
|
Hello,
One way to go is subclassing the button control. This[^] article will tell you more about subclassing.
The other way to go is creating your own button control by deriving your custom button class from CButton.
From there you can make the button do what you want it to do. For exemple, you can send a user defined window message to your window that'll handle the button's actions.
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
I dont wanna go subclass way because i dont wanna subclass "n" classes. Since my ui may have n differnt controls.
|
|
|
|