views:

718

answers:

4

Trying to use a call recording API using sockets. We have the API documentation but the samples are all in C++.

How would I declare the following in vb.net or c#???

#define SIF_GENERAL 0x08000000
#define SIF_CONFIGURATION 0x08010000
#define SIF_ARCHIVE 0x08020000
#define SIF_SEARCH 0x08030000
#define SIF_REPLAY 0x08040000
#define SIF_STATISTICS 0x08050000
#define SIF_ENGINEER 0x08060000

Many Thanks

Forgot to add the following from the documentation;

Message identifiers are unsigned 32-bit values (ULONG).

Does this change the answers already listed??

+4  A: 

VB.Net

Module Constants
  Public Const SIF_GENERAL as Integer =&H08000000
  Public Const SIF_CONFIGURATION As Integer = &H08010000
  Public Const SIF_ARCHIVE As Integer = &H08020000
  Public Const SIF_SEARCH As Integer = &H08030000
  Public Const SIF_REPLAY As Integer = &H08040000
  Public Const SIF_STATISTICS As Integer = &h08050000
  Public Const SIF_ENGINEER As Integer = &h08060000

End Module

C#

public static class Constants {
  public const int SIF_GENERAL =0x08000000;
  public const int SIF_CONFIGURATION = 0x08010000;
  public const int SIF_ARCHIVE = 0x08020000;
  public const int SIF_SEARCH = 0x08030000;
  public const int SIF_REPLAY = 0x08040000;
  public const int SIF_STATISTICS = 0x08050000;
  public const int SIF_ENGINEER = 0x08060000;
}
JaredPar
+1  A: 

C++ ULONG is a 32bit unsigned integer type. In this case your constants don't need to be unsigned so just use int in C# or Integer in VB.Net.

VB.Net

Public Const SIF_GENERAL as Integer = &H08000000

C#

public const int SIF_GENERAL = 0x08000000;

Do not use a 64bit long data type since the data size will be incorrect for your API calls.

Stephen Martin
+1  A: 

You can make the values look more .NETty by using enums:

//C#
public enum SIF : uint
{
    SIF_GENERAL = 0x08000000,
    SIF_CONFIGURATION = 0x08010000,
    SIF_ARCHIVE = 0x08020000,
    SIF_SEARCH = 0x08030000,
    SIF_REPLAY = 0x08040000,
    SIF_STATISTICS = 0x08050000,
    SIF_ENGINEER = 0x08060000,
}

or

'VB.NET
Public Enum SIF As UInt32
    SIF_GENERAL = &H08000000
    SIF_CONFIGURATION = &H08010000
    SIF_ARCHIVE = &H08020000
    SIF_SEARCH = &H08030000
    SIF_REPLAY = &H08040000
    SIF_STATISTICS = &H08050000
    SIF_ENGINEER = &H08060000
End Enum

This way, you get the discoverability and type safety of enums (except where you pass them through your interface, where you'll need to cast them).

You could even increase the .NET look by renaming them - for example SIF.SIF_GENERAL could become SIF.General, although the advantage there is pretty small.

Ant
A: 

If you have constants >= 0x8000000, than you can define them this way:

class Test
{
   public const int AllBits = unchecked((int)0xFFFFFFFF);
   public const int HighBit = unchecked((int)0x80000000);
}

http://msdn.microsoft.com/en-us/library/aa691349(VS.71).aspx

alex2k8