473,408 Members | 2,813 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,408 software developers and data experts.

Call C functions in C#

[repost, nobody have seen this message ?]

Hi,

First, if I am on a wrong group, please tell me,
therefore, i think this one is correct.

Second, please ignore my poor English speaking.

I have to write a c# wrapper to a C library.
This is OK, but I have difficulties with some functions
that deals with double indirections.

The C function is
ectern "C" {
UNIRESULT_S __declspec(dllexport) * __stdcall
uni_open_session (const char * args, UNISESSION_S * *
psession);
}

UNIRESULT_S and UNISESSION_S just are structures (but with
incomplete definition in headers).

This function allocate ressources and retruned this by the
psession pointer.
The returned value is a pointer on a structure.

I have tried this :

[DllImport("clirts32.dll", CharSet=CharSet.Ansi)]
public static extern IntPtr uni_open_session(String args,
ref IntPtr psession) ;

This works in some cases, but provoque an
NullPointerException in others.
(the case where it is works is console application
launcher, where with a web application aspnet, it is not).

The C function is part of a dll, given by a vendor.
He gave me also with .h include files, an vb6 example file.

This last file contains this :

Declare Function uni_open_session Lib "clirts32.dll"
(ByVal args As String, psession As Long) As Long

What is the equivalent in C# ?

How to use it ?

In my C# code, i use C function like this :

string args = "servername etc." ;
IntPtr m_session = new IntPtr(0) ;
IntPtr hresult = Clirts32.uni_open_session(args, ref
m_session) ;

The VB6 example code is

Dim session As Long ' Session-Handle
Dim result As Long
result = uni_open_session(arg_str, session)

Is someone have any idea ?

Is my code correct, and the probleme came from aspnet
references dlls ?
Or is my code incorrect ?

Thank you.
Nov 15 '05 #1
3 2881
Hi,

I believe you might get more help in the
microsoft.public.dotnet.framework.interop newsgroup.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Christopher Sin" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...
[repost, nobody have seen this message ?]

Hi,

First, if I am on a wrong group, please tell me,
therefore, i think this one is correct.

Second, please ignore my poor English speaking.

I have to write a c# wrapper to a C library.
This is OK, but I have difficulties with some functions
that deals with double indirections.

The C function is
ectern "C" {
UNIRESULT_S __declspec(dllexport) * __stdcall
uni_open_session (const char * args, UNISESSION_S * *
psession);
}

UNIRESULT_S and UNISESSION_S just are structures (but with
incomplete definition in headers).

This function allocate ressources and retruned this by the
psession pointer.
The returned value is a pointer on a structure.

I have tried this :

[DllImport("clirts32.dll", CharSet=CharSet.Ansi)]
public static extern IntPtr uni_open_session(String args,
ref IntPtr psession) ;

This works in some cases, but provoque an
NullPointerException in others.
(the case where it is works is console application
launcher, where with a web application aspnet, it is not).

The C function is part of a dll, given by a vendor.
He gave me also with .h include files, an vb6 example file.

This last file contains this :

Declare Function uni_open_session Lib "clirts32.dll"
(ByVal args As String, psession As Long) As Long

What is the equivalent in C# ?

How to use it ?

In my C# code, i use C function like this :

string args = "servername etc." ;
IntPtr m_session = new IntPtr(0) ;
IntPtr hresult = Clirts32.uni_open_session(args, ref
m_session) ;

The VB6 example code is

Dim session As Long ' Session-Handle
Dim result As Long
result = uni_open_session(arg_str, session)

Is someone have any idea ?

Is my code correct, and the probleme came from aspnet
references dlls ?
Or is my code incorrect ?

Thank you.


Nov 15 '05 #2
Ok, thank you for your reply.
I will post there.
-----Original Message-----
Hi,

I believe you might get more help in the
microsoft.public.dotnet.framework.interop newsgroup.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Christopher Sin" <an*******@discussions.microsoft.com> wrote in messagenews:06****************************@phx.gbl...
[repost, nobody have seen this message ?]

Hi,

First, if I am on a wrong group, please tell me,
therefore, i think this one is correct.

Second, please ignore my poor English speaking.

I have to write a c# wrapper to a C library.
This is OK, but I have difficulties with some functions
that deals with double indirections.

The C function is
ectern "C" {
UNIRESULT_S __declspec(dllexport) * __stdcall
uni_open_session (const char * args, UNISESSION_S * *
psession);
}

UNIRESULT_S and UNISESSION_S just are structures (but with incomplete definition in headers).

This function allocate ressources and retruned this by the psession pointer.
The returned value is a pointer on a structure.

I have tried this :

