Missing win32 library. [SOLVED]

Windows specific questions.
SARG
Posts: 1101
Joined: May 27, 2005 7:15
Location: FRANCE

Missing win32 library. [SOLVED]

Postby SARG » May 20, 2013 15:31

@dkl
For a most integrated help in fbdebugger I need that the htmlhelp library (htmlhelp.lib and htmlhelp.h) be added in fbc (as .a and .bi files).
It's an "old" but still active standard library allowing to open only one instance of a help file with successive topics.
In addition the help file is associated with the calling application : when the application is terminated the help is also closed.

Is it possible ?

http://users.freebasic-portal.de/sarg/htmlhelp.h
http://users.freebasic-portal.de/sarg/htmlhelp.lib

If you need to check the lib, it's included with the doc files : http://www.microsoft.com/en-us/download ... x?id=21138


For now I use directly the lib and some elements from the h file. But if users want to compile fbdebugger I have to attached, at least, the lib.

Example of use to open a chm file on the desktop (do not execute it, testfb.chm nonexisting):

Code: Select all

#Include once "windows.bi"

Extern "windows" Lib "htmlhelp"
Declare Function HtmlHelpA(hwndCaller As HWND,pszFile As LPCSTR,uCommand As UINT,dwData As DWORD_PTR) As HWND
End Extern

#define HH_DISPLAY_TOPIC 0000 '  extracted from h file.
#define HH_HELP_CONTEXT  0015

'Open the help and show the topic
htmlhelpA(GetDesktopWindow(),"C:\HTML Help Workshop\testfb.chm::/main windows.htm",HH_DISPLAY_TOPIC,NULL)
Sleep 2000

'An other page is opened replacing the previous one
htmlhelpA(GetDesktopWindow(),"C:\HTML Help Workshop\testfb.chm::/execution buttons.htm",HH_DISPLAY_TOPIC,NULL)
Sleep 2000

'two other pages other opened by their index number
htmlhelpA(GetDesktopWindow(),"C:\HTML Help Workshop\testfb.chm",HH_HELP_CONTEXT,65536)
Sleep 2000
htmlhelpA(GetDesktopWindow(),"C:\HTML Help Workshop\testfb.chm",HH_HELP_CONTEXT,1000)
sleep 2000
Last edited by SARG on May 21, 2013 13:00, edited 1 time in total.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: Missing win32 library.

Postby MichaelW » May 21, 2013 1:03

It might be possible to create a working library but I doubt that doing so will be anything simple. And there is also the question of legality.

As found by the MinGW project staff, this file is a static library that calls LoadLibrary/GetProcAddress to access the file C:\WINDOWS\SYSTEM32\hhctrl.ocx, not an import library, and can be linked by ld.

http://www.citlink.net/~messengertj/htmlhelp.htm
SARG
Posts: 1101
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Missing win32 library.

Postby SARG » May 21, 2013 9:23

MichaelW wrote:It might be possible to create a working library but I doubt that doing so will be anything simple. And there is also the question of legality.

As found by the MinGW project staff, this file is a static library that calls LoadLibrary/GetProcAddress to access the file C:\WINDOWS\SYSTEM32\hhctrl.ocx, not an import library, and can be linked by ld.

http://www.citlink.net/~messengertj/htmlhelp.htm


@MichaelW thanks for your anwser. But sorry I don't understand where is the problem.
All of this is existing and fully working (I used the previous example to test). Nothing needs to be created.
I was just asking to include the library and the H file as the others .a and .bi files for windows. ;-)

Otherwise I would have to add the lib inside the fbdebugger zip file for the users wanting compile their own version.
And I guess that this library could be useful for other projects.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: Missing win32 library.

Postby MichaelW » May 21, 2013 10:50

SARG wrote:But sorry I don't understand where is the problem. All of this is existing and fully working (I used the previous example to test). Nothing needs to be created.
I was just asking to include the library and the H file as the others .a and .bi files for windows. ;-)

I have doubts that the Microsoft library can be legally redistributed in that way.
marcov
Posts: 2973
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Missing win32 library.

Postby marcov » May 21, 2013 10:56

MichaelW wrote:It might be possible to create a working library but I doubt that doing so will be anything simple. And there is also the question of legality.

As found by the MinGW project staff, this file is a static library that calls LoadLibrary/GetProcAddress to access the file C:\WINDOWS\SYSTEM32\hhctrl.ocx, not an import library, and can be linked by ld.

http://www.citlink.net/~messengertj/htmlhelp.htm


