SetMessageShowHandler problem with CFRONT/C#

HalfVector
Member Posts: 3
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:
DBL_pFuncMessageShowHandler has the following prototype:
I import the function in C# like this:
And the delegate is declared as:
Then I call the native function like this:
showMessageHandlerDelegate is an instance of ShowMessageHandlerDelegate:
CustomShowMessageHandler is declared as follows:
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.
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.
0
Comments
-
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.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