Results 1 to 5 of 5

Thread: problem accessing these functions

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2001
    Posts
    746

    problem accessing these functions

    in a demo tutorial example program i downloaded it has a included .h file and then in the src code it has funtions like

    VB Code:
    1. int thedot'h'file::functionname(arguments)
    2. {
    3.         code;
    4. }

    i tried calling these functions with

    VB Code:
    1. functionname(arguments);

    but it didnt work. how can i access these functions?
    FlameWave Technologies - internet tools

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    that looks like a functioin of a class
    you'd have to declare something first
    thedot'h'file myvar;
    myvar.functionname(arguments)

    what book is this?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2001
    Posts
    746
    i still dont quite understand what u mean. the structure is called MasterSocket and inside is a void called Listen. how would i access listen?
    FlameWave Technologies - internet tools

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2001
    Posts
    746
    heres the whole source code.

    VB Code:
    1. // master socket
    2. // written by jared bruni
    3. // mastersocket 1.0
    4. // written by jared bruni
    5. // [url]www.lostsidedead.com[/url]
    6.  
    7. #include <windows.h>
    8. #include <winsock.h>
    9. #include<iostream.h>
    10.  
    11. #define DEFAULT_PORT -1
    12.  
    13. // initilize and kill winsock
    14. void initwinsock();
    15. void killwinsock();
    16. // structure to automaticly initlize and kill winsock
    17. struct AutoWinSockHandle
    18. {
    19.     inline AutoWinSockHandle()
    20.     {
    21.         initwinsock();
    22.     }
    23.  
    24.     inline ~AutoWinSockHandle()
    25.     {
    26.         killwinsock();
    27.     }
    28. };
    29.  
    30. static AutoWinSockHandle sock_handle; // automaticly construct, and deconstruct
    31. // winsock with this static structure
    32.  
    33. struct MasterSocket
    34. {
    35.     SOCKET socketx; // the socket structure
    36.     HWND  hwnd; // handle of the window the socket is attached to
    37.     UINT  SOCKET_ID; // socket ID
    38.     void CreateSocket(HWND hwndx,UINT SOCKET_IDx);// create the socket
    39.     void Listen(UINT port);// listen on the socket
    40.     void Connect(char* ipaddress,UINT port);// connect with the socket
    41.     void Send(char* buff, int len); // send data with a connected socket
    42.     int Recive(char* buff,int len);// recive data
    43.     void Accept(); // accept a incomin socket
    44.     const UINT GetID();// get the ID of this socket
    45.     void Close();// close the socket
    46. };
    47. // initilze windows sockets
    48. void initwinsock()
    49. {
    50.    
    51. WORD wVersionRequested;
    52. WSADATA wsaData;
    53. int err;
    54.  
    55. wVersionRequested = MAKEWORD( 1, 1 );
    56.  
    57. err = WSAStartup( wVersionRequested, &wsaData );
    58. if ( err != 0 ) {
    59.     MessageBox(0,"Error Couldnt Init Winsock!","Aborting",MB_ICONINFORMATION);
    60.     PostQuitMessage(0);
    61.     return;
    62. }
    63.  
    64.  
    65. if ( LOBYTE( wsaData.wVersion ) != 1 ||
    66.          HIBYTE( wsaData.wVersion ) != 1 ) {
    67.     WSACleanup( );
    68.     return;  
    69.  
    70. }
    71. }
    72.  
    73. // killwinsock, on lcose
    74. void killwinsock()
    75. {
    76.     WSACleanup();
    77. }
    78.  
    79. // the master socket data structure
    80. void MasterSocket::CreateSocket(HWND hwndx, UINT SOCKET_IDx)
    81. {
    82.     hwnd = hwndx;
    83.     SOCKET_ID = SOCKET_IDx;
    84.     socketx = socket(AF_INET,SOCK_STREAM,0);
    85.     WSAAsyncSelect(socketx,hwnd,SOCKET_ID,FD_CONNECT|FD_READ|FD_CLOSE|FD_ACCEPT);
    86. }
    87.  
    88. // begin listening
    89. void MasterSocket::Listen(UINT port)
    90. {
    91.     if(port == DEFAULT_PORT) { port = 7; }
    92.    
    93.      struct sockaddr_in addy;
    94.     // begin watching on port 7
    95.     addy.sin_family = AF_INET;
    96.     addy.sin_port = htons(port);
    97.     addy.sin_addr.s_addr = INADDR_ANY; //inet_addr("172.129.243.252");
    98.     bind(socketx,(struct sockaddr*)&addy,sizeof(addy));
    99.     listen(socketx,5);
    100. }
    101. // connect to a remote socket
    102. void MasterSocket::Connect(char* ipaddress,UINT port)
    103. {
    104.     struct sockaddr_in addy2;
    105.     if(port == DEFAULT_PORT) { port = 7; }
    106.  
    107.     addy2.sin_family = AF_INET;
    108.     addy2.sin_port = htons(port);
    109.     addy2.sin_addr.s_addr = inet_addr(ipaddress);
    110.     connect(socketx,(struct sockaddr*)&addy2,sizeof(addy2));
    111. }
    112. // accept a request from remote socket
    113. void MasterSocket::Accept()
    114. {
    115.     struct sockaddr cli_addr;
    116.     int clilen;
    117.     clilen = sizeof(cli_addr);
    118.     socketx = accept(socketx,(struct sockaddr*)&cli_addr,&clilen);
    119. }
    120.  
    121. // send data once socket is connected
    122. void MasterSocket::Send(char* buff, int len)
    123. {
    124.     send(socketx,buff,len,0);
    125. }
    126. // recive data from a connected socket
    127. int MasterSocket::Recive(char* buff,int len)
    128. {
    129.     return recv(socketx,buff,len,0);
    130. }
    131. // get the ID of a given socket, for the wndproc callback
    132. const UINT MasterSocket::GetID()
    133. {
    134.     return (const UINT)SOCKET_ID;
    135. }
    136. // close an open socket
    137. void MasterSocket::Close()
    138. {
    139.     closesocket(socketx);
    140. }
    141.  
    142. int main()
    143. {
    144.     initwinsock();
    145.     MasterSocket.Listen(10);
    146.  
    147.     return 0;
    148. }
    FlameWave Technologies - internet tools

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    When posting C/C++ code you should use [ code ] or [ php ] tags, not [ vbcode ]
    Code:
    int main()
    {
      // initwinsock is not necessary, this is done automatically
      MasterSocket socket;  // create a mastersocket object
      socket->Listen(80);  // listen to the http port
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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