|
Well this is strange... Resource.rc is #included in the header. When I hover over it with the mouse, it even tells me the #define'd value. But now I see that I am also getting a "error C2065: 'ID_FILE_QUIT' : undeclared identifier". When I #include the resource.h file in this particular .cpp file, now it suddenly works. How is it that the compiler can look up it's value on a mouse-over, but somehow can't find it unless I #include it in the .cpp file as well?
|
|
|
|
|
Kevin Strickland wrote: How is it that the compiler can look up it's value on a mouse-over, but somehow can't find it unless I #include it in the .cpp file as well?
Subtle difference between the way info is gathered to build the intellisense database and the way the compiler parses through
the code.
I hate when that happens
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Subtle difference
That is not even close to subtle. LostYourSense is NOT A COMPILER, period.
Perhaps he can get a good trade on ebay ... compiler for filet-o-fish
|
|
|
|
|
led mike wrote: That is not even close to subtle.
I forgot the facetious tags
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I forgot the facetious tags
I don't think Visual Studio supports those.... yet
|
|
|
|
|
Kevin Strickland wrote: So why is the compiler giving me this error?
If we are to assume that the error is pertaining to the case ID_FILE_QUIT statement, then you need to verify that it is an integer constant. Otherwise, please note the line that is in error.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello MFC/Visual C++ experts,
I already read some articles and discussions about my problem in the
web:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=968335&SiteID=1
http://www.codeguru.com/forum/showthread.php?t=407572
http://forums.devx.com/archive/index.php/t-157559.html
I tried to incorporate an example I found in the web using a
CFrameWnd into my existing application, which, however, is an ATL
one (using _tWinMain to startup, instead of the approach via an
CWinApp object). I use the following to create the CFrameWnd:
m_pMainFrame = new CMainFrame;<br />
m_pMainFrame->LoadFrame(IDR_MAINFRAME,<br />
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,<br />
NULL);
He fails at the following assertion (line 23 in afxwin1.inl):
AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()<br />
{ ASSERT(afxCurrentResourceHandle != NULL);<br />
It seems that he doesn't find the menubar (IDR_MAINFRAME is the ID
of my menubar). What I did before to merge the example into my pro-
ject is to copy the resource file from the example, import it into the
resource view in Visual Studio, drag the resources into my existing
resources.rc, copied the new resource IDs into my resource.h, suc-
cessfully compiled and then executed, which gives the above assertion
failure.
What do I have to do that he correctly finds my menu bar? In the
resources.rc it already is. Does he need additional informations? Does
he use the string table for that? Do I have to do DoDataExchange()?
Do I have to invoke AfxEnableControlContainer() or AfxOleInit() or
other application initializing stuff before I can use the CFrameWnd?
I don't know what else to try, so if anyone could help me, I would be
very thankful.
Best regards,
Peter.
|
|
|
|
|
p_473 wrote: using a CFrameWnd into my existing application, which, however, is an ATL
one
I only had to read that far.
If you're going to use MFC classes then, except for a (very) few classes, you need to use an MFC application.
It is possible to get around this, but whether it's portable to future versions or not, I don't know.
Here's some of the issues:
1) Initialization. The MFC library needs to be initialized. The one-and-only CWinApp object is part of this.
You'll need that object even if you don't use its message pump. You'll also need to call AfxInitialize() and/or
AfxWinInit(). From the AfxWinInit() docs:
"If you call AfxWinInit yourself, you should declare an instance of a CWinApp class. For a console application,
you might choose not to derive your own class from CWinApp and instead use an instance of CWinApp directly.
This technique is appropriate if you decide to leave all functionality for your application in your implementation of main."
2) Window messages. If you're using a message loop outside of the MFC framework, then you need to pass all unhandled
messages to the MFC framework from your message loop. You can do this by passing them to your CWinApp object's
PreTranslateMessage() method.
Hope this helps a bit.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello Mark,
thank you for your very helpful answer. I read in some books and
also found the following:
http://support.microsoft.com/?scid=kb%3Ben-us%3B173974&x=14&y=9
So the last point for me to successful add MFC support to my ATL EXE
project is: Currently, my project uses a subclass of CAxDialogImpl<>
as the main window. It is instantiated in an object of class
CAtlExeModuleT<>, in function PreMessageLoop():
CMainDialog mainDlg;
mainDlg.DoModal();
Then, an instance of the CAtlExeModuleT<> is created and in
_tWinMain() its .WinMain() member function is invoked.
When I follow the above Microsoft-article, where it is proposed to
replace the _tWinMain function with InitInstance() and ExitInstance()
member functions of a global CWinApp object, in the InitInstance()
function a CWnd is created and CreateEx() invoked on it.
So here is my question: How to do that with my CMainDialog object?
CWnd and CAxDialogImpl aren't compatible, aren't they? I really would
like to not change the CMainDialog object since it contains many
COMMAND_HANDLER() functions and uses event sinks (COM stuff) to
realize its functionality.
Is there a way to keep it as the "main (dialog) window" of my appli-
cation? Would be great if you could help me here.
So thank you very much for your already precious help.
Best regards,
Peter.
|
|
|
|
|
I would try this before doing all that:
Note the current project's entry point setting (linker settings)
Set the project settings to use MFC DLL or static link
Make sure changing that setting didn't change the entry point setting - if so, set it back to the noted setting from step 1
Add a single global CWinApp object in the main module:
CMyWinApp theMFCApp;
Add these lines to your _tWinMain:
AfxInitialize();
AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0);
The last part I'm not sure of since I haven't used ATL windows. Wherever you have access to
the app's main message loop, add a call to your CWinApp object's PreTranslateMessage method, something like:
if (!theMFCApp.PreTranslateMessage(&msg))
{
... MFC didn't process the message - let ATL handle it...
... pass it on to the ATL message handler...
}
You should be able to create MFC windows.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello Mark,
thank you for your help. To make the problem clearer, I decided to
put the (fortunately short) code I started from in this mail (see
below and sorry that I didn't already do that before).
I already checked the first point of your advice and my project was
already "use MFC in a shared dll". The entry point settings I didn't
find. In Visual Studio 2005 (which I use) under
Project->Settings->Configuration Properties->Linker ... and then?
Could you tell me where I find the entry point settings?
I also added the global CWinApp object.
You wrote that you are not sure about the last point. - Did you mean
the second AfxWinInit... line or the following part concerning the
app's main message loop?
> Wherever you have access to
> the app's main message loop, add a call to your CWinApp object's
> PreTranslateMessage method
Could I put it in _tWinMain or would that be "too late", do I have to
put it before, e.g. directly after instantiating the global CWinApp
object? And finally:
> ... MFC didn't process the message - let ATL handle it...
> ... pass it on to the ATL message handler...
I tried to figure out how, but didn't find out. As I wrote in my
previous mail, the WinMain() member function of the CAtlExeModuleT<>
object is invoked, which only has the int nShowCmd as a parameter.
How do I get the "msg" object into it, if you meant that? - Is there
an appropriate member function which I have to invoke instead of
the WinMain() member function?
class CSampleModule : public CAtlExeModuleT< CSampleModule >
{
public :
HRESULT PreMessageLoop(int nShowCmd)
{
HRESULT hr = CAtlExeModuleT<CSampleModule>::PreMessageLoop(nShowCmd);
if (FAILED(hr))
return hr;
CMainDialog mainDlg;
mainDlg.DoModal();
return S_FALSE;
}
};
CSampleModule _AtlModule;
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE ,
LPTSTR , int nShowCmd)
{
return _AtlModule.WinMain(nShowCmd);
} I hope the problem I have is clearer now. I think it only must be a
single step to the solution of the problem, but I yet don't have the
knowledge to do this step. So I hope you could help me with your
advanced knowledge - you would relieve me from this great problem I
am stuck in.
So thanks again for your help you already provided and hopefully
could do until this hard nut is cracked.
Best regards,
Peter.
|
|
|
|
|
It looks like you don't need to change linker settings if you were already set up to use the
MFC DLL library.
The CWinApp object should be outside of _tWinMain() -
CWinApp MyMFCApp;
int APIENTRY _tWinMain(HINSTANCE instance,...
{
AfxInitialize();
AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0);
<font>return _AtlModule.WinMain(nShowCmd);
}
</font>
I haven't used ATL windows so I don't know where the message loop is. There should be somewhere you can
intercept messages and send them to MFC. The PreMessageLoop looks promising.
I'll take a look around and see if I can give you a more specific answer.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello Mark,
Thank you for your help, so the last problem to solve is how to
get one main event loop for the WinApp object and the _AtlModule?
Yes, you would really help me with taking your look around because
I think your possibilities (as a MVP) are greater than mine.
Nevertheless I of course will try my best to also figure out a
solution in parallel. I think if we could solve that problem we
could be rightly proud, since it seems not to be well-documented.
So I hope we will find the solution and look forward to your answer.
Best regards,
Peter.
|
|
|
|
|
You can override RunMessageLoop() in your CAtlExeModuleT derived class but since you're using a
modal dialog as a main window, it will never get called.
Something's going to have to change in the app's design to get this to work
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello Mark,
Thank you for your answer. Would it help to make the dialog non-modal?
Is it called automatically from _AtlModule.WinMain()?
And when I override RunMessageLoop(), what do I have to put in, then?
If I had to change the design of the app, what could I do to have
the minimal effort? - Pooh, so complicated, I hope we will finally
get it work.
At first, thank you again that you are helping me so bravely.
At next, I wish you a good weekend and if you want maybe write you
again on Monday.
Best regards,
Peter.
|
|
|
|
|
Hello Mark,
I hope you don't mind me posting my question also in other forums?
I think this is sensible trying to reach as many people as possible.
Maybe anyone has already solved the problem with the two ATL/MFC
event loops, so we could both learn from him/her.
But I think we are on a good way, we shouldn't give up since the
aim should be close. - Do you know who else we could ask? - Who could
know such things?
So once again many thanks for you help so far and please don't stop
answering me, your help is so precious for me.
I hope you will have a relaxing weekend (even from me and a
good start into the next week.
Best regards,
Peter.
|
|
|
|
|
Hello Mark,
I hope you aren't angry? - I'm a little desperated. Don't you have
the possibility to ask someone who knows about this main event loop
stuff in MFC and ATL? Who could know this? Until now, your answers
were the most helpful. Please don't stop answering me.
Best regards,
Peter.
|
|
|
|
|
Hi Peter,
Sorry about that, I let email notification of your post slip down my inbox.
Definitely post the problem anywhere you can It's always good to have a variety
of possible solutions to draw from.
Anyway, the issue was the message loop. I looked in the ATL code and
using a modal dialog main window won't work. ATL just passes it to a Windows modal
dialog API so there's no way to get the messages over to the MFC side.
I saw an interesting post (on another site) yesterday that seemed like an easy solution.
It's probably similar to the one in the Microsoft link you found.
Starting with an MFC app, override the Run() method in the CWinApp class.
In the override, don't call the base class Run() - Instead, override the ATL message loop
method and call that. In that override pass messages to the CWinApp PreTranslateMessage().
It's not much different than what we've been discussing, and it would still require your ATL
main window to be modeless.
MArk
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
thank you for your kind reply and sorry for my delayed answer, I have
to work on another project in parallel so I can not always answer
immediately. - To our issue:
Do you mean to set up a new MFC EXE project in Visual Studio?
Could you tell me the site you mentioned where you found the post?
When overriding the Run() method and not calling the base class' Run()
isn't there a danger some necessary initialisation isn't done?
So the only code in the overridden CWinApp.Run() is the call to the
ATL message loop method (what is its name)? And the only code in the
ATL message loop method is the call to CWinApp.PreTranslateMessage()?
Would you mind posting an example? Of course I will try for myself in
parallel, but in the case I get stuck I won't lose that much time.
Maybe it would save your time, too, before I may had to ask you more
questions. Sorry for that, but I don't have a good book where all
those processes like PreTranslateMessage() and Run() are described.
In the library there are only books which describe how to use the
Visual Studio Wizards but not those programming details.
Kind enough of you that you help me so much.
At first I wish you a nice weekend and hope we are just close to the
solution.
Best regards and till soon,
Peter.
|
|
|
|
|
Hi Mark,
I searched the web during the weekend and now understand the MFC
startup mechanism better (how the messaging in ATL works, however,
is still not clear to me). But when I include the MFC windowing stuff
via afxwin.h, the WinMain() function gets also included (after some
ways around: afxwin.h -> afx.h -> afxver_.h -> afxv_w32.h -> windows.h
->winbase.h). So this collides with the _tWinmain definition (_tWinMain
is equal to WinMain, as defined in tchar.h which is included via
afxv_32.h after windows.h). That is, when following the MFC architec-
ture I really should kick off the own _tWinMain definition?
The approach you mentioned sounds promising as it seems to correspond
to the approach in the Microsoft support link you re-mentioned.
So the place to multiplex the messages between the MFC and the ATL
objects in my application seems to be the PreTranslateMessage()
function. So I don't have to override PreTranslateMessage()? Wouldn't
it be sufficient to override PreTranslateMessage instead of the
procedure you proposed? Why do I have to first override CWinApp::Run()
which calls the ATL message loop (how should I do that?) which in
turn calls PreTranslateMessage()? Why this zig-zag-course? What should
I do in the ATL message loop? - Only the call to PreTranslateMessage?
Or is there more to be done? So the way becomes clearer now, although
not all details are clear to me already.
Would be great if you could answer and maybe drop a little example
code so I get the picture.
Best regards,
Peter.
|
|
|
|
|
I have search, read, and tried a lot of directions and finally got a sample that works. I'm posting it here hoping to receive feedback, i cannot oversee it all and this code is only running for a couple of hours now....
One explicit wish that i had is that i do not want to initialize MFC nor show a gui when the ATL Local COM server is only processing commandline arguments (like regserver/unregserver).
Code:
// TestStub.cpp : Implementation of WinMain
#include "stdafx.h"
#include "resource.h"
#include "TestStub.h"
#include "TestDlg.h"
//
// The MFC Module
//
class CTestStubApp : public CWinApp
{
public:
// Overrides
virtual BOOL InitInstance();
virtual int ExitInstance();
virtual int Run();
DECLARE_MESSAGE_MAP()
};
BOOL CTestStubApp::InitInstance()
{
CWinApp::InitInstance();
AfxEnableControlContainer();
//Create a modeless dialog
m_pMainWnd = new CTest();
dynamic_cast<ctest*>(m_pMainWnd)->Create(IDD_TEST, 0);
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
m_pMainWnd->SetFocus();
return TRUE;
}
int CTestStubApp::ExitInstance()
{
//Cleanup
delete m_pMainWnd;
m_pMainWnd = 0;
return CWinApp::ExitInstance();
}
int CTestStubApp::Run()
{
//Do not invoke MFC CWinApp::Run(), messages for MFC are handled through the ATL message handler (RunMessageLoop)
//CWinApp::Run()
return 0;
}
BEGIN_MESSAGE_MAP(CTestStubApp, CWinApp)
END_MESSAGE_MAP()
CTestStubApp theApp;
//
// The ATL Module
//
class CTestStubModule
: public CAtlExeModuleT<cteststubmodule>
{
public :
DECLARE_LIBID(LIBID_TestStubLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_TestSTUB, "{45383526-A2CD-4CA4-9170-AE3DBF5EFB8E}")
HRESULT PreMessageLoop(int nShowCmd) throw();
void RunMessageLoop() throw();
HRESULT PostMessageLoop() throw();
};
HRESULT CTestStubModule::PreMessageLoop(int nShowCmd) throw()
{
//Initialize the MFC module
theApp.InitInstance();
return CAtlExeModuleT<cteststubmodule>::PreMessageLoop(nShowCmd);
}
void CTestStubModule::RunMessageLoop() throw()
{
MSG msg;
while (GetMessage(&msg, 0, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
//Route msg to MFC
theApp.PreTranslateMessage(&msg);
}
}
HRESULT CTestStubModule::PostMessageLoop() throw()
{
//Deinitialize the MFC module
theApp.ExitInstance();
return CAtlExeModuleT<cteststubmodule>::PostMessageLoop();
}
CTestStubModule _AtlModule;
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd)
{
//Initialize the MFC library
AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
return _AtlModule.WinMain(nShowCmd);
}
Some keywords for searchengines on this topic:
ATL, local COM server, CAtlExeModuleT, AfxWinInit, RunMessageLoop, AfxGetResourceHandle assert
|
|
|
|
|
Hello
I need to use a ddk and used aall wizard of ddk
i just could include ntddk.h but
when include other file like video.h it give me
many error.
thanks
|
|
|
|
|
in my expereince you can't
you can use Visual Studio (any edition) as the IDE but when it comes to building you need to use the DDK builders for your target platform.
i've been doing alot with the DDK of late and i only use VS05 as my IDE (very limited IDE doesnt link to all ddk functions)
you may be able to include all the header/libaray files but you will first need to remove the SDK references as the DDK and SDK have some files of the same name but different uses (they both cant be used at the same time).
i havent done that however as it would be a pain to keep swopping between them.
|
|
|
|
|
Hi,
There is a project at the following url showing how to sort the images in terms of similarity with the selected reference image using CIBR method .
http://www.codeproject.com/bitmap/cbir.asp
But the input image in this case is .jpg image.
How can we modify this project so that it can work for .bmp images as input also.Is CIBR method equally applicable to .bmp images also.
Regards
|
|
|
|
|
Maynka wrote: How can we modify this project so that it can work for .bmp images as input also.
You learn and understand how the image classes used in the project work and figure it out.
Maynka wrote: Is CIBR method equally applicable to .bmp images also.
I don't know since I have no knowledge of CIBR method, but if it were my project I would use Google and learn and understand CIBR so I would "know" what the heck I was doing in my own freakin project. *sigh*
|
|
|
|
|