|
I'm not so sure why, but when I commented out the MessageBox in the main program, it did not crash. It installed and removed the hook successfully (to my knowledge). I have another problem though. With the hook installed, if I try to open another program, like Internet Explorer or some kind of software, Windows Crashes. It freezes and then all my icons dissappear and the taskbar goes away, leaving only the background and the cursor. Anyone have any idea why this would be happening? Any help is appreciated.
Thanks in advance
-Dev578
|
|
|
|
|
As an exercise, I am wrapping some of the lower level win32 structures and methods into a C++ object library.
I'd like to avoid forcing the user to do things like "register" classes. I think this is error prone to have the user make 'one' time calls, so I am trying to take advantage of C++ static properties. Currently, I declare an class (static) ATOM and initialize it with a function that is local to the cpp file.
My question revolves around the HINSTANCE member of the WNDCLASSEX struct. It clear that for win2k+, the hinstance parameter is ignored in the CreateWindowEx function - but what about for the population of WNDCLASSEX and subsequent RegisterClassEx calls?
It seems to work in my demo application (using WNDCLASSEX.hInstance = NULL that is). I have also had luck using the return value of GetModuleHandle.
Any suggestiong? I'd like to know whats going on under the hood. Will these methods work in simple cases and not more complex? I've even done this in a small DLL and seemed to have no problems using absolutely no HINSTANCE in the WNDCLASSEX ....
When one registers a class, is it registered systemwide? so that any HINSTANCE could instantiate it? The documentation says the WNDPROC must exist in the HINSTANCE. When I don't provide a hinstance, maybe it assumes the hinstance the call is being made from and so far, my WNDPROC always exists there?
This all comes back to the question, should I force the user to provide a HINSTANCE and consequently, Register classes explicitly.
Any direction would be appreciated.
Thanks in advance,
-Luther
|
|
|
|
|
Hi Luther,
I can only answer some of the questions you've put here. Hopefully someone else will jump in and answer the remainder.
Regarding HINSTANCE
I only know what's available in MSDN and the platform SDK, and these don't cover what goes on "under the hood" for functions like RegisterClassEx and CreateWindowEx. From experience, using NULL for the HINSTANCE doesn't seem to make much difference (but you already knew that). I don't know the consequence of using NULL for the HINSTANCE in these functions.
HINSTANCE can be important for other things though. One example is the TBADDBITMAP structure for a toolbar must get a real HINSTANCE value (not NULL) to create the toolbar.
The bottom line is that you will probably find you'll need the HINSTANCE of your application to do some things, but you'll get away with NULL for some others. Not a very adequate answer, but there you go.
Regarding RegisterClassEx
You need to call this in your application before it creates a normal window. The name registered for the window is not global, each application needs to register the windows before creating it. Using NULL as the HINSTANCE doesn't make it global or system wide.
Some predefined window types don't need to be registered. These include dialogs, edit controls, tool bars, status bars and so forth. All "general purpose" windows, however, need to be registered in the application that uses them.
By the way, you might find my article "Win32 Framework for SDI Applications" a handy reference. The URL is: http://www.codeproject.com/win32/Framework.asp
regards,
David
If it was easy, anyone could do it.
|
|
|
|
|
Many Thanks David.
I have a built a very similar framework - but with templates. Mainly to get as far away from virtual tables as possible. Sometimes subclassing, sometimes superclassing ... but templates add a nice twist.
I've come across one or two articles on Thunking (a lengthy one here on codeproject) but it didn't seem to work perfectly in .NET.
I'm not an ASSEMBLER, and I was probably doing something incorrectly, but setting the callback function to the thunk wasn't properly executing and the application would freeze. I'm not especially fond of the GetWindowLongPtr method, but at least it works. I'm concerned that an application with windows containing several children - each one using GetWindowLongPtr approach is not going to scale well.
Of course that's relative - but c windows apps will always have that speed advantage. It'll probabaly work out just fine ... just trying to explore for a clean, fast solution.
Hoping the lack of HINSTANCE in the WNDCLASSEX doesn't come back to bite me.
Thanks again,
-Luther
|
|
|
|
|
Luther Baker wrote:
Hoping the lack of HINSTANCE in the WNDCLASSEX doesn't come back to bite me.
Actually I was interested in your question about HINSTANCE, and was hoping someone else would come up with a definitive answer (hence my delay in answering your question). If you ever get to the bottom of the implications of using an HINSTANCE of NULL it might make for an interesting article on Code Project (for me anyway ).
I'm currently toying with using TLS (Thread Local Storage) as my thunk (as one of the comments to my article suggested). Seems to work well. Might be easier and more maintainable than assembly. Just a thought.
Best Regards,
David
|
|
|
|
|
Hello friend, somebody know how i can to repaint my dialog, because I open a dialog2 over dialog1 but when I close this dialog2, the dialog1 and his controls is cover with a gray shade, Why???. .
How I can to repaint the dialog???.
All my dialogs are open in form modal. The dialog1 is Child over the main Application, the dialog2 is a child opened over the dialog1 (popup)
I will be waiting your helps, .
The best Regards, .
HackPrince
NiponWare
|
|
|
|
|
Just a guess but this sounds like a WS_CLIPCHILDREN and/or WS_CLIPSIBLINGS problem
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
In Where such the messages?, It's in the Dialog1 or Dialog2???, because I make it with both, but I can't to resolve.
Please somebody know about it???
Regards
NiponWare
|
|
|
|
|
I call the dialog2 with dialog2.DoModal();
NiponWare
|
|
|
|
|
HackPrince wrote:
In Where such the messages?
They are styles, not messages. Look in your project's .rc file and see if the dialog templates (including the controls) use either of these styles.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I want the letter 'O' to be typed in the document of the wordpad application (sample of VC++6.0), when I type 'k'. Similarly I should be able to type one letter and get a sequence of letters (predefined string)typed in the current place of the document. How can I achieve this ?
Thanks in Advance.
Jai Srimannarayana
|
|
|
|
|
Sounds like you might need either a keystroke hook, or you need to process the WM_CHAR message.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks for your suggestion. I added onChar to the view and tried to access the nChar. But I couldn't use unshift alphabet in SendMessage whereas it works for Capital alphabet. How can I achieve it for small alphabet ?
Thanks
Jai Srimannarayana
|
|
|
|
|
kristna wrote:
But I couldn't use unshift alphabet in SendMessage...
What does the call to SendMessage() look like?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
It is not working for characters beyond 96. Any other way ?
void CWordPadView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
switch(nChar)
{
case 'b':
SendMessage(WM_CHAR,'e',0);
break;
...
Can I get some solution ?
Jai Srimannarayana
Jai Srimannarayana
|
|
|
|
|
Is it possible (legally?) to hook CoCreateInstance / CoGetClassObject class for the current process?
I'm trying to move global component registration to side-by-side-DLL's, and hooking these would make the process awfully efficient
Pandoras Gift #44: Hope. The one that keeps you on suffering. aber.. "Wie gesagt, der Scheiss is' Therapie" boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
You can redirect CoGetClassObject() on a per-CLSID basis by setting the TreatAs reg entry in the HKCR\CLSID\{guid} reg key; there are docs on this under "TreatAs" and "CoTreatAsClass" in MSDN.
--Mike--
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
I've hooked CoGetClassObject with success, but I also had to hook LoadTypeLibEx as well. The reason is because even tho it was LoadLibrary'd from the correct location, a previously registered activex control may trigger LoadTypeLibEx (not sure what does trigger it) to load the dll as a resource and use the IDL contained within. Caused me much grief for a bit as I knew the dll was loaded correctly, but the activex calls were calling the wrong stuff.
There are other "TypeLib" functions you may need to hook as well. I had a specific need and didn't research all the variations.
Hope this helps.
--
Joel Lucsy
|
|
|
|
|
Hi,
Has any one tried to compare two images using the cximage library. If you know how to do it or if you have any sample codes. Please help me with that. Thanks a lot.
Madhurya.
|
|
|
|
|
My method was to convert the images to grey scale and then check each pixel.
But I was more interested in seeing if there were any differences between two images not if they were equal.
But if the images are identical, then the files are also identical, just do a 'diff' on the files.
"An education isn't how much you have committed to memory, or even how much you know. It's being able to differentiate between what you do know and what you don't." - Anatole France
|
|
|
|
|
|
If you just need to know if they are exactly the same or not then you might try this:
if( img1.GetSize() == img2.GetSize() )
{
if( memcmp(img1.GetDib(),img2.GetDib(),img1.GetSize()) )
else
}
Or you could just use the GetPixelColor() function to read the individule pixels one at a time, and compare them by calling CompareColors(). That would allow you to know exactly what pixels are different.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Hi,
I've wrote MFC dll using MFC DLL wizard(regular dll using shared MFC dll).
in my dll there is the declaration:
#define TCPDLL_API __declspec(dllexport)
TCPDLL_API int FLRInitializeIP(IPStruct *Server,int num_of_radars);
in my dll.def there is the declaration:
FLRInitializeIP @1
and the implementation is as follow:
TCPDLL_API int FLRInitializeIP(IPStruct *Server , int num_of_radars)
{
struct hostent *Host;
SIZE_T t=100;
char *host_name = new char[100];
gethostname(host_name,t);
Host = gethostbyname(host_name);
Server->HostIP = inet_ntoa(*((struct in_addr*)Host->h_addr));
delete []host_name;
Server->Num_Of_Connected_Clients = 0;
Server->ListeningSocket = INVALID_SOCKET;
Server->Num_Of_Radars = num_of_radars;
if(CreateTCPServerSocket(Server) != LISTEN_SUCCESS)
return 0;
return 1;
}
now,in my application i'm using the dll like this:
typedef int (CALLBACK* FLRInitializeIP_PROCCESS)(IPStruct* ,int);
void CDLLTestDlg::OnListenButton()
{
HINSTANCE hLib;
FLRInitializeIP_PROCCESS FLRInitializeIP;
IPStruct Server;
int result;
hLib = LoadLibrary("TCP_DLL.dll");
FLRInitializeIP = (FLRInitializeIP_PROCCESS)GetProcAddress(hLib,"FLRInitializeIP");
result = FLRInitializeIP(&Server , 1);
m_List.AddString(Server.HostIP);
FreeLibrary(hLib);
}
if,in my application 'the return type is "void" so there is no problem.
But,if the ruturn value is anything else than void,i gets an error.
what i'm doing wrong?
Helpppppppppppppppppppp
Regards,
Eli
|
|
|
|
|
I would first like to mention that your specific problem has nothing to do with the MFC DLL. You have the same problem if it was a regualr' NOn-MFC' DLL.
You need to make the function signatures match the pascal calling convention.
I usually give all regular 'C' functions exported from a DLL the pascal calling convention, unless otherwise required. One exception, for example, is if the function has a variable number of arguments.
Especially since you declared that the function has this signature:
typedef int (CALLBACK* FLRInitializeIP_PROCCESS)(IPStruct* ,int);
And in WTYPES.H there is this definition:
#define CALLBACK FAR PASCAL
You need to define the function ion the DLL with the same signature, like this:
#define TCPDLL_API __declspec(dllexport)
TCPDLL_API int WINAPI FLRInitializeIP(IPStruct *Server,int num_of_radars);
TCPDLL_API int WINAPI FLRInitializeIP(IPStruct *Server , int num_of_radars){
|
|
|
|
|
Hi,
First - thanks for your prompt reply.
well,i'v tried your suggestion,but it's still give me run time error(something about convntion - as you said).
Here is what i did:
Instead of :
TCPDLL_API int FLRInitializeIP(IPStruct *Server,int num_of_radars);
I've wrote :
TCPDLL_API int WINAPI FLRInitializeIP(IPStruct *Server,int num_of_radars);
and instead of :
TCPDLL_API int FLRInitializeIP(IPStruct *Server ,int num_of_radars)
{
struct hostent *Host;
SIZE_T t=100;
char *host_name = new char[100];
gethostname(host_name,t);
Host = gethostbyname(host_name);
Server->HostIP = inet_ntoa(*((struct in_addr*)Host->h_addr));
delete []host_name;
Server->Num_Of_Connected_Clients = 0;
Server->ListeningSocket = INVALID_SOCKET;
Server->Num_Of_Radars = num_of_radars;
if(CreateTCPServerSocket(Server) != LISTEN_SUCCESS)
return 0;
return 1;
}
I've wrote :
TCPDLL_API int WINAPI FLRInitializeIP(IPStruct *Server ,int num_of_radars)
{
struct hostent *Host;
SIZE_T t=100;
char *host_name = new char[100];
gethostname(host_name,t);
Host = gethostbyname(host_name);
Server->HostIP = inet_ntoa(*((struct in_addr*)Host->h_addr));
delete []host_name;
Server->Num_Of_Connected_Clients = 0;
Server->ListeningSocket = INVALID_SOCKET;
Server->Num_Of_Radars = num_of_radars;
if(CreateTCPServerSocket(Server) != LISTEN_SUCCESS)
return 0;
return 1;
}
Now,when I'm debugging my code - the function works well and the run time
error accurs after the :
return 0;
or
return 1;
So,where is the problem???
Again - thanks for your help.
With best regards,
Eli
|
|
|
|
|