Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7829593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:50:23+00:00 2026-06-02T10:50:23+00:00

I am looking at a sample project from sourceforge for linking to a TSAPI

  • 0

I am looking at a sample project from sourceforge for linking to a TSAPI (not TAPI) telephone system – http://tsapi.sourceforge.net/ .

My development environment is 32bit Windows XP and the project is set to target x86.

This works fine as provided to run against .Net 2 but I need to run against .Net 4. When I change the framework and run the 1st function returns -1 indicating failure.

The function definition is:

[DllImport("csta32.dll")]
public static extern int acsOpenStream(ref UInt32 acsHandle, int invokeIDType, UInt32 invokeID, int streamType, char[] serverID, char[] loginID, char[] passwd, char[] applicationName, int acsLevelReq, char[] apiVer, ushort sendQSize, ushort sendExtraBufs, ushort recvQSize, ushort recvExtraBufs, ref PrivateData_t priv);

The c# code (extracted from sample project) for calling this function is:

    // The public method to open the ACS stream
    public bool open(string strLoginId, string strPasswd, string strServerId)
    {
        // Convert the parameters to character arrays
        char[] serverId = strServerId.ToCharArray();
        char[] loginId = strLoginId.ToCharArray();
        char[] passwd = strPasswd.ToCharArray();

        // Define the initial set of variables used for opening the ACS Stream
        int invokeIdType = 1;
        UInt32 invokeId = 0;
        int streamType = 1;
        char[] appName = "Mojo".ToCharArray();
        int acsLevelReq = 1;
        char[] apiVer = "TS1-2".ToCharArray();
        ushort sendQSize = 0;
        ushort sendExtraBufs = 0;
        ushort recvQSize = 0;
        ushort recvExtraBufs = 0;

        // Define the mandatory (but unused) private data structure
        Csta.PrivateData_t privData = new Csta.PrivateData_t();
        privData.vendor = "MERLIN                          ".ToCharArray();
        privData.length = 4;
        privData.data = "N".ToCharArray();

        // Define the event buffer pointer that gets data back from the TServer
        ushort numEvents = 0;
        Csta.EventBuf_t eventBuf = new Csta.EventBuf_t();
        ushort eventBufSize = (ushort)Csta.CSTA_MAX_HEAP;

        // Open the ACS stream
        try
        {
            int openStream = Csta.acsOpenStream(ref acsHandle, invokeIdType, invokeId, streamType, serverId, loginId, passwd, appName, acsLevelReq, apiVer, sendQSize, sendExtraBufs, recvQSize, recvExtraBufs, ref privData);

A C++ sample application is also provided in which the function call is:

m_nRetCode = acsOpenStream(&m_lAcsHandle            // Handle for ACS Stream 
    , APP_GEN_ID            // APP_GEN_ID indicates Application   generated invokeID's
    , (InvokeID_t)m_ulInvokeID  // By default 1
    , ST_CSTA
    , (ServerID_t *)(serverID)  // AE Server Name
    , (LoginID_t *)(loginID)    // CTI LoginID
    , (Passwd_t *)(password)  // CTI LoginID password
    , (AppName_t *)"TSAPI_AgentView"
    , ACS_LEVEL1
    , (Version_t *) "TS1-2" // private Data version in use 8 in our case
    , 10
    , 5 
    , 50
    , 5
    , (PrivateData_t *)&m_stPrivateData); // private Data.

If I change the DLLImport to

[DllImport("csta32.dll", CallingConvention=CallingConvention.Cdecl)]
public static extern int acsOpenStream(ref UInt32 acsHandle, int invokeIDType, UInt32 invokeID, int streamType, char[] serverID, char[] loginID, char[] passwd, char[] applicationName, int acsLevelReq, char[] apiVer, ushort sendQSize, ushort sendExtraBufs, ushort recvQSize, ushort recvExtraBufs, ref PrivateData_t priv);

I get the runtime error

PInvokeStackImbalance was detected
Message: A call to PInvoke function ‘Mojo!Csta::acsOpenStream’ has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

Avaya do not provide the header file – the documentation indicates the function definition to be:

RetCode_t acsOpenStream(
ACSHandle_t *acsHandle, /* RETURN */
InvokeIDType_t invokeIDType, /* INPUT */
InvokeID_t invokeID, /* INPUT */
StreamType_t streamType, /* INPUT */
ServerID_t *serverID, /* INPUT */
LoginID_t *loginID, /* INPUT */
Passwd_t *passwd, /* INPUT */
AppName_t *applicationName, /* INPUT */
Level_t acsLevelReq /* INPUT */
Version_t *apiVer, /* INPUT */
unsigned short sendQSize, /* INPUT */
unsigned short sendExtraBufs, /* INPUT */
unsigned short recvQSize, /* INPUT */
unsigned short recvExtraBufs /* INPUT */
PrivateData_t *privateData); /* INPUT */
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:50:25+00:00Added an answer on June 2, 2026 at 10:50 am

    The string parameters that you declared as char[] were always wrong. I guess you got away with that by chance in earlier .net versions.

    The C++ code declares these parameters as char*, i.e. pointer to null terminated character array. The correct way to declare these parameters in your C# code is as string. The p/invoke marshaller will take care of turning your C# strings into C strings and you can remove all the spurious ToCharArray() code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To all, I was looking at the sample project from http://iphoneonrails.com/ and I saw
I'm looking at Haacks article here - http://haacked.com/archive/2009/07/31/single-project-areas.aspx When I download the sample I
I was looking at some same code (a sample MS Visual Studio C++ project)
I am looking to try out clutter (http://www.clutter-project.org) on an OSX machine (10.6). I
I'm looking to see if there is a sample project, tutorial, contrib branch or
I am looking at a project where we send information from a peripheral device
As described here http://www.ddj.com/cpp/184401688 I do not have time to write this from scratch.
When looking at sample attached properties and behaviors, I've seen a mishmash of uses
I am looking for sample code or documentation on how to use client side
I'm having trouble figuring out how to correctly merge rows. Looking at the sample

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.