Silverfrost Forums

Welcome to our forums

Call HtmlHelp API from C++ compiled with SCC

25 Feb 2016 8:32 #17240

I have an existing hybrid Fortran / C++ app that calls WinHelp.

I have rewritten the API call from WinHelp to HtmlHelp as we are now using the newer help format.

Unfortunately I cannot get the SCC / SLINK combination to bring in the HtmlHelp library.

In the C++ code I have 'Include 'HtmlHelp.h'' at the top and reworked the API call, this passes through the compiler OK.

The problem comes when I link using SLINK, it is finding and using the htmlhelp.lib file fine, but this has a further dependency on some other API calls with odd prefixes. I've included the command 'lo htmlhelp.lib' to reference the file.

The errors generated are;

WARNING the following symbols are missing:
_imp__GetProcAddress                     H:\MyApp\htmlhelp.lib (/0             )
                                              (release/init.obj)
_imp__LoadLibraryA                       H:\MyApp\htmlhelp.lib (/0             )
                                              (release/init.obj)
_imp__RegCloseKey                        H:\MyApp\htmlhelp.lib (/0             )
                                              (release/init.obj)
_imp__RegQueryValueExA                   H:\MyApp\htmlhelp.lib (/0             )
                                              (release/init.obj)
_imp__RegOpenKeyExA                      H:\MyApp\htmlhelp.lib (/0             )
                                              (release/init.obj)

I understand why it needs GetProcAddress etc, I can't figure out why the lib has references to imp_ versions which won't resolve. Using a hex editor I can see the htmlhelp.lib file has '!<arch>' as a header which I thought was a COFF archive, supposedly linkable.

I'm OK with C++ inside Visual Studio but I can't figure out how to get the Salford compiler (SCC) to compile and link this particular library.

What obvious thing am I missing?

Thanks in advance,

Ryan

25 Feb 2016 8:42 #17241

I am guessing that the problem is that the library resides in an ocx (ActiveX) file rather than a DLL.

Which HTML functions are you accessing?

25 Feb 2016 8:48 #17242

Hi Paul,

Yes, the lib does something with HHCTRL.OCX. I was hoping that the lib would be statically linked in and handle all of the OCX loading at runtime, but I'm not sure what I am doing.

The API call I am trying to execute is HtmlHelp as defined at https://msdn.microsoft.com/en-us/library/windows/desktop/ms670172(v=vs.85).aspx

My test code is;

  HWND return_code = HtmlHelp(GetDesktopWindow(), 'hlp.chm\::/copyright.htm', HH_DISPLAY_TOPIC, NULL);

I have been able to compile and run a console app launching help in Visual C using this code. So I'm a little lost.

26 Feb 2016 7:39 #17243

Here is my test program...

#include <windows.h>
#define HH_DISPLAY_TOPIC 0x0000
HWND WINAPI HtmlHelpA(HWND hwndCaller,LPCSTR pszFile,UINT uCommand,DWORD dwData);
 
int main()
{
   HWND return_code = HtmlHelpA(GetDesktopWindow(), 'hlp.chm\::/copyright.htm', HH_DISPLAY_TOPIC, NULL); 
   return 0;
}

For SLINK you can load hhctrl.ocx but you will need to put hhctrl.ocx somewhere where SLINK can see it.

26 Feb 2016 9:23 #17245

Thanks Paul,

That's moved me along somewhat. I can understand what's going on there.

I'm now getting a hang when calling the API but that's something I think I can troubleshoot. Probably down to bad parameters.

Regards

Ryan

27 Feb 2016 7:47 #17247

You might need

extern 'C' HWND WINAPI HtmlHelpA....
2 Mar 2016 3:02 #17274

Hi Paul,

I'm still stuck, I have attempted to use just your sample and replaced the .chm file too in case that is causing it.

I have also linked to both WOW64 and System32 versions of hhctrl.ocx but the app still hangs and never returns from the API call.

Do you have any more ideas? I have noticed that memory usage climbs dramatically for the process once in while so I have a leak or a bad calling convention.

Here is what I have;

helphang.cpp;

#include <windows.h> 
#define HH_DISPLAY_TOPIC 0x0000 

extern HWND WINAPI HtmlHelpA(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD dwData);

int main()
{
	HWND return_code = HtmlHelpA(GetDesktopWindow(), 'hlp.chm\\::/copyright.htm', HH_DISPLAY_TOPIC, NULL);
	return 0;
}

I then compile and link it with;

scc helphang.cpp
slink helphang.dat

The linker command file is;

lo helphang
lo C:\Windows\System32\hhctrl.ocx
; lo C:\Windows\SysWOW64\hhctrl.ocx

file helphang
2 Mar 2016 3:17 #17275

I've narrowed it down.

Part of the problem I was experiencing was that the first of my many test API calls failed and ran up a huge memory bill. During that time, it locked the CHM file.

So when I quit and retried another API approach, I just got a plain hang as the file was locked.

They both looked the same though.

I'll keep going and will post the answer, I suspect it is due to stack space as there is a note in the HTML API about that and a specific stack size is set in my original code.

2 Mar 2016 4:08 #17276

I think that, on a 64 bit system, the ocx in System32 will be the 64 bit version. Not the one that you want.

2 Mar 2016 4:37 #17277

It seems to be the location of the stack that is causing it, which is a worry as I don't really understand why the stack was set so high.

It works if I relocate (or shrink?) the stack, I'm not sure what the parameters do.

The slink command file and adjustments;

lo helphang
lo C:\Windows\System32\hhctrl.ocx
; lo C:\Windows\SysWOW64\hhctrl.ocx

; Takes about 40 seconds delay before launching and help app is corrupt.
; stack 0x21000000

; Does not come back.
; stack 0x40000000

; Launches immediately.
stack 0x01000000

file helphang

Obviously the stack was set that way for a reason so if I change it I may cause issues.

Please login to reply.