Accessing class methods from a .DLL
BlitzMax Forums/BlitzMax Programming/Accessing class methods from a .DLL
| ||
How can BlitzMax access the methods of classes and the class hierarchy that are part of an API in a .DLL file? For example, suppose a DLL contains numerous classes that each have their own 'Create()' method. How can BlitzMax call the Create() method for a particular class in that DLL? I know that through the win32 module found in the win32.mod folder, we have access to the LoadLibraryA routine to load a DLL library and receive a reference to it, and then can use GetProcAddress to set up a function pointer to the routine we want to call in the DLL: Import pub.win32 Global libptr=LoadLibraryA( "DLL_Library_Name" ) Global Function_Name(parameter:Type)=GetProcAddress(libptr,"DLL_Function_Name") ' now can use the function in BMax Function_Name(some_parameter) But how do we access a specific function (method) of a class that is in a DLL file? I see the pub folder has entries for the following WinAPI functions: RegisterClassA RegisterClassW GetModuleHandleA GetModuleHandleW Where "A" stands for ANSI characters, "W" for Unicode characters. Has anybody successfully used these functions (or perhaps other ones) to call various methods of classes buried inside a DLL? |
| ||
to be honest I just wrap each method in a function call and pass a pointer to the class instance to the function If you are straight including c++ code theres a method for methods(!) in the help docs Global _fastforwardParticle(ps:Byte Ptr,secs:Float,interval:Float)=getprocaddress(sow,"sow_fastforwardParticle") c++ void sow_fastforwardParticle(Ogre::ParticleSystem *ps,float time,float interval){ ps->fastForward(time,interval); } |
| ||
If you want to use class functions, you need to extern the whole class and the functions must be declared as virtual within the C++ source. See advanced topics in help. |
| ||
thats not going to help you if the class is in a dll is it? |
| ||
The idea is not to have to extern anything, just access the class using the WinAPI from BMax. |
| ||
well do let us know if you manage a better solution than the one I currently use for dll's, I'd love to know it! |