Sign in to follow this  
TiitHns

Win Api question and function pointer question

Recommended Posts

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;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this