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.Nex tKey(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=(obje ct)key;
nav.NextKey(hTa bleRef,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 .InteropService s.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.RuntimeT ype.InvokeDispM ethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[]
byrefModifiers, Int32 culture, String[] namedParameters )
at System.RuntimeT ype.InvokeMembe r(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifi er[] modifiers, CultureInfo culture, String[]
namedParameters )
at System.RuntimeT ype.ForwardCall ToInvokeMember( String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes,
MessageData& msgData)
at CFRONTLib.CFRON TClass.NextKey( Int32 hTable, Object& Key)
at WinNavAccessApp .Form1..ctor() in
c:\alfred\vstud io\wstest\winna vaccessapp\form 1.cs:line 90
at WinNavAccessApp .Form1.Main() in
c:\alfred\vstud io\wstest\winna vaccessapp\form 1.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. 6 5196
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(hTa bleRef, null);
--
Greg Ewing [MVP] http://www.citidc.com/
"Alfred B. Thordarson" <at*********@la ndsteinar.je> wrote in message
news:79******** *************** ***@posting.goo gle.com... 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.Nex tKey(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=(obje ct)key; nav.NextKey(hTa bleRef,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 .InteropService s.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.RuntimeT ype.InvokeDispM ethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters ) at System.RuntimeT ype.InvokeMembe r(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifi er[] modifiers, CultureInfo culture, String[] namedParameters ) at System.RuntimeT ype.ForwardCall ToInvokeMember( String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) at CFRONTLib.CFRON TClass.NextKey( Int32 hTable, Object& Key) at WinNavAccessApp .Form1..ctor() in c:\alfred\vstud io\wstest\winna vaccessapp\form 1.cs:line 90 at WinNavAccessApp .Form1.Main() in c:\alfred\vstud io\wstest\winna vaccessapp\form 1.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.
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_SPA M_citidc.com> wrote in message news:<e0******* ******@TK2MSFTN GP10.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(hTa bleRef, null);
-- Greg Ewing [MVP] http://www.citidc.com/
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(TableH andle,NULL);
I get An unhandled exception of type 'System.Executi onEngineExcepti on'
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(TableH andle,keyPtr);
Again I get an exception:
Unhandled Exception: System.NullRefe renceException: Object reference
not set to an instance of an object.
at CPPNavLib.Class 1.GetKey(Int32 TableHandle, Int32 KeyNo) in
c:\alfred\vstud io\wstest\cppna vlib\cppnavlib. cpp:line 47
at WinNavAccessApp .Form1..ctor() in
c:\alfred\vstud io\wstest\winna vaccessapp\form 1.cs:line 91
at WinNavAccessApp .Form1.Main() in
c:\alfred\vstud io\wstest\winna vaccessapp\form 1.cs:line 152
The program '[2928] WinNavAccessApp .exe' has exited with code 0 (0x0).
Isn't there someone out there that can help me?
Alfred, how about this:
Object o = null;
nav.NextKey(hTa bleRef, ref o);
--
Greg Ewing [MVP] http://www.citidc.com/
"Alfred B. Thordarson" <at*********@la ndsteinar.je> wrote in message
news:79******** *************** ***@posting.goo gle.com... 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_SPA M_citidc.com> wrote in message
news:<e0******* ******@TK2MSFTN GP10.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(hTa bleRef, null);
-- Greg Ewing [MVP] http://www.citidc.com/
Hi Greg.
You wrote: Object o = null; nav.NextKey(hTa bleRef, 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.NullRef erenceException '
occurred in mscorlib.dll
Additional information: Object reference
not set to an instance of an object.
-Alfred
"Greg Ewing [MVP]" <gewing@_NO_SPA M_citidc.com> wrote in message news:<eb******* *******@TK2MSFT NGP11.phx.gbl>. .. Alfred, how about this:
Object o = null; nav.NextKey(hTa bleRef, ref o);
-- Greg Ewing [MVP] http://www.citidc.com/
"Alfred B. Thordarson" <at*********@la ndsteinar.je> wrote in message news:79******** *************** ***@posting.goo gle.com... 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_SPA M_citidc.com> wrote in message news:<e0******* ******@TK2MSFTN GP10.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(hTa bleRef, null);
-- Greg Ewing [MVP] http://www.citidc.com/
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(obje ct sender, System.EventArg s 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*********@la ndsteinar.je> wrote in message
news:79******** *************** **@posting.goog le.com... Hi Greg.
You wrote: Object o = null; nav.NextKey(hTa bleRef, 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.NullRef erenceException ' occurred in mscorlib.dll Additional information: Object reference not set to an instance of an object.
-Alfred
"Greg Ewing [MVP]" <gewing@_NO_SPA M_citidc.com> wrote in message
news:<eb******* *******@TK2MSFT NGP11.phx.gbl>. .. Alfred, how about this:
Object o = null; nav.NextKey(hTa bleRef, ref o);
-- Greg Ewing [MVP] http://www.citidc.com/
"Alfred B. Thordarson" <at*********@la ndsteinar.je> wrote in message news:79******** *************** ***@posting.goo gle.com... 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_SPA M_citidc.com> wrote in message news:<e0******* ******@TK2MSFTN GP10.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(hTa bleRef, null); > > -- > Greg Ewing [MVP] > http://www.citidc.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
ct_connect(): network packet layer: internal net library
error: Net-Library operation terminated due to disconnect
|
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:
|
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 called "form1", and I have selects called "PORTA", "PORTB" ...
etc...
|
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 geographical locations. I have been
completely unsucessful in acheiving this goal so far however.
Things I have tried:
Create a shortcut to ftp sight via browser then tried to map local drive to
|
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 work. I want to
output a bit pattern from base 10 input. All I get is a zero after the
input...I've looked over the code but can't see the problem...any ideas?
/* display the bit pattern corresponding to
a signed decimal integer */
| |
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 o=getobject(,"ConsoleApplication2.Program")
msgbox o.TestString
|
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 class.
The service is returning with the error code: -2147467259. I have not
succeeded to find any additional information about the error. The
"SoapFault" method seems to return only a bunch of question marks.
|
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 elements and would like to seek a
solution for this.
I had looked through several articles for accessing programatically-created
dynamic elements such as:
1)
|
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
|
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 explorer would do in this case.
The headers I am getting are:
Headers {Content-Disposition: attachment; filename="dynamic_file.mdb"
Connection: close
Cache-Control: private
Content-Type: application/octet-stream
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |