Typedef Declaration in VB


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Typedef Declaration in VB

  1. #1
    Join Date
    Nov 2004
    Posts
    9

    Unhappy Typedef Declaration in VB

    Hi all !
    I'm just about to use a DLL made in C++, I'll need some help to declare all "TypeDef" and functions in a vb fashion way.
    PLEASE GIVE EXPLANATIONS thankls

    The most important for now are the CONNECTION_ADDR type and the NetApiConnect method....

    Can you help me to understand how the sruct should be declared in VB, and also the method ?
    Here's how I declared the "API function in vb so far...

    Private Declare Function NetApiConnect Lib "NetApi" (IN CONNECTION_ADDR * prConnAddr,
    IN int nNumConnections
    ) As Long


    I'm now posting part of the .h file.

    typedef struct {
    CONNECTION_TYPE eType;
    union {
    SOCKET_ADDR rSocket;
    MODEM_ADDR rModem;
    COMM_PORT_ADDR rCommPort;
    GENERIC_ADDR rGeneric;
    };
    } CONNECTION_ADDR;


    typedef int (* LOG_CALLBACK)(
    IN int nRid,
    IN OB_LOG_ENTRY * prObLogEntry,
    IN unsigned long nCallbackParameter
    );

    typedef enum {
    SOCKET_TYPE,
    MODEM_TYPE,
    COMM_PORT_TYPE,
    UNKNOWN_CONN_TYPE,
    _LAST_CONN_TYPE
    } CONNECTION_TYPE;

    typedef struct {
    unsigned long ulIpAddress;
    char acHost[ MAX_HOST_NAME_LEN ];
    unsigned short nPort;
    } SOCKET_ADDR;

    typedef struct {
    char acCallString[64];
    } MODEM_ADDR;

    typedef struct {
    int nPort;
    } COMM_PORT_ADDR;

    typedef struct {
    char acData[ CONNECTION_ADDR_MIN_SIZE ];
    } GENERIC_ADDR;



    typedef struct _SESSION * SESSION_ID;
    typedef struct _REQUEST * REQUEST_ID;
    typedef int (* VIDEO_CALLBACK)(
    IN int nRid,
    IN OB_VIDEO * prObVideo,
    IN int nError,
    IN SESSION_ID hSessionId,
    IN REQUEST_ID hRequestId,
    IN unsigned long nCallbackParameter
    );
    typedef enum {
    SEEK_TIME_ABSOLUTE,
    SEEK_TIME_LIVE,
    SEEK_TIME_BEFORE,
    SEEK_TIME_AFTER,
    SEEK_NEXT,
    SEEK_PREV,
    SEEK_GET_TIME,
    SEEK_GET_TIME_AND_RID
    } SEEK_TYPE;

    #define PLAYBACK_REVERSE 0x01
    #define PLAYBACK_FRAME_CURRENT 0x02
    #define PLAYBACK_FRAME_ALL 0x04
    #define PLAYBACK_REAL_TIME 0x08
    #define PLAYBACK_NO_DROPS 0x10
    #define PLAYBACK_LIVE_MODE 0x20

    typedef enum {
    CFG_LIVE_MODE_QUALITY,
    CFG_VERSION,
    CFG_NO_SEEK_ON_CONNECT,
    } CONFIG_TYPE;

    typedef struct {
    char acVersion[64]; // Version label. May or may not be specified.
    // Empty string if unspecified.
    unsigned long nMajor;
    unsigned long nMinor;
    unsigned long nPatch;
    unsigned long nBuildNo;
    } VERSION_INFO;
    #undef DLL_DECLSPEC
    #ifdef NETAPI_EXPORTS
    #define DLL_DECLSPEC __declspec(dllexport)
    #else
    #define DLL_DECLSPEC __declspec(dllimport)
    #endif

    DLL_DECLSPEC int
    NetApiConnect(
    IN CONNECTION_ADDR * prConnAddr,
    IN int nNumConnections
    );

    DLL_DECLSPEC int
    NetApiDisconnect(
    );

    DLL_DECLSPEC int
    NetApiGetResources(
    OUT OB_RESOURCE ** pprResources,
    OUT int * pnNumResources
    );

    DLL_DECLSPEC int
    NetApiGetRid(
    IN int nUniqueId,
    IN RESOURCE_TYPE eType,
    IN int nParameter
    );

    DLL_DECLSPEC int
    NetApiGetObject(
    IN int nRid,
    IN RVCOBTYPE eObject,
    OUT void * pvObject,
    IN int nSize,
    OUT int * pnPercentRemaining
    );

    DLL_DECLSPEC int
    NetApiSetObject(
    IN int nRid,
    IN RVCOBTYPE eObject,
    IN void * pvObject,
    IN int nSize,
    OUT int * pnPercentRemaining
    );

    DLL_DECLSPEC int
    NetApiVideoPlay(
    IN int * pnRids,
    IN int nNumRids,
    IN int nMainVideoIndex,
    IN VIDEO_CALLBACK pCallback,
    IN unsigned long nCallbackParameter,
    IN int nFlags
    );

    DLL_DECLSPEC int
    NetApiVideoStop(
    );

    DLL_DECLSPEC int
    NetApiVideoSeek(
    IN OUT FILETIME * pnTime,
    IN SEEK_TYPE eSeekType,
    OUT BOOL * pbSeekHit
    );

    DLL_DECLSPEC int
    NetApiLogUpdateSection(
    IN LOG_TYPE eLog,
    IN int nFirstEntry,
    IN int nNumEntries,
    IN LOG_CALLBACK pCallback,
    IN unsigned long nCallbackParameter,
    IN int nFlags
    );

    DLL_DECLSPEC int
    NetApiLogGetSize(
    IN LOG_TYPE eLog
    );

    DLL_DECLSPEC void
    NetApiGetCfg(
    IN CONFIG_TYPE eConfigType,
    OUT void * pvConfigData,
    IN int nConfigSize
    );

    DLL_DECLSPEC void
    NetApiSetCfg(
    IN CONFIG_TYPE eConfigType,
    OUT void * pvConfigData,
    IN int nConfigSize
    );

    DLL_DECLSPEC int
    NetApiGetConnectionStatus(
    IN int nConnection,
    OUT int * pnLine,
    OUT char ** ppcFile,
    OUT int * pnExtendedError
    );

    DLL_DECLSPEC char *
    NetApiGetLastErrors(
    );

    /*
    * Undocumented function
    */
    DLL_DECLSPEC char *
    ErrString(
    IN int nErr
    );

    #ifdef __cplusplus
    }
    #endif


    #endif

  2. #2
    Join Date
    Feb 2004
    Location
    Colton, CA
    Posts
    550
    I'm not a big C programmer, but you'd normally do something like:

    Code:
    Public Declare Function FunctionName Lib "Library.dll" (ByVal Parameter1 As Integer, ByVal Parameter2 As Integer, ByVal bState As Integer) As Boolean
    ...inside a module.

    BTW - Remember INT in C is a 32-bit data type, where as in VB it's a 16-bit. Maybe you should use SHORT. Oh, and INT in VB is ALWAYS signed.

  3. #3
    Join Date
    Nov 2004
    Posts
    9
    Well thanks, but I allready know that, if you look at my original post, you'll see the following declaration.
    Private Declare Function NetApiConnect Lib "NetApi" (IN CONNECTION_ADDR * prConnAddr,
    IN int nNumConnections) As Long

    In fact, my post is more about arguments declaration of typedef type to be used by the NetApiConnect function.
    In C, it's defined as a typedef struct, and it uses "union", which I don't know how to translate in VB.

    Thanks for posting, you help stupid people like me !!!!
    Not stupid, but without some specific knowledge.

  4. #4
    Join Date
    Feb 2004
    Location
    Colton, CA
    Posts
    550
    My bad, i'll read the post properly next time.

  5. #5
    Join Date
    Dec 2005
    Location
    South of Nowhere, Maine
    Posts
    309
    A structure in C is a Type in VB.
    And an enum is till an enum.

    I don't know about the Union stuff though... If you can find it, Dan Appleman has a book out on translating C++ API's to VB Classic. Pretty good book...

  6. #6
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    A union says, "Depending on the value of the eType field, this block of memory can be either a SOCKET_ADDR, MODEM_ADDR, COM_PORT_ADDR or GENERIC_ADDR." The C compiler takes care of mapping the memory into the appropriate struct automatically.

    VB has no equivalent of a union, but you can simulate one by creating a Type consisting of an eType field and an array of bytes large enough to hold the largest struct. At runtime, read eType to determine what kind of data is in the byte array, the use the CopyMemory API to copy the bytes into a variable of the appropriate Type. You may find some of these discussions helpful: http://groups.google.com/groups/search?q=vb+union+type
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  7. #7
    Join Date
    Nov 2004
    Posts
    9

    Talking

    Well I do know it's always going to be a "SOCKET_TYPE" connection type.
    I've tried the following code, but get no connection to host....
    This doesn't work.
    ' MY FORM CODE....

    Private Sub Form_Load()
    Dim mytestConnect As ConnectionAddress
    Dim mySocket As SocketAddress
    Dim test As Long
    mySocket.acHost(0) = "1"
    mySocket.acHost(1) = "0"
    mySocket.acHost(2) = "."
    mySocket.acHost(3) = "1"
    mySocket.acHost(4) = "."
    mySocket.acHost(5) = "1"
    mySocket.acHost(6) = "."
    mySocket.acHost(7) = "2"
    'Do I have to terminate the string or something ?
    mySocket.nPort = 82

    mytestConnect.eType = 0
    mytestConnect.Socket = mySocket
    'MsgBox mytestConnect.Socket.acHost(0)
    test = NetApiDisconnect()
    'MsgBox test
    test = NetApiConnect(mytestConnect, 1)
    MsgBox test
    End Sub

    'MY MODULE CODE
    Public Type SocketAddress
    ulIpAddress As Long
    acHost(63) As String * 1 ' will be used by default if set, I will use it e.g. "10.1.1.2"
    nPort As Long ' e.g 80
    End Type

    Public Type ConnectionAddress
    eType As Long 'Will always be 0, refers to "SOCKET_TYPE" I think
    Socket As SocketAddress
    End Type

    Public Declare Function NetApiConnect Lib "MyApi.dll" (myAddress As ConnectionAddress, ByVal numberConnections As Long) As Long
    Public Declare Function NetApiDisconnect Lib "MyApi.dll" () As Long


    I don't even know how I could debug the whole thing....
    The dll is responding at least !
    It's probably the way I'm passing the string "acHost" ????
    You see anything wrong ?


    Thanks.

  8. #8
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    your definition of acHost is an array of Strings of length one, instead of one string of length 64. Try this:

    Public Type SocketAddress
    ulIpAddress As Long
    acHost As String * 64
    nPort As Long ' e.g 80
    End Type
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

Similar Threads

  1. MMFAN Retires
    By MMFAN in forum .NET
    Replies: 20
    Last Post: 09-23-2002, 12:54 AM
  2. .NET vs. Enterprise Java: Who's Got Better Security?
    By Glen Kunene in forum Talk to the Editors
    Replies: 17
    Last Post: 03-23-2002, 01:43 AM
  3. C Header to VB Declaration
    By MaRiŲ in forum VB Classic
    Replies: 0
    Last Post: 10-01-2001, 11:46 AM
  4. Replies: 90
    Last Post: 04-17-2001, 01:45 AM
  5. VB type declaration for LPSTR
    By peter higgins in forum VB Classic
    Replies: 0
    Last Post: 03-21-2001, 01:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center