Results 1 to 5 of 5

Thread: How to call this legacy function in C#?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    20

    How to call this legacy function in C#?

    Some kind person show me how to call this in C#?

    In VB6 I use:

    VB Code:
    1. Declare Function GX_GetDTMFKey Lib "GxVoice.dll" (ByVal ChannelNo As Integer, ByVal DTMFCount As Integer, ByRef DTMFString As Byte) As Integer
    2.  
    3. ...
    4. Dim DtmfBuffer(10) As Byte
    5. Dim itemp As Integer
    6. Dim ChannelNo As Integer
    7.  
    8. ChannelNo = 5
    9.  
    10. itemp = GX_GetDTMFKey(ChannelNo, 1, DtmfBuffer(0))

    Works great.

    In C# I try

    VB Code:
    1. [DllImport("GxVoice.dll", CharSet = CharSet.Auto)]
    2.   public extern static ushort GX_GetDTMFKey(ushort ChannelNo, ushort     DTMFCount, char[] DTMFKey);
    3.  
    4. ...
    5.  
    6. char[] DTMFKey = new char[1];
    7. ushort i = GxVoiceAPI.GX_GetDTMFKey(5, 1, DTMFKey);

    And i comes back with an error code.

    Something to do with passing DTMFKey by reference?

    The DLL is unmanaged legacy code.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to call this legacy function in C#?

    You're passing a Byte by reference in the first code snippet and it works so why do anything differently in the second?
    Code:
    [DllImport("GxVoice.dll", CharSet = CharSet.Auto)]
    public extern static short GX_GetDTMFKey(short ChannelNo, short DTMFCount, ref Byte DTMFBuffer);
    Code:
    byte[10] dtmfBuffer;
    short iTemp;
    short channelNo = 5;
    
    iTemp = GX_GetDTMFKey(channelNo, 1, ref dtmfBuffer[0]);
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    20

    Re: How to call this legacy function in C#?

    Code:
    byte[10] dtmfBuffer;
    Will not compile.

    I think you mean:

    Code:
    byte[] dtmfBuffer = new byte[10];
    Thanks but unfortunately did not work. Returns an error code (-1) shoudl return zero.

    I'm pretty sure

    Code:
    [DllImport("GxVoice.dll", CharSet = CharSet.Auto)]
      public extern static ushort GX_GetDTMFKey(ushort ChannelNo, ushort     DTMFCount, char[] DTMFKey);
    ... is okay as it is part of another project that was working fine - but the code that called it is no longer available.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to call this legacy function in C#?

    Yeah, sorry about the byte array. Still in VB mode there. From the VB6 declaration I would guess that the third argument is actually declared as a pointer. Given that C# supports pointers you could declare an unsafe code block and actually use a pointer. Apart from that I wouldn't like to suggest anything else without being able to test it, given that I would have thought my previous suggestion would have worked.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843

    Re: How to call this legacy function in C#?

    How come you are using ushort data types in place of integers?
    Merry Christmas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width