call C function with double pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher Sin

    #1

    call C function with double pointer

    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(dlle xport) * __stdcall
    uni_open_sessio n (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("clir ts32.dll", CharSet=CharSet .Ansi)]
    public static extern IntPtr uni_open_sessio n(String args,
    ref IntPtr psession) ;

    This works in some cases, but provoque an
    NullPointerExce ption 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_sessio n Lib "clirts32.d ll"
    (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_op en_session(args , ref
    m_session) ;

    The VB6 example code is

    Dim session As Long ' Session-Handle
    Dim result As Long
    result = uni_open_sessio n(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.

Working...