Win Api question and function pointer question

Started by
4 comments, last by thedustbustr 15 years, 9 months ago
When i call GetModuleHandle(NULL); to get HINSTANCE is it same during program life time? Is it possible to convert member function to global function pointer; foo = &myclass::foo;
http://www.daily-it.com
Advertisement
Quote:Original post by TiitHns
When i call GetModuleHandle(NULL); to get HINSTANCE is it same during program life time?

Yes

Quote:Original post by TiitHns
Is it possible to convert member function to global function pointer;

foo = &myclass::foo;

You can only create member-function-pointers on types and then use those on instances:
class MyClass{  public:    void foo(int x);};void (MyClass::*bar)(int) = &MyClass::foo;MyClass* a = new MyClass;(a->*bar)(2);delete a;

You cannot 'store' the instance in the pointer as well.
Million-to-one chances occur nine times out of ten!
struct foo{void do();};#include <boost/bind.hpp>#include <boost/function.hpp>foo myfoo;boost::function<void ()> functor = boost::bind(&foo::do, &myfoo);functor();
Another question about windows dll-s. if i include dll to my project and i need to use these functions once can i throw these functions away and free memory they use in program?
http://www.daily-it.com
If you use LoadLibrary to load the DLL, you can use FreeLibrary to say that you're done with lib and decrement the reference count. As long as you've only called LoadLibrary once, the DLL will be unloaded from your app's address space.
MJP is correct. but messing around with LoadLibrary can be tricky. Its certainly not going to "just work" like using a statically linked DLL does. You know how if you make a DLL and want to load it in another project, how you have to add MyDllName.lib to the linker inputs? If you want to load only when you need it and free it as soon as you're done, you have to effectively take care of all that linker magic by yourself. Not terribly fun.

This topic is closed to new replies.

Advertisement