SetMessageShowHandler problem with CFRONT/C#

HalfVectorHalfVector Member Posts: 3
edited 2008-04-24 in Navision Attain
Hi all.

First, I'm using cfront.dll for Navision 3.6 and C#.

I'm trying to stop Navision from showing message boxes every time an error occurs.

I know that in cfront.dll for Navision 4.0 you have the method DBL_HideMessageShowHandler but not in 3.6 that it's what I'm using right now.

So I've discovered that assigning a callback function using DBL_SetMessageShowHandler, you achieve this (I saw that in the sample that comes with the SDK in C) but unfortunately I can't get this working with C#.

The declaration for DBL_SetMessageShowHandler is:
typedef void* (DBL_CDECL *tDBL_SetMessageShowHandler)(DBL_pFuncMessageShowHandler ShowFunc);

DBL_pFuncMessageShowHandler has the following prototype:
typedef void (DBL_CDECL *DBL_pFuncMessageShowHandler)(DBL_U8* Message, DBL_U32 MessageType, DBL_S32 ErrorCode);

I import the function in C# like this:
[DllImport("cfront.dll", EntryPoint = "DBL_SetMessageShowHandler")]
internal static extern IntPtr SetMessageShowHandler(NavisionMessageHandler.ShowMessageHandlerDelegate showFuncPtr);

And the delegate is declared as:
internal delegate void ShowMessageHandlerDelegate(byte[] message, uint messageType, int errorCode);

Then I call the native function like this:
NativeMethods.SetMessageShowHandler(showMessageHandlerDelegate);

showMessageHandlerDelegate is an instance of ShowMessageHandlerDelegate:
showMessageHandlerDelegate = new ShowMessageHandlerDelegate(CustomShowMessageHandler);

CustomShowMessageHandler is declared as follows:
private void CustomShowMessageHandler(byte[] message, uint messageType, int errorCode)
{
}

So SetMessageShowHandler is always returning a NULL pointer (I guess should return the address of the callback funcion).

The truth is I have no idea what's going on. I'm using SetExceptionHandler that is almost the same than SetMessageShowHandler (except that it has 2 parameters instead of 3) and it's working right.

I'm thinking the problem could be the "byte[]" type but I've tried with "string" too with no luck.

Someone has encountered this same problem?

Thank you.

Comments

  • HalfVectorHalfVector Member Posts: 3
    Oh my god, I was calling SetMessageShowHandler before calling DBL_Init.

    Now it's working (CustomShowMessageHandler is called) but I'm receiving some exceptions. I'll try to fix that!.

    Thank you.
Sign In or Register to comment.