|
Ok, I flopped some code around and what you described does in fact work, but I'm looking for something else. Since a static function is shared by all instances of a class it defeats the purpose of what I'm trying to accomplish.
I need to be able to call a dynamic list of function pointers without a type requirement. So for the code I gave in my first post, I want to essentially register ("Add a Listener") to a specific objects attribute and when that attribute gets changed through an Set function notify everyone who registered with that attribute of its change.
Got any nuggets of wisdom to point me in the right direction?
|
|
|
|
|
0rigin wrote: I need to be able to call a dynamic list of function pointers without a type requirement
This is tough because C++ is a strongly typed language.
You can keep a vector of member function pointers but to call those functions through the
pointers you'll need an object of the class the function is a member of.
That means you'll also need to store objects to make the calls on (i.e. "registrants" also need
to register an object along with the function pointer).
If the objects are all the same class (or a class derived from a common class) then one function
pointer typedef could be used, like you're doing.
If the objects are all different class types then you'd need to have separate typedefs for all the
separate member function pointers.
I don't know if those are "nuggets of wisdom"
Mark
"I'm the Dude. So that's what you call me. You know, that or, uh, His Dudeness, or uh, Duder, or El Duderino if you're not into the whole brevity thing." The Big Lebowski
|
|
|
|
|
Sounds like the problem I had a little while ago... so I implemented a callback wrapper class with virtual functions to accomplish this. See the tutorial on functors in the function pointer tutorials.
|
|
|
|
|
Thanks for your help guys,
I'm already on my way to implementing functors.
Thanks,
0rigin
|
|
|
|
|
A word of caution: your classes must not go out of scope before accessing the callback stored by the functor related to the class, otherwise, you will get undefined behavior (most likely an access violation exception). This is why functors are best used with either singleton classes. You should not retain the functor past the scope of the class object that the functor uses.
Other than that, if you get stuck anywhere, feel free to ask.
|
|
|
|
|
Hi,
I've just written a tiny little console app- 8.0KB in release mode and knocked together a deployment project for it, standard MSI installer- release mode size 1.9MB! It's packaging the VC8 CRT, fair enough, but why so large? Any ideas anyone? It's not normally a problem but I need the installer to be as nimble as possible.
Thanks in advance,
dave
|
|
|
|
|
Build your app with static linking, it will grow by the parts of MFC and the CRT that you use, instead of requiring you to ship all of them.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi Christian,
Thanks for the info- just a quickie, does this mean just make sure msvcrt8.lib is set in the linker dependencies and ignore all default libraries is checked? or is there a compiler option that'll handle it for me?
thanks again,
dave
|
|
|
|
|
There's a setting in your project properties -
Configuration Properties/C++/Code Generation/Runtime Library
where you can choose one of the non-DLL versions of the CRT.
Mark
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
Hello,
I started to develop an application with MFC, using Document/views and OCX components, My application works fine but I just realized (and hope it not too late) that I need a same feature as reflection provided by .NET.
So my question is should I throw my application into the bean and develop a new one with C# or managed C++ or can I use my application by mixing MFC and managed C++ .
Or probably is there something else existing for unmanaged C++ that provides the same features as reflection.
Actually what I need to do is to dynamically access to the member functions and member variables of my application by their name.
For example I would like to type in the name of a function from an edit control to call that function.
You will probably suggest me to map the functions and data types but frankly I think it is not elegant. Of course this solution could be considered if nothing else is better.
Please what do you suggest me to do?
|
|
|
|
|
One option would be to COM-ize the classes/functions that need to be available to your application, and let them implement IDispatch. Then you have GetIdsOfNames and Invoke.
Hope this helps,
Daníel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Thanks for proposing this solution.
I am 100% newbee with COM, so where do you suggest me to start? a good book or just to search some articles in code project?
Does Invoke mean that I will be able to call the function on runtime by typing in its name and parameters from an edit control?
|
|
|
|
|
Arris7 wrote: Does Invoke mean that I will be able to call the function on runtime by typing in its name and parameters from an edit control?
Yes, if you already have a IDispatch pointer to an object which implements the functions you want to call, then you can first call GetIdsOfNames to get the DISPID of the function, then use Invoke to call a function with a given DISPID. This is how it is done the hard way (pure C++), but you could also use scripting mechanics which take care of all this. One article which talks about similar things is this one: http://www.codeproject.com/com/scripter.asp[^], you can surely find other similar.
Hope this helps,
Daníel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Hoe to convet a .mid file into .wav file using VC++/MFC? need functionality......
|
|
|
|
|
Hello,
I'm looking for an API function to get the CPU load (or a method to do this based on several API functions).
I recently bought a dual core processor and the minimized task manager isn't very helpful with providing quick information as to how each core is used. After digging a little on the net I decided I would be nice to write my own utility, but got stuck.
Any ideas how to do this? Any existing apps worth installing?
Many thanks,
Miron Brezuleanu
|
|
|
|
|
You need to use the performance counters. See PdhOpenQuery for how to get started with the Performance Data Helper APIs.
|
|
|
|
|
#include <iostream>
#include <string>
void println(const std::string& msg)
{ std::cout << msg << '\n'; }
class Base {
public:
Base() { println("Base::Base()"); virt(); }
virtual void virt() { println("Base::virt()"); }
};
class Derived : public Base {
public:
Derived() { println("Derived::Derived()"); virt(); }
virtual void virt() { println("Derived::virt()"); }
};
int main()
{
Derived d;
...
}
Why does the virtual virt function is called on the base class and not on derived class?
|
|
|
|
|
tom groezer wrote: Why does the virtual virt function is called on the base class and not on derived class?
Because in the base constructor, the object is only created to that point - there's still no
derived class constructed yet (Constructors are called in order from base to derived).
That's why you shouldn't make virtual calls from a constructor
Mark
"I'm the Dude. So that's what you call me. You know, that or, uh, His Dudeness, or uh, Duder, or El Duderino if you're not into the whole brevity thing." The Big Lebowski
|
|
|
|
|
Hi iam doing a project on localization. For that i want to develop a translator tool. Pls tell me the way to generate a dynamic resource file.
|
|
|
|
|
Maybe this link wll help: Creating a Resource-Only DLL[^]
"I'm the Dude. So that's what you call me. You know, that or, uh, His Dudeness, or uh, Duder, or El Duderino if you're not into the whole brevity thing." The Big Lebowski
|
|
|
|
|
Actually i want to generate rc file programatically. Can any one help me out?
|
|
|
|
|
hariharask wrote: Actually i want to generate rc file programatically
Oh, ok. Sorry about that!
In that case, you should know the .rc file format so you can read/write them.
Here's the info: About Resource Files[^]
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
I have 2-Views with property pages. If I am in View1, I can
get and save a number that I would like to transfer to a property
page in View2. I can save the number to the document and if I
print preview, the data appears in the correct property page in
View2.
Here is my problem. When I visit the property page in View2, the
data does not appear on the screen. I need to take (or load) the
data from the document. But OnSetActive nor OnInitDialog are not
called in the property page when it becomes active. When I am
in a property page in View2, how can I reload data from the document?
I tried a variety of different things. I just cant get it to work
unless I add a button that says "Get Number" and then when clicked,
it goes and retrieves that data. There has to be a way to automatically
transfer retrieve that data. Please, any response any one can give
me will be greatly appreciated.
Sincerely,
Danielle Brina (an overworked graduate student)
|
|
|
|
|
I'm wanting to make a chat program that uses IRC for my gaming clan. We use IRC to talk mostly. When in games I play some window mode so I can still chat in IRC.
Basically I want to make a program that will sit on top of any window so I can view IRC activity and respond (I can do that bit all later)
The problem I'm having is making the form sit on top of windows. For example Sitting on top of CSS as it uses Direct-X. Is there a way I can make it sit on top? I don't need to be able to type or click the window directly so CSS would always have mouse/keyboard control. I'd use a key combo like ctrl+keys to talk.
So yea true "on top" for forms over games etc? Code would be nice to help me, or just advice on what to research.
Thanks
|
|
|
|
|
mosimo wrote: Basically I want to make a program that will sit on top of any window so I can view IRC activity and respond
See -> SetWindowPos Function[^]
looks something like
SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
With respect, I must disagree. A quick look at middle management in just about any corporation shows that the dodo not only survived, it's reproducing in record numbers. Christopher Duncan
|
|
|
|