using System; using System.Runtime.InteropServices; class MainClass { [DllImport("user32.dll")] private static extern bool CharToOem(System.Text.StringBuilder lpszSrc, System.Text.StringBuilder lpszDst); protected static string Char2Oem(string data) { System.Text.StringBuilder str = new System.Text.StringBuilder(data); System.Text.StringBuilder str2 = new System.Text.StringBuilder(data.Length); CharToOem(str,str2); return str2.ToString(); } [DllImport( "cfront.dll", CallingConvention = CallingConvention.Cdecl)] private static extern Int32 DBL_Init(); [DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)] private static extern void DBL_Exit(); [DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)] private static extern Int32 DBL_GetVersion(); [DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)] private static extern void DBL_ConnectServer( string server_name, string net_type ); private static void ConnectServer( string server, string net_type ) { string _server = Char2Oem( server ); string _net_type = Char2Oem( net_type ); DBL_ConnectServer( _server, _net_type ); } public static void Main(string[] args) { Console.WriteLine("Testing C/Front"); DBL_Init(); Console.WriteLine( "Version {0}", DBL_GetVersion() ); DBL_ConnectServer( "192.168.0.10", "TCP" ); DBL_Exit(); } }
Comments
I decided that maybe it wasn't the cfront.dll that was missing a related dll but maybe something that .NET was looking for so I compiled the code above using Portable.NET (http://www.dotgnu.org) and Mono (http://www.go-mono.org) and ran it using the respective interpreters and presto it worked! I connected looped through tables, read Company names, all without a problem.
Just for an experiment I used the other interpreters to run the above example compiled by the other compilers Mono an PNET played nice together but each time I tried the Microsoft .NET runtime it complained about the "Internal Error, etc".
Could somebody else compile and run the above example so I can work out if it is my installation of .NET that is the problem.
This is unlikely as this problem exists on at least 3 computers that I have tried it on.
I have tried it on :
WinXP professional, WinXP Home, Win2000 all with the SDK and Runtime environments installed.
I am not using Visual Studio so maybe VS installs something that is missing in the SDK or Runtime.
Any help would be greatly appreciated.
Regards, Simon.
Could some one try and compile this one? and run it on .NET and post the results, it would be greatly appreciated.
it is complaining at this line
if( 0 != DBL_OpenTable( ref htable, table_no ) )
with the following error
C:\My Documents\Visual Studio Projects\NavisionTest\NavisionTest\MainClass.cs(72): Use of unassigned local variable 'htable'
Any ideas?
should read
sorry for the typo
when I run it as a console app it compalins about CFRONT.dll.... I will look at it as time allows.
In the meantime have you considered http://msdn.microsoft.com/vstudio/tryit/
it provides an online (free) version of VS.net. for 3 hours (further blocks of time can be requested) 8)
change your code from
to
than your example works
For converting from oem to ansi you can use nav functions
Regards, Arek.
P.S. Sorry for my bad english
I made the change but I still get "Internal Error 182 in Module 1", did the second example work for you?
Are you using VS.NET or the SDK? I am using the SDK on Win2K and I am wondering if it forgot to installed some necessary dll.
I will try your change again on a WinXP machine and see if that makes a difference, I am also going to try and get a demo of VS.NET and try that, if that works then I'll get work to shell out money for it. Until I can prove that it works I am facing an uphill battle.
At least I know it works somewhere, which is great.
Maybe we should all start collaborating on a C# module that wraps up C/Front, anybody interested?
Thanks again, Simon.
Don't forget copy cfront.dll into your debug/release folder.
I work on wrapper class for navision. That works fine, but i have
problems with handling errors and messages (see my post about DBL_SetMessageShowHandler ())
regards, Arek