` Printed Icetips Article

Icetips Article



Other Languages - using Clarion with...: C++ Calling clarion functions from VC
2002-11-28 -- Jim Kane
 
Newsgroups: comp.lang.clarion


I wrote a clarion dll to read tps files from vc.  I did not use (I never
use) mfc or atl.  This was a straight C app.
in callfile.c
     case WM_CREATE:
          hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
          hdc = GetDC (hwnd) ;
          GetTextMetrics (hdc, &tm) ;
          cxChar = tm.tmAveCharWidth ;
          cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;
          cyChar = tm.tmHeight + tm.tmExternalLeading ;
          ReleaseDC (hwnd, hdc) ;

   //load the clarion dll
    hGetFile =
          LoadLibrary(TEXT("GETFILE.DLL"));

    if(!hGetFile == 0)
    {
     PD_Init          =
         )GetProcAddress(hGetFile,"PD_INIT");
     PD_SetDataPath   =
D_SETDATAPATH   )GetProcAddress(hGetFile,"PD_SETDATAPATH");
   PD_GetBufferSize =
(PD_GETBUFFERSIZE )GetProcAddress(hGetFile,"PD_GETBUFFERSIZE");
   PD_OpenFile      =
PENFILE      )GetProcAddress(hGetFile,"PD_OPENFILE");
//more code here
    }
    else
    {
   MessageBox(hwnd,"LoadLib Failed for GetFile.dll","Fatal Error", MB_OK);
   SendMessage(hwnd,WM_CLOSE,0,0);
   return(1);
    }


    if(PD_Init == 0 || PD_SetDataPath==0 || PD_OpenFile==0 ||
PD_GetBufferSize==0 ||
//more code here
    )
          {
   MessageBox (hwnd, TEXT("Wrong version of GetFile.Dll"), TEXT("Fatal
Error"), MB_OK);
   SendMessage(hwnd,WM_CLOSE,0,0);
   return(1);
    }


    PD_Init();  //Init the dll
//rest of the program here......


then in callfile.h the prototypes
#ifndef CALLFILE_H
#define CALLFILE_H

#ifdef __cplusplus
extern "C" {
#endif

//Function Prototypes
typedef void (WINAPI * PD_INIT)(void);
PD_INIT PD_Init;

typedef unsigned char (WINAPI * PD_SETDATAPATH )(LPCSTR lpDataPath);
PD_SETDATAPATH PD_SetDataPath;

typedef unsigned char (WINAPI * PD_GETBUFFERSIZE)(LPCSTR lpFileLabel,
LPDWORD cbBuffer);
PD_GETBUFFERSIZE PD_GetBufferSize;

typedef unsigned char (WINAPI * PD_OPENFILE)(LPCSTR lpFileLabel, LPCVOID
lpBuffer, DWORD cbBuffer);
PD_OPENFILE PD_OpenFile;

typedef unsigned char (WINAPI * PD_CLOSEFILE)(LPCSTR lpFileLabel);
PD_CLOSEFILE PD_CloseFile;

//other prototypes here
//Equates
// Error Equates - Usually returned as a byte (unsigned char)
#define levelbenign 0 //No Error
#define levelfatal 3 //Error - Action did not complete
#define levelnotify 5 //Action didnt complete but not an error - typically
End of File
//Cstring size for File and Key Labels
#define LabelLen 41


#ifdef __cplusplus
};
#endif
#endif

Jim Kane


"Mihai Palade (Bucharest - Romania)"  wrote in message
news:3de5e21a@news.softvelocity.com...
> Hi,
>
> I have changed the name attribute as '_cwhello' ! I am getting exactly the
> same link error !
> The lib is the one generated by Clarion.
> Inside MSDN they say that LoadLibrary is another solution.
> What I am using impluies that CWHELLO is inside CWHELLO.DLL . (!?).
> As I said, I am very unexperienced here, I just wanna make a call from
VC++
> to Clarion.
> If possible and have some time, could you prepare for me a very simple
> example !?
> Thank you for your time !
>
> Mihai
>
> "jim kane"  wrote in message
> news:3de5b668$1@news.softvelocity.com...
> > change the name attribute to name('_cwhello')
> > that is what vc is looking for.
> > I dont know how you have made a lib for VC to link - usually I call by
> > address to call a cw dll.  I use loadlibrary, getprocaddress() and call
by
> > address.
> > jim kane
> >
> > "Mihai Palade"  wrote in message
> > news:3de56c88@news.softvelocity.com...
> > > Hello,
> > >
> > > No experience with VC++. I just wanna try if VC++ may call a Clarion
DLL
> :
> > >
> > > 1) I have a C55 DLL which exports a function
> > > CWHELLO - (REAL),REAL,C,NAME('CWHELLO') - it just shows up an HELLO
> > message
> > > box.
> > >
> > > 2) VC++ has to call the CWHELLO function
> > >
> > > QUESTION : What is the function prototype I have to use !?
> > >
> > > extern "C" double CWHELLO(double); (!!!???); in this case the compile
> > works
> > > but I am having problems with the linker :
> > >
> > > Linking...
> > > simpleCALL.obj : error LNK2001: unresolved external symbol _cwhello
> > > Debug/simpleCALL.exe : fatal error LNK1120: 1 unresolved externals
> > > Error executing link.exe.
> > >
> > > Mihai
> > >
> > >
> >
> >
>
>



Printed April 28, 2024, 12:21 am
This article has been viewed/printed 35140 times.
Google search has resulted in 317 hits on this article since January 25, 2004.