|
-
Aug 6th, 2006, 08:45 AM
#1
Thread Starter
Junior Member
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:
Declare Function GX_GetDTMFKey Lib "GxVoice.dll" (ByVal ChannelNo As Integer, ByVal DTMFCount As Integer, ByRef DTMFString As Byte) As Integer
...
Dim DtmfBuffer(10) As Byte
Dim itemp As Integer
Dim ChannelNo As Integer
ChannelNo = 5
itemp = GX_GetDTMFKey(ChannelNo, 1, DtmfBuffer(0))
Works great.
In C# I try
VB Code:
[DllImport("GxVoice.dll", CharSet = CharSet.Auto)]
public extern static ushort GX_GetDTMFKey(ushort ChannelNo, ushort DTMFCount, char[] DTMFKey);
...
char[] DTMFKey = new char[1];
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.
-
Aug 6th, 2006, 08:57 AM
#2
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]);
-
Aug 6th, 2006, 09:10 AM
#3
Thread Starter
Junior Member
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.
-
Aug 6th, 2006, 09:29 AM
#4
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.
-
Aug 8th, 2006, 08:19 AM
#5
Fanatic Member
Re: How to call this legacy function in C#?
How come you are using ushort data types in place of integers?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|