Re: Calling C functions from NewEra Pcode ?
Posted in 1996
Ian Macdonald wrote: > > Hello all. > > We have been trying without success to call C functions from our Newera pcode > executables. > > We've seen the section in the Release Notes regarding this, which seem somewhat > incoherent in that they a) refer to a type "cfunc_t" which isn't defined > anywhere that we can find, and b) say at one point that: > "Every DLL must include a function called GetUsrFunc() (or some other > fixed name) ..." > > Huh ? Some other fixed name ? Like what ? > > Anyway, we've followed the rules as best we can, substituting _USERFUNC for > c_funct (we found _USERFUNC in fglrt.h and it seemed somewhat appropriate), > with no success at all. Pcode applications which contain calls found in the > DLL and are run with "-u name.dll" just return "function foo not defined..." at > runtime. > > Before you ask, we've marked all our C functions for export, as well as the > UsrFuncts array and GetUsrFunc() and GetUsrFuncArray(). > > Anyone done this, or knows someone who has, or met someone at the pub who has, > or anything... ? Not that we're desperate, mind you; we've still got 20 days > to deadline... (but who's counting ?) > > Ian Macdonald, ikm@labsys.com.au Phone +61 3 9894 2500 > Laboratory Systems, Melbourne, Australia. Fax +61 3 9894 3338 Write NewEra code containing BEGIN_C and END_C. Make a project with NewEra Options -nosql -c++ and compile it to a DLL. Start fglgo your.4gi -u your.dll. The following sample doesn't work, it's just a hint! ****************************** sample.4gh ************************* INCLUDE SYSTEM "ixwindow.4gh" INCLUDE SYSTEM "ixapp.4gh" INCLUDE SYSTEM "ix4gl.4gh" CLASS sample FUNCTION prtDialog(win ixWindow) PRIVATE VARIABLE hwnd ixWindow PUBLIC VARIABLE portraitLen, landscapeLen SMALLINT FUNCTION !destroy() END CLASS ****************************** sample.4gl ************************* INCLUDE "prtlib.4gh" BEGIN_C #include <string.h> #include <stdlib.h> #include <stdio.h> #include <print.h> #include <commdlg.h> extern "C" HWND __getHWndFromixWindow(struct ixwindow *); PRINTDLG pd; END_C ############################################################## FUNCTION prtDialog::prtDialog(win ixWindow) LET hwnd = win BEGIN_C char szPrinter[80]; char *szPort; memset(&pd, 0, sizeof(PRINTDLG)); pd.lStructSize = sizeof(PRINTDLG); pd.hwndOwner = __getHWndFromixWindow(self->hwnd); pd.Flags = PD_RETURNDC | PD_PRINTSETUP; END_C END FUNCTION