|
You gotta put the hook procedure in a dll that can be loaded by Calc.exe's process. Then pass SetWindowsHookEx the HINSTANCE for that dll as loaded into your process. (as well as the pointer to the hook procedure)
|
|
|
|
|
Okay, thanks I'll try that then.
Cheers
Griffith
Everything you say will be misquoted, ripped out of context and used against you.
|
|
|
|
|
A return of 0 means it didn't work. NULL = 0. Check the docs. As previously mentioned, the actual procedure needs to be in a dll.
Joel Lucsy (jjlucsy@concentric.net)
|
|
|
|
|
My mistake, I meant to say that GetLastError() returned 0, just after I attempted to create the hook.
I thought I had to place the procedure in a DLL only for system-wide hooks, but it appears it's in order for all hooks outside of the calling process.
Griffith
Everything you say will be misquoted, ripped out of context and used against you.
|
|
|
|
|
I added a cpp /.h file pair which has definitions of listcontrol derived class. I am supposed to associate a variable of this type with the listctrl on my view form. i.e. I should have the choice of making the variable either of type Clistctrl or Myclistctrl. In the sample project I can do that....both classes show up in CW. I included the .h file of the derived class in my view class. IN my project when I select the listctrl ID_LIST1 in CW, and try to associate it with a m_list, I can only make it of type Clistctrl, and not myCListCtrl. How do I get around this?
Thanks,
ns
|
|
|
|
|
When I have that problem I delete the clw file and then I call the classwizard. It will ask you the file that you want to add to it....
Regards
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
That was great! I was thinking I'd have to mess with messagemaps etc...
Many thanks,
ns
|
|
|
|
|
I have a modeless dialog that comes up before the main window (OnCreate()). when the Main Window comes up, my dialog loses focus. I want to be able regain focus initially to let the user view the data in the dialog, then let them do whatever(shut it down, hide, etc.)
BW
{insert witty/thought-provoking saying here}
|
|
|
|
|
You could create your modeless dialog in a different place like, OnInitDialog() for dialog app or at the end of CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) in a SDI or MDI. How are you creating your Modeless dialog?
I create mine like this..
/Display the Refresh Dialog Box
if (!::IsWindow(m_dMyModelessDlg.GetSafeHwnd()))
{
m_dMyModelessDlg.Create(IDD_MY_MODELESS, this);
m_dMyModelessDlg.ShowWindow(SW_SHOW);
}
|
|
|
|
|
I am optimising an application that relies on a utility function (two square a number) in a different source code file. In the particular case, the utility function is getting called 400 million times (which takes a while).
So essentially I have:
file1.cpp
..
get_square(num)
..
file2.cpp
double get_square(double a)
{
return a * a;
}
When I compile and link this, get_square() is not made inline. I am using a header file to declare function in file2.c.
file2.h
extern inline double get_square(double a);
Now the code still does not get inlined. If I move the function definition into the header file, then it is inlined.
Is this the correct way to do this? Should the function body be in the head file as well? What if the compiler does not decide to inline the code, won't I get problem on linking?
I understand how to use inline in source code files and class definitions, but how should it be used when I want to call functions in a different source code file?
|
|
|
|
|
AFAIK either method should work under certain circumstances.
MSDN says:
The __forceinline keyword instructs the compiler to inline the function without performing any cost/benefit analysis.
If your using VC++ 6.0 you can specify whether inline should occur with:
Project->Settings->C/C++->Category->Optimizations->Inline function expansion
Check your build mode to make sure it's set to Any suitable for both debug and release.
I always use the C++ implicit inline method for trivial functions.
class myClass{
int myInline(){ return 100; }
};
I'm not 100% sure, but I think it's gaurenteed to inline when declared and defined as above and you avoid un-needed inline keywords. Also I tried this a while back and came to this conclusion...You cannot under any circumstance inline a ctor() in debug.
You asked:
"Now the code still does not get inlined. If I move the function definition into the header file, then it is inlined."
So why not do it this way...?
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hockey wrote:
I'm not 100% sure, but I think it's gaurenteed to inline when declared and defined as above and you avoid un-needed inline keywords
Actually inlining is never guaranteed unless you use __forceinline which is generally a bad idea. However, in practice VC++ always inlines trivial functions like Hockey illustrated. (I also agree with his suggest to set inlining to "Any Suitable", though I turn off inlining for debug since it can make debugging a real pain.
Incidentally, I'd implement your function as a MACRO.
|
|
|
|
|
can i ask why u have a function call for something so trivial?
just curious
"... and so i said to him ... if it don't dance (or code) and you can't eat it either f**k it or throw it away" biz stuff about me
|
|
|
|
|
Is this not the purpose of inline mutators and accessors...?
Besides it's like using a MACRO with type checking and ZERO penalties. Syntactic sugar I thought...?
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Because the other way to do this is:
double a = some_complicated_result();
answer = a * a;
The new code is easier i.e.
answer = get_square(some_complicated_result());
A #define can't be used, as this will evaluate the argument twice.
kris
|
|
|
|
|
For the compiler to inline a function it must (obviously) have access to the function definition. Move your get_square function into the header file.
Just for kicks you might also consider making it a template function, to work with any type you can multiply:
template <typename T>
T get_square(T v) { return v * v; }
|
|
|
|
|
I though about doing this, but was unsure of the run time implications.
Are all templates sorted out at compile time? or do the require some run time checking?
|
|
|
|
|
A template is just what its name implies, a template for the compiler to generate code from. As such, the code is generated at compile time and there is no runtime overhead.
|
|
|
|
|
I have a Dialog Applicatio with a CTreeCtrl in it . On a right click event I need to get the position of the mouse so that i can show another dialog at that location .
What method do I need to call ?
|
|
|
|
|
GetCursorPos() returns the position of the mouse, then use ScreenToClient() to translate it.
Roger Allen
Sonork 100.10016
I think I need a new quote, I am on the prowl, so look out for a soft cute furry looking animal, which is really a Hippo in disguise. Its probably me.
|
|
|
|
|
Thank you. that worked . I needed just the GetCursorpositon function .
I couldnt actually get the significance of the screentoClient method. Please can u explain ?
|
|
|
|
|
I am trying to set up an 2D array using COleSafeArray but I get an error ("INVALID INDEX) when I set the index to include negative values.
In short, I want an array with -10
|
|
|
|
|
You need to give index[1] some value, i.e., initialize the array. In the way you are using it the position 1 of the index has nothing in it. if you add something like
index[1] = 0;
before your for loop your code should work.
|
|
|
|
|
I derived a class from CButton, let's call it My_Button for the sake of discussion. Then I derived another class from My_Button, call it My_Button1. I thought I could create message handlers in My_Button that would handle common actions for all my button classes, but for some reason, My_Button (my base class) doesn't respond to the messages. Here's what happens... If I create a message handler (OnMouseMove) in the My_Button class, it won't capture mouse movement, but if I add that handler in the My_Button1 class, it does! Am I missing something? Shouldn't my new base class also handle it?
Thanks.
|
|
|
|
|
Check the BEGIN_MESSAGE_MAP macros in .cpp files. Probably Your_Button1 goes straight to CButton (not to Your_Button) when handling Windows messages - it has CButton as 2nd macro argument and should have Your_Button.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|