Recent

Author Topic: [solved] load hunspell.dll  (Read 10866 times)

dbannon

  • Hero Member
  • *****
  • Posts: 788
    • tomboy-ng, a rewrite of the classic Tomboy
[solved] load hunspell.dll
« on: February 02, 2018, 08:44:41 am »
Hi Folks, needing to do some spell checking and going over the forum and looking at whats likely to be installed already, I choose hunspell. If nothing else, hunspell is used by LibreOffice and it would be nice to avoid further install demands. Several code snippets out there ...

I found getting it to work under Linux easy but cannot get the call to LoadLibrary() to work under Windows. Perhaps, as much as anything, because I don't know what the DLL is really called or where it is. The code snipits all seem to just say LoadLibrary(Pchar('hunspell.dll')) with no path (have they put the dll in working directory ?). I do not seem to have a dll by that name on my windows box and it does have a working hunspell spell checker in LibreOffice.

I can even find the LibreOffice's  dictionary files.

Can anyone suggest how I find (and load) the hunspell.dll ?

If you help me, I promise not to say anything nasty about windows for at least a week !

Davo 
« Last Edit: February 20, 2018, 11:56:26 am by dbannon »
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: load hunspell.dll
« Reply #1 on: February 02, 2018, 08:47:24 am »
hunspell is not part of windows you need to either find the dll (openoffice might install a version) or build it from source your self.after that placing the dll in the same directory as your exe should be enough to allow loadlibrary to work.
« Last Edit: February 02, 2018, 08:49:31 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1250
Re: load hunspell.dll
« Reply #2 on: February 02, 2018, 09:06:19 am »
Just had a look in my LibreOffice portable apps folder - no sign of hunspell.dll.

Oh, there is a copy shipped with CuteMarkEdPortable though.  DependancyWalker lists two other DLLs (libgcc_s_dw2-1.dll, libstdc++-6.dll), both in the same folder.  Should be able to copy those three into the same folder as your exe...

https://portableapps.com/apps/office/cutemarked-portable
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: load hunspell.dll
« Reply #3 on: February 02, 2018, 10:20:52 am »
hunspell.dll is statically linked in Libre/Open-Office.

See the list at https://en.wikipedia.org/wiki/Hunspell

You could also try the downloads at http://www.crawler-lib.net/nhunspell
It has a Hunspellx86.dll and Hunspellx64.dll (besides the NHunspell.dll)

(There is also a wrapper for NHunspell for Delphi 2007+ floating around)
« Last Edit: February 02, 2018, 10:24:14 am by rvk »

dbannon

  • Hero Member
  • *****
  • Posts: 788
    • tomboy-ng, a rewrite of the classic Tomboy
Re: load hunspell.dll
« Reply #4 on: February 02, 2018, 11:53:20 am »
Quote
hunspell.dll is statically linked in Libre/Open-Office.
OK, that explains why I cannot find it.

Thanks guys, unfortunately, neither suggestion worked, they do not load.

And, even more unfortunate, LoadLibrary() is in the RTL and apparently I cannot debug into there. So, I cannot find out even if its trying to open it and failing or still, somehow, not looking in the right place (I have tried an explicit path). Sigh...

Might try opening some other random dll. Obviously I won't get any further than opening it but thats further than I have got so far.....

I am quite sure I am not the first person to try and load a library into a Lazarus app......

D
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

GetMem

  • Hero Member
  • *****
  • Posts: 3519
Re: load hunspell.dll
« Reply #5 on: February 02, 2018, 11:59:10 am »
@dbannon
Put the dlls in the same directory with your exe.  To test if a particular library can be loaded:
Code: Pascal  [Select]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   LibHandle: TLibHandle;
  4. begin
  5.   LibHandle := LoadLibrary('FullPathToYourLibrary');
  6.   if LibHandle <> NilHandle then
  7.   begin
  8.      Showmessage('ok');
  9.   end;
  10. end;

If you know the name of the function, you can load it dynamically as well.

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: load hunspell.dll
« Reply #6 on: February 02, 2018, 12:01:04 pm »
Thanks guys, unfortunately, neither suggestion worked, they do not load.
Are you sure.
I just tried this and it worked for both hunspell and nhunspell DLLs.

Code: Pascal  [Select]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   Handle1: TLibHandle;
  4. begin
  5.  
  6.   Handle1 := LoadLibrary('Hunspellx86.dll');
  7.   if Handle <> 0 then
  8.   begin
  9.     Showmessage('Library Hunspellx86.dll loaded');
  10.     FreeLibrary(Handle1);
  11.   end
  12.   else
  13.     Showmessage('Error');
  14.  
  15.   Handle1 := LoadLibrary('NHunspell.dll');
  16.   if Handle <> 0 then
  17.   begin
  18.     Showmessage('Library NHunspell.dll loaded');
  19.     FreeLibrary(Handle1);
  20.   end
  21.   else
  22.     Showmessage('Error');
  23.  
  24. end;

Make sure you load the correct bitness dll. So in 32bit appllication load x86 and in 64bit application load x64.

dbannon

  • Hero Member
  • *****
  • Posts: 788
    • tomboy-ng, a rewrite of the classic Tomboy
Re: load hunspell.dll
« Reply #7 on: February 02, 2018, 01:05:44 pm »
OK, so I wrote  long answer saying Yes I'm sure and was about to post the code I am using. Then I realised it was in fact loading, since I started using the Hunspellx64.dll