[DllImport("clirts32.dll", CharSet=CharSet.Ansi)]
public static extern IntPtr uni_open_session(String args, ref IntPtr psession) ;

This works in some cases, but provoque an
NullPointerException in others.
(the case where it is works is console application
launcher, where with a web application aspnet, it is not).
The C function is part of a dll, given by a vendor.
He gave me also with .h include files, an vb6 example file.
This last file contains this :

Declare Function uni_open_session Lib "clirts32.dll"
(ByVal args As String, psession As Long) As Long

What is the equivalent in C# ?

How to use it ?

In my C# code, i use C function like this :

string args = "servername etc." ;
IntPtr m_session = new IntPtr(0) ;
IntPtr hresult = Clirts32.uni_open_session(args, ref
m_session) ;

The VB6 example code is

Dim session As Long ' Session-Handle
Dim result As Long
result = uni_open_session(arg_str, session)

Is someone have any idea ?

Is my code correct, and the probleme came from aspnet
references dlls ?
Or is my code incorrect ?

Thank you.


.

Nov 15 '05 #3
Christopher,

From the VB code, it actually looks like you want this:

[DllImport("clirts32.dll", CharSet=CharSet.Ansi)]
public static extern IntPtr uni_open_session(String args, IntPtr psession);

And then you pass in the psession variable as you would normally. You
then call it like this:

IntPtr result = uni_open_session(arg_str, IntPtr.Zero);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Christopher Sin" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...
[repost, nobody have seen this message ?]

Hi,

First, if I am on a wrong group, please tell me,
therefore, i think this one is correct.

Second, please ignore my poor English speaking.

I have to write a c# wrapper to a C library.
This is OK, but I have difficulties with some functions
that deals with double indirections.

The C function is
ectern "C" {
UNIRESULT_S __declspec(dllexport) * __stdcall
uni_open_session (const char * args, UNISESSION_S * *
psession);
}

UNIRESULT_S and UNISESSION_S just are structures (but with
incomplete definition in headers).

This function allocate ressources and retruned this by the
psession pointer.
The returned value is a pointer on a structure.

I have tried this :

[DllImport("clirts32.dll", CharSet=CharSet.Ansi)]
public static extern IntPtr uni_open_session(String args,
ref IntPtr psession) ;

This works in some cases, but provoque an
NullPointerException in others.
(the case where it is works is console application
launcher, where with a web application aspnet, it is not).

The C function is part of a dll, given by a vendor.
He gave me also with .h include files, an vb6 example file.

This last file contains this :

Declare Function uni_open_session Lib "clirts32.dll"
(ByVal args As String, psession As Long) As Long

What is the equivalent in C# ?

How to use it ?

In my C# code, i use C function like this :

string args = "servername etc." ;
IntPtr m_session = new IntPtr(0) ;
IntPtr hresult = Clirts32.uni_open_session(args, ref
m_session) ;

The VB6 example code is

Dim session As Long ' Session-Handle
Dim result As Long
result = uni_open_session(arg_str, session)

Is someone have any idea ?

Is my code correct, and the probleme came from aspnet
references dlls ?
Or is my code incorrect ?

Thank you.

Nov 15 '05 #4

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

Similar topics

7
by: Bruce W...1 | last post by:
I'm a PHP newbie coming from experience with ASP.NET. I want to have a separate PHP file to support each HTML PHP page. This would be the equivalent of an ASP.NET code-behind file but using PHP....
2
by: Greg Chapman | last post by:
I am at my wit's end trying to get information out of Streamline.net's support dept about my problem. They reply quickly enough, but seem to try and give out the least possible amount of info each...
7
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
6
by: Philip Warner | last post by:
I have a set of classes: C (base) C1 (inherits C) C2 (inherits C) ... Cn (inherits C) (the C1..Cn also have subclasses, but thats not really relevant to the question)
46
by: Steven T. Hatton | last post by:
I just read §2.11.3 of D&E, and I have to say, I'm quite puzzled by what it says. http://java.sun.com/docs/books/tutorial/essential/concurrency/syncrgb.html <shrug> -- NOUN:1. Money or...
15
by: AmmarN | last post by:
Hi all, I have a c++ programme that intakes a binary file and performs various operations on it. I am not gonna get in to the details of the operations, currently i specify the order in which the...
5
by: GCRhoads | last post by:
I have some templated functions and I want to write a call wrapper class for it. I also want to pass the function object from this class to some functions that will then call the function...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
9
by: Andrew Poulos | last post by:
Say I have this: var foo = function(x, y) { return x + y; }; var bar = function(fname, param1, param2) { /* * how do I call the function "foo" * and pass parameters to it?
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: 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...
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
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,...

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.