Note that you can link to the htmlhelpA and -W functions in the ocx, so it might be a matter of manually creating an import library for it. (FPC generates them on the fly, so I don't have one)

IOW, while that particular lib uses getprocaddress, it doesn't mean that all htmlhelp.lib versions are of the dynloading kind. (e.g. try platform sdk). Or create an own. (there are only two functions afaik)
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: Missing win32 library.

Postby MichaelW » May 21, 2013 12:34

marcov wrote:Note that you can link to the htmlhelpA and -W functions in the ocx, so it might be a matter of manually creating an import library for it. (FPC generates them on the fly, so I don't have one)

IOW, while that particular lib uses getprocaddress, it doesn't mean that all htmlhelp.lib versions are of the dynloading kind. (e.g. try platform sdk). Or create an own. (there are only two functions afaik)

Good idea, that in my simple test appears to work.

Code: Select all

pexports hhctrl.ocx > hhctrl.dll.def
pause
dlltool -d hhctrl.dll.def -l libhhctrl.dll.a
pause

Code: Select all

LIBRARY HHCTRL.OCX
EXPORTS
AuthorMsg
DllCanUnloadNow
DllGetClassObject
DllRegisterServer
DllUnregisterServer
HhWindowThread
HtmlHelpA
HtmlHelpW
LoadHHA
doWinMain

Code: Select all

#include "windows.bi"

extern "Windows-MS" lib "hhctrl"
    declare function HtmlHelpA( byval as HWND, byval as LPCSTR, _
                                  byval as UINT, byval as DWORD_PTR ) as HWND
end extern

#define HH_DISPLAY_TOPIC 0000

print HtmlhelpA( GetDesktopWindow(), "api.chm", HH_DISPLAY_TOPIC, NULL )

sleep

But there are still the questions of why Microsoft provides a static library instead of an import library, what sort of additional functionality does the static library provide, and how important is this functionality.

A few selected parts of a dump created by the Microsoft COFF Binary File Dumper:

Code: Select all

Dump of file htmlhelp.lib

File Type: LIBRARY

5 public symbols

      1FC ??_C@_00A@?$AA@
      1FC ?pHtmlHelpA@@3P6GPAUHWND__@@PAU1@PBDIK@ZA
      1FC ?pHtmlHelpW@@3P6GPAUHWND__@@PAU1@PBGIK@ZA
      1FC _HtmlHelpA@16
      1FC _HtmlHelpW@16

COFF SYMBOL TABLE
000 00000000 DEBUG  notype       Filename     | .file
    init.cpp
002 00000000 SECT1  notype       Static       | .drectve
    Section length   2A, #relocs    0, #linenums    0, checksum        0
004 00000000 SECT2  notype       Static       | .debug$S
    Section length 1D83, #relocs    8, #linenums    0, checksum        0
006 00000000 SECT3  notype       Static       | .rdata
    Section length   4C, #relocs    0, #linenums    0, checksum        0
008 00000010 SECT3  notype       Static       | _txtInProc$S28269
009 00000000 SECT3  notype       Static       | _txtHHCtrl$S28268
00A 00000000 SECT4  notype       Static       | .bss
    Section length   18, #relocs    0, #linenums    0, checksum        0
00C 00000014 SECT4  notype       External     | ?pHtmlHelpA@@3P6GPAUHWND__@@PAU1@PBDIK@ZA (struct HWND__ * (__stdcall* pHtmlHelpA)(struct HWND__ *,char const *,unsigned int,unsigned long))
00D 00000010 SECT4  notype       External     | ?pHtmlHelpW@@3P6GPAUHWND__@@PAU1@PBGIK@ZA (struct HWND__ * (__stdcall* pHtmlHelpW)(struct HWND__ *,unsigned short const *,unsigned int,unsigned long))
00E 00000000 SECT5  notype       Static       | .text
    Section length   99, #relocs    C, #linenums    F, checksum        0, selection    1 (pick no duplicates)
010 00000000 SECT5  notype ()    External     | _HtmlHelpA@16
    tag index 00000016 size 00000099 lines 0000214E next function 0000001F
012 00000000 UNDEF  notype ()    External     | __imp__GetProcAddress@8
013 00000000 UNDEF  notype ()    External     | __imp__LoadLibraryA@4
014 0000000C SECT4  notype       Static       | _?g_fTriedAndFailed@?1??HtmlHelpA@@9@16@4HA$S28296
015 00000004 SECT4  notype       Static       | _?g_hmodHHCtrl@?1??HtmlHelpA@@9@16@4PAUHINSTANCE__@@A$S28294
016 00000000 SECT5  notype       BeginFunction | .bf
    line# 0026 end 00000027
018 0000000F SECT5  notype       .bf or.ef    | .lf
019 00000099 SECT5  notype       EndFunction  | .ef
    line# 003d
01B 00000000 SECT6  notype       Static       | .debug$S
    Section length   D8, #relocs    6, #linenums    0, checksum        0, selection    5 (pick associative Section 5)
01D 00000000 SECT7  notype       Static       | .text
    Section length   5F, #relocs    5, #linenums    8, checksum        0, selection    1 (pick no duplicates)
01F 00000000 SECT7  notype ()    Static       | ?GetRegisteredLocation@@YGHPAD@Z (int __stdcall GetRegisteredLocation(char *))
    tag index 00000027 size 0000005F lines 0000234D next function 00000030
021 00000000 UNDEF  notype ()    External     | __imp__RegCloseKey@4
022 00000000 UNDEF  notype ()    External     | __imp__RegQueryValueExA@24
023 00000000 SECT8  notype       Static       | .rdata
    Section length    1, #relocs    0, #linenums    0, checksum        0, selection    2 (pick any)
025 00000000 SECT8  notype       External     | ??_C@_00A@?$AA@ (`string')
026 00000000 UNDEF  notype ()    External     | __imp__RegOpenKeyExA@20
027 00000000 SECT7  notype       BeginFunction | .bf
    line# 0012 end 00000034
029 00000008 SECT7  notype       .bf or.ef    | .lf
02A 0000005F SECT7  notype       EndFunction  | .ef
    line# 0022
02C 00000000 SECT9  notype       Static       | .debug$S
    Section length   7D, #relocs    2, #linenums    0, checksum        0, selection    5 (pick associative Section 7)
02E 00000000 SECTA  notype       Static       | .text
    Section length   99, #relocs    C, #linenums    F, checksum        0, selection    1 (pick no duplicates)
030 00000000 SECTA  notype ()    External     | _HtmlHelpW@16
    tag index 00000034 size 00000099 lines 00002520 next function 00000000
032 00000000 SECT4  notype       Static       | _?g_fTriedAndFailed@?1??HtmlHelpW@@9@16@4HA$S28322
033 00000008 SECT4  notype       Static       | _?g_hmodHHCtrl@?1??HtmlHelpW@@9@16@4PAUHINSTANCE__@@A$S28320
034 00000000 SECTA  notype       BeginFunction | .bf
    line# 0043 end 00000000
036 0000000F SECTA  notype       .bf or.ef    | .lf
037 00000099 SECTA  notype       EndFunction  | .ef
    line# 005a
039 00000000 SECTB  notype       Static       | .debug$S
    Section length   D8, #relocs    6, #linenums    0, checksum        0, selection    5 (pick associative Section a)
03B 00000000 SECTC  notype       Static       | .debug$T
    Section length 5928, #relocs    0, #linenums    0, checksum        0

BTW, even though the Htmlhelp.lib from my 2003 PSDK is ~1/4 the size of the static library, I have doubts that it’s a (normal) import library because, for example, the string “__imp__HtmlHelpA” does not appear in the file.

As a test I tried to link with it, and while the linker appeared to find the HtmlHelpA@16 function OK, there was another problem:

Code: Select all

./htmlhelp.lib(obj/i386/init.obj): In function `HtmlHelpA@16':
d:\dnsrv\enduser\h:3: undefined reference to `__security_cookie'
d:\dnsrv\enduser\h:22: undefined reference to `@__security_check_cookie@4'
./htmlhelp.lib(obj/i386/init.obj): In function `HtmlHelpW@16':
d:\dnsrv\enduser\h:3: undefined reference to `__security_cookie'
d:\dnsrv\enduser\h:22: undefined reference to `@__security_check_cookie@4'

The details of that problem are here.
SARG
Posts: 1101
Joined: May 27, 2005 7:15
Location: FRANCE

Missing win32 library. [solved]

Postby SARG » May 21, 2013 12:59

I have done this way and it's working. No need the lib. Thanks again.
By the way, I learn that an ocx is just a dll ;-)

Code: Select all

#Include once "windows.bi"

#Define HH_DISPLAY_TOPIC 0000
#define HH_HELP_CONTEXT  0015

Dim As Any Ptr library = DyLibLoad( "hhctrl.ocx" )
If library=0  Then Print "hhctrl.ocx not found":Sleep 2000:End
Print "Loaded":Sleep 2000

Dim HtmlHelpA As Function (hwndCaller As HWND,pszFile As LPCSTR,uCommand As UINT,dwData As DWORD_PTR) As HWND

HtmlHelpA = DyLibSymbol( library, "HtmlHelpA" )
If HtmlHelpA=0  Then Print "Address not found":Sleep 2000:End
Print "Address found"

''Open the help and show the topic
htmlhelpA(GetDesktopWindow(),"C:\HTML Help Workshop\testfb.chm::/main windows.htm",HH_DISPLAY_TOPIC,NULL)
Sleep 2000

HtmlHelpA(GetDesktopWindow(),"C:\HTML Help Workshop\testfb.chm::/execution buttons.htm",HH_DISPLAY_TOPIC,NULL)
Sleep 2000

''two other pages other opened by their index number
HtmlHelpA(GetDesktopWindow(),"C:\HTML Help Workshop\testfb.chm",HH_HELP_CONTEXT,65536)
Sleep 2000

HtmlHelpA(GetDesktopWindow(),"C:\HTML Help Workshop\testfb.chm",HH_HELP_CONTEXT,1000)
Sleep 2000

DylibFree(library)
marcov
Posts: 2973
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Missing win32 library. [solved]

Postby marcov » May 25, 2013 12:25

SARG wrote:By the way, I learn that an ocx is just a dll ;-)


Afaik it is a DLL that exposes an ActiveX object. But here they also added some plain procedures.

I wouldn't worry too much about how and why, CHM was introduced as part of MSIE, and has a convoluted history. I had code linking to hhctrl.ocx in late win98 times, and the same source still compiles.

Return to “Windows”

Who is online

Users browsing this forum: No registered users and 1 guest