-
Jul 31st, 2016, 08:18 PM
#1
Thread Starter
Frenzied Member
Module for directly using FFTW in VB6
As you probably remember, I created a DLL file, using ASM code (which you can find here http://www.vbforums.com/showthread.p...libfftw3-3-dll), that had STDCALL functions, that called the CDECL functions in the FFTW DLL file. However, that requires distributing one more dependency with programs that use FFTW. I found a way, using Windows API calls in a standard VB6 module, to directly call all the CDECL functions from within VB6. The file is called FFTW3.bas (as it is designed to work with version 3 of FFTW, which is the latest version). Below is a link to the code for that module on PasteBin (sorry, it's too many characters to paste on VBForums, as it goes over the 15000 character limit).
http://pastebin.com/cnJw8mB1
The first thing you want to do when your program starts is call InitFFTW.
The way that InitFFTW works is, it first uses LoadLibrary to load libfftw3-3.dll into memory, and get a handle to it. It then uses a series of calls to the GetProcAddress function, to get the addresses of all the functions that are most important in FFTW (there's a few that the DLL file has that are much more advanced, but 99% of the time you won't be needing them, so they aren't included in this module).
When your program closes, the last action your program takes should be to call CloseFFTW. This empties the collection that has stored the addresses for all the functions, and then frees the DLL for FFTW itself by calling FreeLibrary.
Now after you have called InitFFTW, you can use any of the other public functions in this module. The first one you are going to need to use is one of the Plan functions. This generates what the makers of FFTW call a "plan", which is an opaque structure that has all the stuff setup in memory needed to perform a particular type of timedomain2frequencydomain transform (or frequencydomain2timedomain transform). The value returned from such a Plan function is a handle to the plan. After the plan is set up, you can use it with either the initial data source and destination that was set up at the time of making the plan (via the FFTWExecute method), or use it on data sources or destinations other than those that were used at the time the plan was created (via one of the following methods, FFTWExecuteDFT, FFTWExecuteDFTR2C, FFTWExecuteDFTC2R, or FFTWExecuteR2R).
After you are done with executing the transform, if you don't need to use it again, you can call FFTWDestroyPlan. This will allow you to free the memory occupied by that plan. However, it doesn't get rid everything that was created when the plan was created. When the plan was created, something else called "wisdom" was also create. This is additional data that is created when the plan was created, which can optimize the internal workings of FFTW, so that future calls to plan creation functions can be speed up. The more plans you create, the more "wisdom" gets created, so use it, the faster it is able to operate when creating additional plans, because the more it is able to optimize its internal workings. It's a sort of "machine learning" algorithm that they seem to have implemented. However, if you want to clear out all the memory that got allocated by the use of FFTW (including all plans, and all created wisdom), without actually freeing the entire DLL file from memory, then you can use FFTWCleanup.
Note that, except for InitFFTW and CloseFFTW, all of the public methods in this module actually don't directly make a call to libfftw3-3.dll. Instead they make a call to a private function in my module called CallCDECL, which in turn uses the Windows API function called DispCallFunc to actually call the CDECL functions in the FFTW DLL file.
Last edited by Ben321; Aug 1st, 2016 at 11:36 PM.
Reason: fixed typo in thread title
-
Aug 5th, 2016, 01:41 PM
#2
Re: Module for directly using FFTW in VB6
PasteBin?
you could zip and attach
-
Aug 5th, 2016, 01:51 PM
#3
Re: Module for directly using FFTW in VB6
Also you can call a CDecl function directly in the compiled form using TLB.
-
Aug 6th, 2016, 11:40 PM
#4
Thread Starter
Frenzied Member
Re: Module for directly using FFTW in VB6
Originally Posted by The trick
Also you can call a CDecl function directly in the compiled form using TLB.
I believe a TLB requires that both the programmer and the end user, register the TLB with either an installer or manually with regsvr32, just like with ActiveX DLL and OCX (ActiveX control) files. I was trying to make a more user-friendly (read as, requiring fewer dependencies) way of handling FFTW in VB6. Using a TLB goes against this goal.
Besides, I don't even know how to create a TLB. Can this be done from within VB6, or will I need 3rd party software to do that?
-
Aug 7th, 2016, 06:31 AM
#5
Re: Module for directly using FFTW in VB6
You shouldn't register tlb on an end user machine. There is quite rare situations when you actually need to register tlb on the end user machine. I mean the user of exe/dll.
That is the simple example of calling cdecl functions diractly from vb6 (you need to compile exe, because ther is an IDE bug that doesn't allow use standard cdecl functions from IDE, although you can call cdecl methods of objects both in IDE and exe.)
http://www.vbforums.com/showthread.p...=1#post4975305
-
Aug 9th, 2016, 08:31 AM
#6
Re: Module for directly using FFTW in VB6
microsoft supplied mktyplib.exe with VB6.
-
Feb 21st, 2018, 07:19 PM
#7
New Member
Re: Module for directly using FFTW in VB6
Sorry for resurrecting such an old thread, but, Ben321 you wouldn't happen to have some examples of using the library would you?
-
Feb 22nd, 2018, 09:52 AM
#8
Re: Module for directly using FFTW in VB6
Pastebin is blocked at some companies... not to mention it's an external site.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|