PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

PocketHAL / MFC example?

clintsinger · 18 Nov 2004, 00:16 UTC
I have a full screen application (windowed on the desktop) that is required to be done in MFC. Does anyone have an example of how to override the default drawing capabilities of MFC and replace them with a PocketHAL implementation?

Cheers,
Clint
Why do you want to use MFC for a fullscreen app? That will only add overhead to your app.
Also, in MFC the message handling loop is hidden, practically forcing you to use a worker thread for the rendering (which has several issues on many devices if you don't know how to work around this issue).
Pejo Software - Per · 18 Nov 2004, 09:41 UTC
Johan wrote:Also, in MFC the message handling loop is hidden, practically forcing you to use a worker thread for the rendering.

I don't agree. In a MFC applicaion you can override the CWinThread::Run() or other methods used in the framework, you can even replace AfxWinMain if you want't to. This is not difficult and a good thing is that all MFC source code is available so you can just have a look at it and see how it works.
The major drawback of using MFC is that you loose some portability.
A quick answer to the original question: Search the web on how to use DirectX with MFC, the same techniques can probably be used here.
Johan wrote:Also, in MFC the message handling loop is hidden, practically forcing you to use a worker thread for the rendering (which has several issues on many devices if you don't know how to work around this issue).



Threads are a really bad idea in this case and only complicates matters. I agree with Pejo, there are better ways to handle this then using threads.
PeJo: Have you tried this? I know I did it once and ran into lots of issues trying to hook myself into the framework. I agree that multiple threads are to be avoided at all costs though.
Pejo Software - Per · 18 Nov 2004, 21:16 UTC
Johan wrote:PeJo: Have you tried this?

Yes.
At work we are making embedded software for a display node in a car. When doing this we also make sure that we develop almost all code so that it also can run on a PC, both with unit tests using cppunit and a emulator developed with MFC.
In order speed up the rendering in the emulator and unit tests (and make it easy to calculate a checksum off the current display content) I added DirectDraw rendering. In order to do this for the emulator I needed to override CWinThread::Run().
Ok, thanks.
Clint Singer · 25 Nov 2004, 01:15 UTC
The thing is I already have an application that runs on a custom windows ce platform. Many of my libraries are already in MFC and the utmost in performance isn't required. ie. I am not making a game. What I would like is the ability to get direct screen access and program against it directly.

So the question is, is it even possible to make pockethal work with MFC?

Cheers,
Clint
The next version of PocketHAL should work with MFC. Altough if you don't need performances, why don't you simply create a DIB and blit it to the screen?
Thierry wrote:The next version of PocketHAL should work with MFC. Altough if you don't need performances, why don't you simply create a DIB and blit it to the screen?


Great news Thierry! As for the DIB option, I would prefer PocketHAL because it seems like a great library. Also, if I can convince the company to use it then that means a donation :)

Cheers,
Clint
Great.

You can actually use the GDISurface right now. It's a wrapper around a DIB. You can then get it's DC and blit to the display.
clintsinger · 20 Feb 2005, 05:18 UTC — Linking problem
Hi Thierry,

I made an attempt to try PocketHAL with MFC and ran into a linking problem. It seems that PocketHAL has linked to a couple libraries that MFC is trying to link to as well and this is causing a conflict. The errors are as follows:

Linking...
libcmt.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCR71D.dll)
libcmt.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCR71D.dll)
libcmt.lib(crt0dat.obj) : error LNK2005: __cexit already defined in msvcrtd.lib(MSVCR71D.dll)
libcmt.lib(crt0dat.obj) : error LNK2005: __c_exit already defined in msvcrtd.lib(MSVCR71D.dll)
libcmt.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
libcmt.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
libcmt.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
libcmt.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
libcmt.lib(crt0.obj) : error LNK2005: __amsg_exit already defined in msvcrtd.lib(MSVCR71D.dll)
libcmt.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in msvcrtd.lib(MSVCR71D.dll)
libcmt.lib(crt0dat.obj) : warning LNK4006: _exit already defined in msvcrtd.lib(MSVCR71D.dll); second definition ignored
libcmt.lib(crt0dat.obj) : warning LNK4006: __exit already defined in msvcrtd.lib(MSVCR71D.dll); second definition ignored
libcmt.lib(crt0dat.obj) : warning LNK4006: __cexit already defined in msvcrtd.lib(MSVCR71D.dll); second definition ignored
libcmt.lib(crt0dat.obj) : warning LNK4006: __c_exit already defined in msvcrtd.lib(MSVCR71D.dll); second definition ignored
libcmt.lib(crt0init.obj) : warning LNK4006: ___xc_z already defined in msvcrtd.lib(cinitexe.obj); second definition ignored
libcmt.lib(crt0init.obj) : warning LNK4006: ___xc_a already defined in msvcrtd.lib(cinitexe.obj); second definition ignored
libcmt.lib(crt0init.obj) : warning LNK4006: ___xi_z already defined in msvcrtd.lib(cinitexe.obj); second definition ignored
libcmt.lib(crt0init.obj) : warning LNK4006: ___xi_a already defined in msvcrtd.lib(cinitexe.obj); second definition ignored
libcmt.lib(crt0.obj) : warning LNK4006: __amsg_exit already defined in msvcrtd.lib(MSVCR71D.dll); second definition ignored
libcmt.lib(winxfltr.obj) : warning LNK4006: __XcptFilter already defined in msvcrtd.lib(MSVCR71D.dll); second definition ignored
Creating library ../../../Bin/x86/Debug/MDUd.lib and object ../../../Bin/x86/Debug/MDUd.exp
LINK : warning LNK4098: defaultlib 'msvcrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
msvcrtd.lib(cinitexe.obj) : warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
libcmt.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
../../../Bin/x86/Debug/MDUd.exe : fatal error LNK1120: 1 unresolved externals

The application I am writing has the UI portion borrowed from the fireworks sample so that there is no requirement on MFC to do the drawing, event processing etc, but I still need MFC because the rest of the application uses it extensively.

Is there some way to get a pockethal library that compiles nicely with MFC?

Cheers,
Clint Singer
clintsinger · 20 Feb 2005, 05:27 UTC
Hi Thierry,

I thought I'd mention that I am using PocketHAL .8 Alpha 3 on Windows XP for the MFC test. If that helps at all. The goal is the ability to compile the same application for the desktop and windows ce.

Cheers,
Clint Singer
You are linking with different types of library files, single threaded and multi threaded.

In your linker options you should be able to specify a library to exclude from the link. Make this "libcmt.lib" (or if that causes problems try excluding "msvcrtd.lib" instead).
Hi Clint,
I got PF/PH v8.1 to link with MFC by commenting out the following line in PocketFrog.h:

#pragma comment( lib, "gdi32.lib" )

This caused the program to link correctly.

I am using this option for a Desktop application. Like so many other people, I am working on a game; so I am using MFC and PF/PH to create a game builder on the desktop. Everything works, accept that the PF display will not draw unless it has focus. I have traced this down to GetDisplay not returning a valid pointer unless the window has focus.

Thiery, is there a way for PH to return a valid pointer when running on the desktop but the PF/PH window does not have focus?

thanks.

clintsinger wrote:Hi Thierry,

I made an attempt to try PocketHAL with MFC and ran into a linking problem. It seems that PocketHAL has linked to a couple libraries that MFC is trying to link to as well and this is causing a conflict. The errors are as follows:

...