YES, COOL - it now works as the attached PDF proves. 1000 timesRepeat: [ Transcript show: 'Henrik thanks!!!' ;cr ] Henrik - you have saved me to have to return to the darker sides of computing and digg deeper into low level again ;) I knew that it must have been something in the calling wrapper and was too blind to see it. A little bit misleading that one can not use the original C signature in the NB description with char* and autoconversion through NB. Maybe I was too used to NB's predecessor FFI where one wrote char* and just passed the Smalltalk string. Stupid me, I should have RTFM of NativeBoost instead of assuming its close to FFI in this regard! So again the problem was in front of the computer. Hey: that now means one can easily generate a PDF from websites or HTML generated by Pharo or Seaside, ... which I think is way cool! In return: will clean up the code as soon as possible, also a config, documention and an entry in the config browser. We can now proudly say: even when you want to print fancy stuff there is no excuse not to use Pharo for that ;) Bye T.
Gesendet: Freitag, 23. Mai 2014 um 14:52 Uhr Von: "Henrik Johansen" <henrik.s.johansen@veloxit.no> An: "Pharo Development List" <pharo-dev@lists.pharo.org> Betreff: Re: [Pharo-dev] NativeBoost and WKHTML
On 23 May 2014, at 2:36 , Torsten Bergmann <astares@gmx.de> wrote:
Hi,
as there was no responded so far I tried to track the problem deeper and did a short test client in C/C++ to verify if I can call WKHTMLTOPDF there and generate a PDF and to compare to the Pharo/NativeBoost client.
Attached is the according CPP file which works and results in a PDF with the google homepage.
I also additionally implemented the callback functions in the Pharo wrapper and using the error handling I noticed that the component returns "Failed loading page http:// ..."
With that info I compared the C/C++ calls to the Pharo/NativeBoost calls more deeply and found out that in C/C++ the following call for an object setting works (by returning 1):
// this returns 1 in C/C++ which is OK int a = wkhtmltopdf_set_object_setting(os, "page", "http://www.google.de"); printf("object set %i",a);
while in Pharo the same call fails (by returning 0):
"The following call failed and returns 0 instead of 1" self setObjectSetting: 'page' to: 'http://www.google.de' in: os.
With argument type char * , NB does not 0-terminate your strings, but passes in the argument you provided raw. ByteStrings have an internal representation size a multiplum of 4, thus âpageâ will have no accidentally terminating 0, while âoutâ does, and the call fails since whatever garbage bytes are in the image after the string instance (âpageâ) leads to the it not being recognized as a valid property name.
Change the call definitions to use String as argument type instead, and NB will convert the args to zero-terminated strings for you:
NBFFICallout stdcall: #(int wkhtmltopdf_set_object_setting(wkhtmltopdf_object_settings* settings, String aName, String value)) module: 'wkhtmltox.dll'
Alternatively, you need to provide null-terminated strings yourself:
x := self setObjectSetting: ('page' , (Character value: 0) asString) to: 'http://www.google.de', (Character value: 0) asString) in: os.
Which also returns makes it return 1.
Cheers, Henry