|
Mark Salsbery wrote: Do you use AfxSetResourceHandle() somewhere?
Yup, the resources are loaded from a satellite DLL with LoadLibrary() and AfxSetResourceHandle(). The HINSTANCE for both (application or DLL) is not NULL.
|
|
|
|
|
I just found something. Looks like my code for registering the window class is like in Chris Maunder's article Creating Custom Controls[^] and someone mentions the same problem there.
Thanks for help
/M
|
|
|
|
|
Hei Moak,
Yes, you have made the correct fix. Now let me explain why. I will try to be very detailed so forgive me if I walk at too low of a level.
You see... at the very root it all has to do with Protected Mode[^] and how the operating system handles virtual addresses. When you load a resource, naturally the operating system needs to know where this resource is located in memory before you can use it. Normally if the resource is located in the executable you can simply pass AfxGetInstanceHandle() and at the lower levels the translation lookaside buffer[^] looks for the location for your processes virtual address. If there is a TLB-miss then it would have to access the page table to find this physical memory offset.
Essentially what I am saying is that AfxGetInstanceHandle() is nothing more than the module base address. These addresses are used for finding the resource.
You can see this by doing the following experiment:
#define MyGetInstanceHandle((HINSTANCE)&__ImageBase)
You can do something similar inside the DLL to see that all your actually passing is the module base address:
__inline HINSTANCE MyGetResourceHandle(LPCTSTR lpModuleName)
{
HINSTANCE h;
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, lpModuleName, &h);
return h;
}
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks for the detailed feedback!
/Moak
|
|
|
|
|
That's all cool info, but how does it affect the failed creation of the window using the OP's registered
window class?
Thanks,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Moak explained that he was creating a resource-only DLL[^] for his dialogs and other misc resources. How can you instantiate a dialog if you cannot locate the dialog resources. The WNDCLASS structure is populated with information from the resource section. Therefore his call to GetClassInfo() failed.
AfxGetInstanceHandle() will return the base address of MyApplication.EXE
AfxGetResourceHandle() will return the base address of MyModule.DLL
So when he used AfxGetInstanceHandle() the window creation failed because it was searching for the dialog resources in MyApplication.EXE when they were actually located in MyModule.DLL
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: Therefore his call to GetClassInfo() failed.
That's the part I was missing!
Thanks man!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It should be known that the explanation I gave was actually a simplified description of what actually happens under the MFC hood. I neglected to mention AfxSetResourceHandle() and afxCurrentResourceHandle. I also left out AFX_MANAGE_STATE(AfxGetStaticModuleState())[^] and duplicate resource ID issues all for the sake of brevity.
Best Wishes,
-David Delaune
|
|
|
|
|
Right. I got all that. I was just not wrapping my head around what was specifically causing failure in this
case, and why the change fixed it.
Thanks again,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Is there a simple code to print the Image to the printer ?
I already have 'screen capture' and save its to a .bmp file.
( http://84.244.8.225/winscreen.html ) .
Thx ,
Frederik Pot (Holland)
|
|
|
|
|
I found a sort of solution:
I get the pixels from the screen with GetPixel().
First : HDC im = GetDC(hwnd);
And the something like:
kleur = GetPixel(im, x, y);
rood = (int) GetRValue(kleur);
groen = (int) GetGValue(kleur);
blauw = (int) GetBValue(kleur);
SetPixel(hPrinter, x, y, RGB(rood, groen, blauw));
But it looks it delivers verry small images...
So any other tips will be welcome... Thx !
|
|
|
|
|
For a rectangular region of pixels, there's no need to copy a pixel at a time.
You can use something like StretchBlt() instead.
Most modern printers (and thus their DCs) have a much larger dots-per-inch (DPI) value
than screens, so you should use GetDeviceCaps() to get the HORZRES/VERTRES and/or
LOGPIXELSX/LOGPIXELSY values for the printer DC so you know what dimensions to
stretch the captured pixels to.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You can use of StretchBlt or BitBlt and you need to handle (hdc) of printer.
|
|
|
|
|
I've got an application that runs on several computers which handles simultaneous video capture (to be clear, each system runs it's own copy of the capture software). I've got another application that runs on another computer and is used to control capture software that is running on the other systems.
Currently, the capture software uses the winsock call "listen" to listen for incoming connections on a specific port. When I want to connect to the capture systems from the control system, I use the winsock call "connect" to make the connection. Currently, I cycle through a list of possible capture machines and attempt to connect to each one, however, the capture systems may or may not be running the capture software. Because connect doesn't allow me to specify a timeout, this connection process can take an extremely long time if even a single capture system is powered down or isn't running the software.
So my question is:
Is there a way to check to see if a system is listening for a connection before I call connect? Or, is there a better way to handle establishing connections between my machines.
Thanks,
Adam Kraver
|
|
|
|
|
Unfortunately you can't find out if a TCP port is open other than trying it. However there some design you could give a try:
- time out the connect call or use a socket library that can
- use a separate protocol to check availability, this could be the control system actively checking the hosts or the hosts sending an "hey I am alive" message in regular intervals
- use more than one client on the control system to compensate for delays
Hope it helps
/M
|
|
|
|
|
I would like to be able to reuse a project created in Visual Studio 6.0 in the latest Visual C++ 2008 Express package, but when compiling, I get this error message:
Compiling...
StdAfx.cpp
c:\myprojects\my projects\slammers\stdafx.h(16) : fatal error C1083: Cannot open include file: 'afxext.h': No such file or directory
Creating browse information file...
Microsoft Browse Information Maintenance Utility Version 9.00.21022
What is the proper way (if it exists) to reuse projects?
thank you.
|
|
|
|
|
Question 31:
Does Visual C++ 2008 Express Edition include MFC and ATL?
Answer:
No, MFC and ATL are not included with Visual C++ 2008 Express. MFC and ATL will be included in Visual Studio 2008 Standard and above editions.
http://www.microsoft.com/express/support/faq/[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Hello everyone,
Here is my precompiled header settings,
--------------------
Create/Use PCH Through File stdafx.h
PreCompiled Header File .\Debug/client.pch
--------------------
1.
It means all the content before stdafx.h will be precompiled into client.pch? So that each time compiler "assumes" the content before stfafx.h will not be changed. Right?
2.
How will compiler solve this situation?
#include "foo.h"
#include "stdafx.h"
#include "goo.h"
#include "stdafx.h"
Compiler will pre-compile foo.h, goo.h and stdafx.h into one client.pch file? Or pre-compile foo.h + stdafx.h into one file, and pre-compile goo.h and stdafx.h into another file?
thanks in advance,
George
|
|
|
|
|
The compiler will ignore the included file above stdafx.h...
You should get a warning as well, something like
warning C4627: '#include <foo.h>': skipped when looking for precompiled header use
To do something like that negates the usefulness of a precompiled header anyway....why would you do it?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark,
I am reading MSDN definition for the file name parameter from,
http://msdn2.microsoft.com/zh-cn/library/7zc28563(en-us).aspx
[^]
here is the meaning for the file parameter from MSDN,
--------------------
Specifies a header (.h) file. When this argument is used, the compiler
compiles all code up to and including the .h file.
--------------------
For exmaple, we have a file like this,
include "stdafx.h"
1. Does it mean when we compile the file, only stdafx.h and section 2 are compiled?
2. Or does it mean when compiler do the precompile, section 1 and stdafx.h will be pre-compiled into some .pch file?
regards,
George
|
|
|
|
|
Hi,
AFAIK, it is a rule that every cpp file in program should include "stdafx.h" and also it should be in the first line before including any other header.
Best Regards,
Suman
--
"Programming is an art that fights back!"
|
|
|
|
|
|
Hi,
I am not sure, I think as Mark said, whatever in the "section1" will be ignored and remaining will be compiled.
You can check it by using some mathmatics functions in your cpp file and include the "math.h" before "stdafx.x", you may get error.
Best Regards,
Suman
--
"Programming is an art that fights back!"
|
|
|
|
|
Thanks Suman,
For the pre-compile phase to generate pre-compiled headers (.pch), is only stdafx.h used to generate the client.pch or both section 1 and stdafx.h are used to generate the client.pch?
(you can check my original post for more details about context)
regards,
George
|
|
|
|
|
There's a third compiler option you need to work with here
/Yc Create precompiled header
/Yu Use precompiled header
If you look closely at the settings for a wizard-generated Visual C++ project,
ONE source file uses the /Yc option to create the precompiled header....this is typically
stdafx.cpp. All the other source files use the /Yu compiler option, to use the precompiled
header.
The "Create/Use PCH through file" option has two uses -
1) when used with /Yc, it specifies the file to stop precompilation on (at the end of)
2) when used with /Yu, it specifies the file to replace with the precompiled header
This has the following effects if "stdafx.h" is the "Create/Use PCH through file" setting:
1) For the file compiled with the /Yc option, everything included before and through the stdafx.h file
is compiled into a precompiled header file.
2) For any files compiled with the /Yu option, everything included before and through the stdafx.h file
is ignored and replaced with the precompiled header file.
Hopefully I explained that OK.
More info here: /Yu (Use Precompiled Header File)[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|