View previous topic :: View next topic |
Author |
Message |
Ryan
Joined: 25 Feb 2016 Posts: 110
|
Posted: Thu Feb 25, 2016 9:32 pm Post subject: Call HtmlHelp API from C++ compiled with SCC |
|
|
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;
Code: | 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 |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Thu Feb 25, 2016 9:42 pm Post subject: |
|
|
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? |
|
Back to top |
|
|
Ryan
Joined: 25 Feb 2016 Posts: 110
|
Posted: Thu Feb 25, 2016 9:48 pm Post subject: |
|
|
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;
Code: | 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. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Fri Feb 26, 2016 8:39 am Post subject: |
|
|
Here is my test program...
Code: | #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. |
|
Back to top |
|
|
Ryan
Joined: 25 Feb 2016 Posts: 110
|
Posted: Fri Feb 26, 2016 10:23 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Sat Feb 27, 2016 8:47 am Post subject: |
|
|
You might need
Code: | extern "C" HWND WINAPI HtmlHelpA.... |
|
|
Back to top |
|
|
Ryan
Joined: 25 Feb 2016 Posts: 110
|
Posted: Wed Mar 02, 2016 4:02 pm Post subject: |
|
|
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;
Code: | #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;
Code: | scc helphang.cpp
slink helphang.dat
|
The linker command file is;
Code: | lo helphang
lo C:\Windows\System32\hhctrl.ocx
; lo C:\Windows\SysWOW64\hhctrl.ocx
file helphang |
|
|
Back to top |
|
|
Ryan
Joined: 25 Feb 2016 Posts: 110
|
Posted: Wed Mar 02, 2016 4:17 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Wed Mar 02, 2016 5:08 pm Post subject: |
|
|
I think that, on a 64 bit system, the ocx in System32 will be the 64 bit version.
Not the one that you want. |
|
Back to top |
|
|
Ryan
Joined: 25 Feb 2016 Posts: 110
|
Posted: Wed Mar 02, 2016 5:37 pm Post subject: |
|
|
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;
Code: |
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. |
|
Back to top |
|
|
|