A
Alfred B. Thordarson
I have a problem accessing a DLL using C#.
I'm using C/FRONT with Navision's CFRONT.DLL, which contains the
method:
DBL_S32* DBL_NextKey(DBL_HTABLE hTable, DBL_S32* Key);
typedef signed long int DBL_S32;
In addition the documentation says that "hTable" is the "Handle to the
table" and "Key" is "A table key or a NULL". Trying to access this
method from C# (FYI: I'm using Visual Studio), I see the method
defined as:
object CFRONTClass.NextKey(int hTable,ref object key);
The first parameter is not a problem. I have a valid integer for the
hTable, which works for other methods that don't take "object" as a
parameter. But I would like to send "NULL" (as the documentation
describes) as the second parameter (key), it is this paramter's actual
type that is my problem.
I have spent some time on figuring out what the type should be but I
get type mismatch exceptions for all the different types like int[],
Int32[], object[], etc. In the end I found the IntPtr type and now I'm
writing the code as:
IntPtr[] key=new IntPtr[21];
object keyObject=(object)key;
nav.NextKey(hTableRef,ref keyObject);
This gets me further but doesn't work. Besides, it is not NULL, it is
just a reference to an array of integer pointers (as I understand it).
This code now gives me the following exception:
An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Old format or invalid type library.
Unhandled Exception: System.Runtime.InteropServices.COMException
(0x80028019): Old format or invalid type library.
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[]
byrefModifiers, Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes,
MessageData& msgData)
at CFRONTLib.CFRONTClass.NextKey(Int32 hTable, Object& Key)
at WinNavAccessApp.Form1..ctor() in
c:\alfred\vstudio\wstest\winnavaccessapp\form1.cs:line 90
at WinNavAccessApp.Form1.Main() in
c:\alfred\vstudio\wstest\winnavaccessapp\form1.cs:line 148
The program '[1692] WinNavAccessApp.exe' has exited with code 0 (0x0).
I'm totally stuck here and need some help with changing my code above
so that I send the proper type and value into the NextKey method
I would appreciate all the help you could give me.
I'm using C/FRONT with Navision's CFRONT.DLL, which contains the
method:
DBL_S32* DBL_NextKey(DBL_HTABLE hTable, DBL_S32* Key);
typedef signed long int DBL_S32;
In addition the documentation says that "hTable" is the "Handle to the
table" and "Key" is "A table key or a NULL". Trying to access this
method from C# (FYI: I'm using Visual Studio), I see the method
defined as:
object CFRONTClass.NextKey(int hTable,ref object key);
The first parameter is not a problem. I have a valid integer for the
hTable, which works for other methods that don't take "object" as a
parameter. But I would like to send "NULL" (as the documentation
describes) as the second parameter (key), it is this paramter's actual
type that is my problem.
I have spent some time on figuring out what the type should be but I
get type mismatch exceptions for all the different types like int[],
Int32[], object[], etc. In the end I found the IntPtr type and now I'm
writing the code as:
IntPtr[] key=new IntPtr[21];
object keyObject=(object)key;
nav.NextKey(hTableRef,ref keyObject);
This gets me further but doesn't work. Besides, it is not NULL, it is
just a reference to an array of integer pointers (as I understand it).
This code now gives me the following exception:
An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Old format or invalid type library.
Unhandled Exception: System.Runtime.InteropServices.COMException
(0x80028019): Old format or invalid type library.
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[]
byrefModifiers, Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes,
MessageData& msgData)
at CFRONTLib.CFRONTClass.NextKey(Int32 hTable, Object& Key)
at WinNavAccessApp.Form1..ctor() in
c:\alfred\vstudio\wstest\winnavaccessapp\form1.cs:line 90
at WinNavAccessApp.Form1.Main() in
c:\alfred\vstudio\wstest\winnavaccessapp\form1.cs:line 148
The program '[1692] WinNavAccessApp.exe' has exited with code 0 (0x0).
I'm totally stuck here and need some help with changing my code above
so that I send the proper type and value into the NextKey method
I would appreciate all the help you could give me.