[C#] C/FRONT is terminated after handling exception

dominiquedominique Member Posts: 3
I'm currently writing a C# class to access a Navision database. I'm using LoadLibrary to gain access to the C/FRONT functions. I got a working app, although if I use a different database version, I get stuck with errors. I know you can't open other databases with C/FRONT other than it's own version, but I want a 'nice' message instead of that conversion popup.

But when I'm trying to connect to a 3.7 db with cfront 5.0, the exception is handled, after that the app is terminated with no message. When I try to debug with Visual Studio 2008, it says something about a buffer overrun. Basically the cfront dll is run as unmanaged code and the connectserverandopendatabase function doesn't modify it's parameters (const DBL_U8 *), so I don't see what's wrong. Whenever I try to connect to a 5.0 db, everything is fine (didn't test the exception handler on other functions yet), I can connect, get version, checklicensefile, closedatabase and disconnectserver, without problems.

Example:
// Part of code...

public delegate void FuncExceptionHandler(int ErrorCode, bool IsFatal);
private delegate IntPtr DBL_SetExceptionHandler(FuncExceptionHandler ExceptionHandler);
private DBL_SetExceptionHandler _SetExceptionHandler;

private LoadLib()
{
    IntPtr hCFront = LoadLibrary("cfront.dll");
    IntPtr hFunc = GetProcAddress(hCFront, "DBL_SetExceptionHandler");
    _SetExceptionHandler = (DBL_SetExceptionHandler)Marshal.GetDelegateForFunctionPointer(hFunc, typeof(DBL_SetExceptionHandler));
    //... You get the point :-P
}

public static void Main()
{
    LoadLib();
    _SetNavisionPath("C:\\Program Files\\MSBN5.0\\CSIDE Client");
    _Init();
    _SetExceptionHandler(new FuncExceptionHandler(HandleError));

    // Using a cfront 5.0 on a 3.7 db raises an exception
    _ConnectServerAndOpenDatabase("NDBCN","","tcp","C:\\Program Files\\MSBN3.7\\CSIDE Client\\database.fdb",0,true,true,"","");
}

public void HandleError(int ErrorCode, bool IsFatal)
{
    Console.WriteLine("e="+ErrorCode+"; f="+IsFatal);
}

The reason I'm not using OCX, it doesn't provide any functions to handle exceptions. When I use DllImport instead of LoadLibrary, I get AccessViolationExceptions.

I hope someone can tell me what I'm doing wrong or give suggestions.

Thanks in advance.

Comments

  • garakgarak Member Posts: 3,263
    in my oppinion / tests, the cfront 5.0 is not designed for 3.70.
    User for 3.70 the cfront dll for 3.7.
    Or, if possible, upgrade your DB to 5.x ;-)
    Do you make it right, it works too!
  • dominiquedominique Member Posts: 3
    I know it wasn't designed for 3.7 db's, all I want is normal detection of version incompatibility, not a database conversion popup with an OK button. It doesn't matter whether I can query the database or not, as long as the user gets a message.
Sign In or Register to comment.