473,386 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Accessing a DLL from C#

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(Strin g 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.
Nov 15 '05 #1
6 5181
Alfred, have you tried just passing null like this? I've never used that
dll myself but sounds like that might work for you.

IntPtr[] key=new IntPtr[21];
nav.NextKey(hTableRef, null);

--
Greg Ewing [MVP]
http://www.citidc.com/


"Alfred B. Thordarson" <at*********@landsteinar.je> wrote in message
news:79**************************@posting.google.c om...
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(Strin g 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.

Nov 15 '05 #2
No I haven't; because you can't pass a null to a ref parameter. A ref
parameter requires the caller to pass a valid object of the proper
type. My question is what is a proper C# type to a "ref object" that
is being marshalled to the type (signed long int *) in a dll written
in C.

"Greg Ewing [MVP]" <gewing@_NO_SPAM_citidc.com> wrote in message news:<e0*************@TK2MSFTNGP10.phx.gbl>...
Alfred, have you tried just passing null like this? I've never used that
dll myself but sounds like that might work for you.

IntPtr[] key=new IntPtr[21];
nav.NextKey(hTableRef, null);

--
Greg Ewing [MVP]
http://www.citidc.com/

Nov 15 '05 #3
I also tried to add a reference to the CFRONT.DLL in a managed C++
ClassLibrary Project and then I get the following declaration:

object __gc *NextKey(int, object __gc * __gc *)

If I now use this method as:

Object __gc *key=Navision->NextKey(TableHandle,NULL);

I get An unhandled exception of type 'System.ExecutionEngineException'
occurred in mscorlib.dll. Probably because the DLL doesn't like the
NULL. So, I tried the following code:

Object __gc * __gc *keyPtr;
(*keyPtr)=NULL;
Object __gc *key=Navision->NextKey(TableHandle,keyPtr);

Again I get an exception:

Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object.
at CPPNavLib.Class1.GetKey(Int32 TableHandle, Int32 KeyNo) in
c:\alfred\vstudio\wstest\cppnavlib\cppnavlib.cpp:l ine 47
at WinNavAccessApp.Form1..ctor() in
c:\alfred\vstudio\wstest\winnavaccessapp\form1.cs: line 91
at WinNavAccessApp.Form1.Main() in
c:\alfred\vstudio\wstest\winnavaccessapp\form1.cs: line 152
The program '[2928] WinNavAccessApp.exe' has exited with code 0 (0x0).

Isn't there someone out there that can help me?
Nov 15 '05 #4
Alfred, how about this:

Object o = null;
nav.NextKey(hTableRef, ref o);

--
Greg Ewing [MVP]
http://www.citidc.com/


"Alfred B. Thordarson" <at*********@landsteinar.je> wrote in message
news:79**************************@posting.google.c om...
No I haven't; because you can't pass a null to a ref parameter. A ref
parameter requires the caller to pass a valid object of the proper
type. My question is what is a proper C# type to a "ref object" that
is being marshalled to the type (signed long int *) in a dll written
in C.

"Greg Ewing [MVP]" <gewing@_NO_SPAM_citidc.com> wrote in message

news:<e0*************@TK2MSFTNGP10.phx.gbl>...
Alfred, have you tried just passing null like this? I've never used that dll myself but sounds like that might work for you.

IntPtr[] key=new IntPtr[21];
nav.NextKey(hTableRef, null);

--
Greg Ewing [MVP]
http://www.citidc.com/

Nov 15 '05 #5
Hi Greg.

You wrote:
Object o = null;
nav.NextKey(hTableRef, ref o);
Unfortunatelly you can not send in a ref to null - it compiles but
gives a runtime exception:

An unhandled exception of type 'System.NullReferenceException'
occurred in mscorlib.dll
Additional information: Object reference
not set to an instance of an object.

-Alfred

"Greg Ewing [MVP]" <gewing@_NO_SPAM_citidc.com> wrote in message news:<eb**************@TK2MSFTNGP11.phx.gbl>... Alfred, how about this:

Object o = null;
nav.NextKey(hTableRef, ref o);

--
Greg Ewing [MVP]
http://www.citidc.com/


"Alfred B. Thordarson" <at*********@landsteinar.je> wrote in message
news:79**************************@posting.google.c om...
No I haven't; because you can't pass a null to a ref parameter. A ref
parameter requires the caller to pass a valid object of the proper
type. My question is what is a proper C# type to a "ref object" that
is being marshalled to the type (signed long int *) in a dll written
in C.

"Greg Ewing [MVP]" <gewing@_NO_SPAM_citidc.com> wrote in message

news:<e0*************@TK2MSFTNGP10.phx.gbl>...
Alfred, have you tried just passing null like this? I've never used that dll myself but sounds like that might work for you.

IntPtr[] key=new IntPtr[21];
nav.NextKey(hTableRef, null);

--
Greg Ewing [MVP]
http://www.citidc.com/

Nov 15 '05 #6
Alfred, you can definitely send a null object as a ref. That error sounds
like the NextKey function isn't checking to make sure the object isn't null
before accessing it. Are you sure you are supposed to pass null as the
second parm?

Here's some code from a simple windows form which demonstrates that this is
possible.

private void Form1_Load(object sender, System.EventArgs e)
{
object o = null;
Test(ref o);
}
private void Test(ref object o)
{
if (o == null)
MessageBox.Show("o was null");
else
MessageBox.Show("o was not null");
}

--
Greg Ewing [MVP]
http://www.citidc.com/

"Alfred B. Thordarson" <at*********@landsteinar.je> wrote in message
news:79*************************@posting.google.co m...
Hi Greg.

You wrote:
Object o = null;
nav.NextKey(hTableRef, ref o);


Unfortunatelly you can not send in a ref to null - it compiles but
gives a runtime exception:

An unhandled exception of type 'System.NullReferenceException'
occurred in mscorlib.dll
Additional information: Object reference
not set to an instance of an object.

-Alfred

"Greg Ewing [MVP]" <gewing@_NO_SPAM_citidc.com> wrote in message

news:<eb**************@TK2MSFTNGP11.phx.gbl>...
Alfred, how about this:

Object o = null;
nav.NextKey(hTableRef, ref o);

--
Greg Ewing [MVP]
http://www.citidc.com/


"Alfred B. Thordarson" <at*********@landsteinar.je> wrote in message
news:79**************************@posting.google.c om...
No I haven't; because you can't pass a null to a ref parameter. A ref
parameter requires the caller to pass a valid object of the proper
type. My question is what is a proper C# type to a "ref object" that
is being marshalled to the type (signed long int *) in a dll written
in C.

"Greg Ewing [MVP]" <gewing@_NO_SPAM_citidc.com> wrote in message

news:<e0*************@TK2MSFTNGP10.phx.gbl>...
> Alfred, have you tried just passing null like this? I've never used

that
> dll myself but sounds like that might work for you.
>
> IntPtr[] key=new IntPtr[21];
> nav.NextKey(hTableRef, null);
>
> --
> Greg Ewing [MVP]
> http://www.citidc.com/

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Amy Tseng | last post by:
Hi, I am having a problem accessing SQL Server 2000 via UNIX. I am accessing SQL Server 2000 from Solaris using Sybase Open Client (CT-Lib). Here is the error message: CT-LIBRARY error:...
5
by: Sandeep | last post by:
Hi, In the following code, I wonder how a private member of the class is being accessed. The code compiles well in Visual Studio 6.0. class Sample { private: int x; public:
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
3
by: prodirect | last post by:
Hi all, I hope someone can help me. I've recently created a database and wanted to put it up on an ftp sight so that multiple people could access the same tables at the same time from different...
47
by: fb | last post by:
Hi Everyone. Thanks for the help with the qudratic equation problem...I didn't think about actually doing the math...whoops. Anyway... I'm having some trouble getting the following program to...
3
by: AdamM | last post by:
Hi all, When I run my VbScript, I get the error: "ActiveX component can't create object: 'getobject'. Error 800A01AD". Any ideas what I did wrong? Here's my VBScript: dim o set...
1
by: Eirik Brattbakk | last post by:
Hi I have some problems accessing a soap service made in c# using an ATL/MFC client over SSL. I have tried both CSoapMSXMLInetClient and CSoapWininetClient as template arguments with my stub...
1
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
3
by: niju | last post by:
Hi there, I have three web pages (A,B,C). I need to prevent users accessing page B and C without accessing A. What would be the best way to achieve this rule? Many Thanks Niju
5
by: Daniel Corbett | last post by:
I am trying to save a file dynamically created in a webpage. I get the following headers, but cannot figure out how to save the attachment. I am basically trying to replicate what internet...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.