Problem with DBL_SetMessageShowHandler and c#

athoma
Member Posts: 5
Hi to all,
i have casting DBL_SetMessageShowHandler in c#, this works fine, but
only first time
, at second error my function is not execute.
Any ideas?
regards, Arek
P.S. sorry for my bad english
i have casting DBL_SetMessageShowHandler in c#, this works fine, but
only first time

Any ideas?
regards, Arek
P.S. sorry for my bad english
using System; using System.Runtime.InteropServices; namespace TestAppNav { delegate void _ErrorShowProc(string Message, int MessageType, string ErrorCode); class Class1 { [DllImport("cfront.dll", CharSet=CharSet.Ansi , CallingConvention=CallingConvention.Cdecl) ] private static extern IntPtr DBL_SetMessageShowHandler(_ErrorShowProc ShowFunc); private static _ErrorShowProc oNavErr; private static string sMsg=null; static void myErrorShowProc(string Message, int MessageType, string ErrorCode) { //example sMsg = Message.ToString();// Char2Oem(Message.ToString()); Message = null; } [DllImport("cfront.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl) ] private static extern void DBL_ConnectServer( string ServerName, string NetType ); [DllImport("cfront.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl) ] private static extern bool DBL_Init(); [DllImport("cfront.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl) ] private static extern void DBL_Exit(); [DllImport("cfront.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl) ] private static extern void DBL_OpenDatabase(string DatabaseName, int CacheSize, bool UseCommitCache); [DllImport("cfront.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl) ] private static extern void DBL_OpenCompany(char[] CompanyName); [DllImport("cfront.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl) ] private static extern void DBL_CloseDatabase(); [DllImport("cfront.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl) ] private static extern string DBL_CompanyName(); [DllImport("cfront.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] private static extern Int32 DBL_GetVersion(); [DllImport("cfront.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl) ] private static extern void DBL_Ansi2OemBuff ([In,Out] char[] Src, [In,Out] char[] Dst,int DstSize); [DllImport("cfront.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl) ] private static extern void DBL_Oem2AnsiBuff ([In,Out] byte[] Src, [In,Out] byte[] Dst,int DstSize); [STAThread] static void Main(string[] args) { bool bOk = DBL_Init(); oNavErr = new _ErrorShowProc(myErrorShowProc); IntPtr nPointer = DBL_SetMessageShowHandler(oNavErr); GC.KeepAlive(oNavErr); OpenDatabase("D:\\_Navision\\Navision_Datenbanken\\databaseNavDemo370.fdb", 9000, true); //DBL_ConnectServer("192.168.1.28", "TCP"); //first Error -> ok OpenCompany("CRONUS 999999 AG"); Console.WriteLine("Navision Error " + sMsg); //second error -> nothing OpenCompany("CRONUS 88888 AG"); Console.WriteLine("Navision Error " + sMsg); Console.WriteLine( "Version {0}", DBL_GetVersion() ); DBL_Exit(); } public static bool OpenCompany(string p_CompanyName) { try { int nSizeLoc = p_CompanyName.Length; char[] myData = new char[nSizeLoc]; char[] myDest = new char[nSizeLoc]; myData= p_CompanyName.ToCharArray(); DBL_Ansi2OemBuff(myData, myDest, nSizeLoc); DBL_OpenCompany(myDest); return true; } catch { return false; } } public static bool OpenDatabase(string p_DatabaseName, int p_CacheSize, bool p_UseCommitCache) { try { DBL_OpenDatabase(p_DatabaseName, p_CacheSize, p_UseCommitCache); return true; } catch { return false; } } } }
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