PDA

View Full Version : SDK Error Numbers


NoLoComprendo
03-06-2004, 19:48
Is there a list available somewhere of the error numbers for the functions/procedures available in the SDK? In the Delphi import file (TsRemoteImport.pas) all I find is "Result: 0 = OK, else the error number"! Is there an official list available (or one that could be made available) or has someone mapped them out?

Thanks in advance.

pbarrette
04-06-2004, 07:19
Hi NoLo,

I'm not sure about error numbers. When I call a function it almost always returns as good. If it's a non-zero, then you should be able to call "tsrGetLastError" to get an English translation of the error.

To be honest, I'm not entirely sure if there are error numbers since I don't really look at the result var. I just check to see if it is zero and if not I can call tsrGetLastError to find out what went wrong.

pb

NoLoComprendo
04-06-2004, 14:18
The trouble is, I can't call tsrGetLastError! I reckon the problem is in the way I'm Marshalling the strings across and therefore I can't get an error message back!

Here's the API call I'm using:


Public Declare Auto Sub tsrGetLastError Lib "TSRemote" (<MarshalAs(UnmanagedType.VBByRefStr, SizeConst:=1024)> ByRef pchBuffer As String, ByVal BufferLength As Int32)


And the way I'm calling it in my code:


If Not intCheck = 0 Then
'Error
Dim strString As String
objTSRemoteAPI.tsrGetLastError(strString, 1024)
Exit Function
End If


If I put a breakpoint over 'Exit Function' and check the contents of strString, it is always null/'Nothing' in VB. I can't for the life of me work out why - I'm not getting any execution or marshalling errors being thrown, but something must be wrong!

pbarrette
07-06-2004, 06:13
Hi NoLoCo,

Try this:

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace TestPad
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
int iResult;
StringBuilder aErrText = new StringBuilder(1024);
int iBLen = 1024;

//Make an array to hold the speaker ID's
Int32[] aIDs = new Int32[1024];
int iRecords = 1024;

//Get speaker ID#'s.
iResult = TSControlApi.tsrGetSpeakers(aIDs, ref iRecords);

//Setup array for names and ID's.
string[,] aNameList = new string[iRecords,2];

//If the call succeeded..
if(iResult == 0)
{
Console.WriteLine("Success\r\n");
}
else
{
TSControlApi.tsrGetLastError(aErrText, iBLen);
Console.WriteLine(aErrText);
}
}
}

//Our P/Invoke code
class TSControlApi
{
[DllImport("TSRemote")]
public static extern int tsrGetSpeakers(Int32[] aIDs, ref int iRecords);

[DllImport("TSRemote")]
public static extern void tsrGetLastError(StringBuilder aErrorText, Int32 iBufLen);
}

}


Works for me,

pb

NoLoComprendo
07-06-2004, 19:09
Of course! That makes sense! The tsrGetLastError procedure changes the string by reference, only strings in .NET are immutable :). Stringbuilder is an array of characters and therefore can be changed by reference... plus you can set a length-limit!

Thanks pbarratte, you are a life saver :).

EDIT:

Oddly enough, the Stringbuilder idea didn't work for me... exactly. Passing it by value filled it with junk data, but data nevertheless. I think it was just that the wrong encoding was being used. Therefore, I swapped the stringbuilder for a byte array, and used the GetString method of System.Text.ASCIIEncoding to convert the byte array into a string. It worked beautifully :).

FURTHER EDIT:

This works for the string required in tsrGetLastError, but not in any of the others! I'm trying to call tsrGetChannelInfoByName and the first parameter is a string. Neither the byte array trick nor the stringbuilder trick work - I'm simply don't seem to be able to pass a value of a string (which it needs according to the delphi documentation). I can pass things ByRef, but that leads to the 'Channel Not Found' error! Any ideas?

WalkaboutTigger
08-06-2004, 04:57
Is this (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp) what you're looking for? :rolleyes:

pbarrette
15-06-2004, 22:41
Hi NoLo,

Set the CharSet to ANSI in the P/Invoke structure:
class TSControlApi
{
[DllImport("TSRemote", CharSet=CharSet.Ansi)]
public static extern int tsrConnect(String sUrl);
}

class TestPad
{
[STAThread]
static void Main(string[] args)
{
string sSvrUrl = "localhost:8767";

int iResult = TSControlApi.tsrConnect(sSvrUrl);

Console.WriteLine(iResult.ToString());
}
}

This works for me. I would have tested tsrGetChannelInfoByName as well, but I really didn't feel like recreating the structs needed to get valid return data.

pb