CFront compilation problems

c.kestasc.kestas Member Posts: 15
edited 2007-03-16 in Navision Attain
I'm new in C/front and I'm having trouble compiling the sample program (sample.c) that comes with the Navision CD. I have C/Front for Navision 4.00 and I try to compile with C++ (Visual Studio .NET).

I get many errors like the one that follows:

error C2664: 'stricmp' : cannot convert parameter 1 from 'DBL_U8 *' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Any ideas?
Thanks

Comments

  • dick11dick11 Member Posts: 60
    That code is (old) standard C. The compiler of VS is more strict today so it complains more often. You could decrease you compiler warning level.

    I use C#: no problem, only a lot of work.

    Search for dllimport in this forum. Also look in the cf.h file for the exact interface.
    Dick van der Sar

    www.dasautomatisering.nl
  • NeoskyNeosky Member Posts: 1
    I had exactly the same problem. And I like to use c++ so I was happy to find this post but pity finding not solution here, so I work out a solution as follows.

    After coping the content of sample.c to sample.cpp and libload.c to libload.cpp and compilation of sample.cpp with Visual Studio .NET 2003 you get the following error:

    C1083 Include_file can’t be loaded ‘cf/ch.h’
    Solution: change
    #include <cf/cf.h>
    

    To
    Extern "C" {
    #include "cf.h"
    }
    

    The same applies to lipload.cpp.
    Neosky wrote:
    Added:If you don't do so you will get in the end a Linker error: 92 unsolved reference.

    Next error C1004 says that the file ends unexpected just delete the last symbol in the cf.h
    c.kestas wrote:
    error C2664: 'stricmp' : cannot convert parameter 1 from 'DBL_U8 *' to 'const char *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    After a little search [1] [2] [3] I found that it is a convert problem.
    typedef unsigned char DBL_U8;		
    DBL_U8     *NDBCDriverName = (DBL_U8*)"ndbcn";
    
    unsigned char *NDBCDriverName;
    

    The Code above shows that NDBCDriverName is a pointer to ‘unsigned char’ but ‘stricmp’ is requires a pointer to 'const char', the almost the same applies to lines below here ‘SessionInit’ is waiting for a pointer to unsigned char. The Solution is a typecast:
    //<<<Changed by Neosky>>>---[(const char*)]---{to convert unsigned char* to const char*}
      //<<<Changed by Neosky>>>---[(unsigned char*)]---{to convert const char* to unsigned char*}
      if (!stricmp((const char*)NDBCDriverName, "NDBCN"))
        SessionInit((unsigned char*)"cfront.dll");
      else if (!stricmp((const char*)NDBCDriverName, "NDBCS"))
        SessionInit((unsigned char*)"cfrontsql.dll");
    

    The next error C2440 ‘=’:’void*’ can’t be converted to ‘’comes after compiling libload.cpp
    hGlobalSession = malloc(sizeof(DLL));
    

    This means the function malloc gives out a void value witch need to be converted by typecast to HDLLSESSION, HDLLSESSION is a static struct DLL* as shown:
    _CRTIMP void * __cdecl malloc(size_t);
    
    typedef struct DLL
    {
      char               DLLName[20];
      DBL_S16            DLLLoaded;
      DBL_DLLHandleType* DLLHandle;
    } DLL;
    typedef struct DLL* HDLLSESSION;
    static HDLLSESSION hGlobalSession = NULL;
    

    So the solution is as follows:
    //<<<Changed by ber_lst>>>---[(struct DLL*)]---{to convert void* to struct DLL* }
      hGlobalSession = (struct DLL*)malloc(sizeof(DLL));
    

    The last error C2664 says ‘strcpy’ converting of parameter 2 from ‘DBL_U8*’ to ‘const char*’ is not possible.
    strcpy(hGlobalSession->DLLName, DLLName);
    

    DLLName is a DBL_U8 type and as such it is unsigned char, so that means a pointer to unsigned char can’t be converted to a pointer to const char.
    char *  __cdecl strcpy(char *, const char *);
    
    void SessionInit&#40;DBL_U8* DLLName&#41;
    &#123;
      //<<<Changed by ber_lst>>>---[(struct DLL*)]---{to convert void* to struct DLL* }
      hGlobalSession = (struct DLL*)malloc(sizeof(DLL));
      strcpy(hGlobalSession->DLLName, DLLName);
      hGlobalSession-&gt;DLLLoaded = 0;
      DBL_Init&#40;&#41;;
    &#125;
    

    The Solution:
    //<<<Changed by ber_lst>>>---[(const char*)]---{to convert unsigned char* to struct const char*}
      strcpy(hGlobalSession->DLLName, (const char*)DLLName);
    

    Finally copy all needed files as descript in readme.txt of c/front sample to the debug folder, compil the sample.exe and have fun. =D>
Sign In or Register to comment.