Its just that the function then goes on to do things like

Code: Pascal  [Select]
  1. Hunspell_create := THunspell_create(GetProcAddress(HunLibHandle, 'Hunspell_create'));

And they are all failing, and the function returns false.

Thanks folks, tomorrow I'll try and workout why GetProcAddress() fails. Sort of sounds like those functions are not actually in the DLL. I think I'm going to learn a lot more about Windows DLL than I want to...

At least now I can LoadLibrary ....
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: load hunspell.dll
« Reply #8 on: February 02, 2018, 01:25:11 pm »
OK, so I wrote  long answer saying Yes I'm sure and was about to post the code I am using. Then I realised it was in fact loading, since I started using the Hunspellx64.dll

Its just that the function then goes on to do things like

Code: Pascal  [Select]
  1. Hunspell_create := THunspell_create(GetProcAddress(HunLibHandle, 'Hunspell_create'));

And they are all failing, and the function returns false.

Thanks folks, tomorrow I'll try and workout why GetProcAddress() fails. Sort of sounds like those functions are not actually in the DLL. I think I'm going to learn a lot more about Windows DLL than I want to...

At least now I can LoadLibrary ....
1)there are a number of open source projects that bind with (n)hunspell dlls for delphi already try using one of them as base.
2) use a dependency walker application for windows to see which functions are exported from your dll.
3) make sure that both libraries (linux/windows) use the same compiler (and version) to avoid problems with the exported names, c/C++ is notoriously problematic with name mangling.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: load hunspell.dll
« Reply #9 on: February 02, 2018, 01:35:04 pm »
Thanks folks, tomorrow I'll try and workout why GetProcAddress() fails. Sort of sounds like those functions are not actually in the DLL. I think I'm going to learn a lot more about Windows DLL than I want to...
I see that the Hunspellx64.dll has different exported functions (see left on image).

I downloaded the thunspell.zip from Torry (THunSpell v.1.13 which you can port B.T.W. or use as example).
That one does have hunspell_create (see right on image).

So you might need to compile the 64bit version yourself or find another one other than the nhunspell one, with the correct functions.
« Last Edit: February 02, 2018, 01:38:26 pm by rvk »

dbannon

  • Hero Member
  • *****
  • Posts: 788
    • tomboy-ng, a rewrite of the classic Tomboy
Re: load hunspell.dll
« Reply #10 on: February 03, 2018, 12:56:55 pm »
OK, just to be clear.

My problem is that I can get my hands on three different hunspell.dll files. The one from portable apps and the one from Torry are both 32 bit and unusable with my 64 bit FPC/Lazarus install on Windows. The 64bit one from NHunspell uses totally different names for functions (not just different capitalisation) - don't know why. Or how to use it.

To prove the above, I took my windows code back to my Linux box where I have some cross compilers setup, built a 32bit windows version of my test app, took the binary back to the Windows box and it did exactly what it should do there with the Torry dll (did not test the portableapps one).

The solution is that I need to build a 64bit windows DLL. And make it available too. I'll put all of this one a wiki page when I get it all working reliably on all three platforms.

Thanks folks for your help, this forum really is something special !

PS - DependancyWalker - the one I found is 12 years old and gave me all sorts of errors. Is that what people expect ? http://www.dependencywalker.com/

David
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: load hunspell.dll
« Reply #11 on: February 03, 2018, 01:22:19 pm »
PS - DependancyWalker - the one I found is 12 years old and gave me all sorts of errors. Is that what people expect ? http://www.dependencywalker.com/
that's the one I'm using with out any problems. There are 3 versions keep away of the ia64 there is no hardware to support it any longer. for optimal operation you need to much the bitness of the loaded executable to the bitness of the walker ee use the x86 to inspect 32bit applications and the x64 for 64bit. I never tested it under wine on linux though.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 6491
Re: load hunspell.dll
« Reply #12 on: February 03, 2018, 01:33:21 pm »
Looks that it does not work on Win10 where even the analysis of notepad.exe results in an eternal hourglass.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: load hunspell.dll
« Reply #13 on: February 03, 2018, 01:35:38 pm »
Looks that it does not work on Win10 where even the analysis of notepad.exe results in an eternal hourglass.
here are a couple alternatives https://alternativeto.net/software/dependency-walker/  it lists the one rvk used on his screen shots too.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

dbannon

  • Hero Member
  • *****
  • Posts: 788
    • tomboy-ng, a rewrite of the classic Tomboy
Re: load hunspell.dll
« Reply #14 on: February 05, 2018, 07:23:02 am »
Taazz said
Quote
keep away of the ia64 there is no hardware to support it
What ?  I can remember the HP rep assuring me the future of (my sort of) computing was definitely Itanium. Made me shut down my Alpha Cluster....

Jokes aside, Dependency Walker does work for me, shows me what I wanted to know such as names of methods. But it also shows a lot of errors, and, even with a 64bit DLL on a 64bit system and a 64bit Dependency Walker seems to want to link in a whole lot of 32bit libraries. And thats even if I look at an internal windows10 DLL.

But it did show me some of what I needed to know. Exception being whether the DLL is 32bit or 64bit. 

I'll have a look at suggested alternatives.

Thanks
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng