CFront compilation problems

c.kestas
Member Posts: 15
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
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
0
Comments
-
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.0 -
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>
ToExtern "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.hc.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.cpphGlobalSession = 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(DBL_U8* DLLName) { //<<<Changed by ber_lst>>>---[(struct DLL*)]---{to convert void* to struct DLL* } hGlobalSession = (struct DLL*)malloc(sizeof(DLL)); strcpy(hGlobalSession->DLLName, DLLName); hGlobalSession->DLLLoaded = 0; DBL_Init(); }
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>0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions