Troubles with Sockets Bluetooth in Windows XP
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Troubles with Sockets Bluetooth in Windows XP

  1. #1
    Join Date
    Nov 2006
    Posts
    2

    Unhappy Troubles with Sockets Bluetooth in Windows XP

    Hi everybody, how are you? I hope fine.

    Well, I'm developing a application where communication two PCs using Bluetooth.

    For this, I writed follow code:
    Code:
    #include <stdio.h>
    #include <winsock2.h>
    #include <Ws2bth.h>
    #include <BluetoothAPIs.h>
    
    int main(int argc, char **argv) {
    	// -----------------
    	// Inicializar WinSock
    	WSADATA wsaData;
    	printf("Inicializando Winsock().\n");
    	int iResult = WSAStartup(MAKEWORD(1, 1), &wsaData);
    	if (iResult == NO_ERROR) {
    		printf("Error en WSAStartup()\n");
    		exit(1);
    	}
    	printf("Inicializacion con exito.\n\n");
    	
    	// ------------------
    	// Se crea un SOCKET para la conexión 
    	printf("Se crea el SOCKET.\n");
    	SOCKET connectSocket;
    	connectSocket = socket(AF_BTH, 
    						   SOCK_STREAM, 
    						   BTHPROTO_RFCOMM);
    	if (connectSocket == INVALID_SOCKET) {
    		printf("Error en socket(): %ld\n", WSAGetLastError());
    		WSACleanup();
    		exit(1);
    	} 
    	printf("Creacion del socket con exito.\n\n");
    	
    	// -------------------
    	// La estructura "sockaddr_in" especifica la familia de direcciones.
    	// En el lado del SERVER el numero de puerto
    	// de ser un numero de puerto valido o en su
    	// caso usar BT_PORT_ANY, que asigna un numero
    	// de puerto automaticamente y puede ser consultado
    	// usando la funcion "getsockname()".
    	SOCKADDR_BTH local_addr;
    	local_addr.addressFamily = AF_BTH;
    	local_addr.btAddr = 0;
    //	local_addr.serviceClassId = NULL_GUID;
    	local_addr.port = BT_PORT_ANY; 
    	
    	// -------------------
    	// Se enlaza el PORT al SOCKET.
    	printf("Enlazando el PORT al SOCKET.\n");  
    	iResult = bind(connectSocket, 
    	               (struct sockaddr *) &local_addr, 
    	               sizeof(local_addr));
    	if (iResult == SOCKET_ERROR) {
    		printf("Fallo la funcion bind().\n");
    		closesocket(connectSocket);
    		exit(1);
    	}
    //	SOCKADDR_BTH fore_addr;
    //	getsockname(connectSocket,
    //				(struct sockaddr *) &fore_addr,
    //				sizeof(fore_addr));
    //	printf("Enlazado con exito.\nNumero de puerto: %d", fore_addr.port);
    	printf("Enlazado con exito.\n\n");
    	
    	// --------------------
    	// Establecer SOCKET en modo LISTEN.
    	printf("Establecer SOCKET en modo LISTEN.\n");
    	iResult = listen(connectSocket, 10);
    	if (iResult == SOCKET_ERROR	) {
    		printf("Fallo la funcion listen().\n");
    		closesocket(connectSocket);
    		exit(1);
    	}
    	printf("Funcion listen() con exito.\n\n");
    	
    	return 0;		
    }
    I have install Microsoft Plataform SDK (XPSP2 PSDK), where there are header files (BluetoothAPIs.h, WinSock2.h, WinSock, ws2bth.h) and library files (irprops.lib and WS2_32.Lib).

    My makefile is follow:

    Code:
    CC = gcc
    all: Server.exe
    
    Server.exe: Server.o
    	$(CC) -o Server.exe Server.o -lirprops -lWS2_32
    	
    Server.o: Server.c
    	$(CC) -c Server.c -I"C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include"
    Note: My compiler it's MinGW 3.4.2 (gcc) and IDE is Eclipse (with CDT).

    When I to compile, show me some erros:

    Code:
    mingw32-make all 
    gcc -c Server.c -I"C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include"
    In file included from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/windef.h:166,
                     from C:/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/excpt.h:20,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/windows.h:157,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/winsock2.h:47,
                     from Server.c:2:
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/winnt.h:741:2: #error Must define a target architecture.
    In file included from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/windows.h:164,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/winsock2.h:47,
                     from Server.c:2:
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/winuser.h:10562: warning: declaration does not declare anything
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/winuser.h:10567: warning: declaration does not declare anything
    In file included from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/objbase.h:383,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/ole2.h:45,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/windows.h:207,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/winsock2.h:47,
                     from Server.c:2:
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/objidl.h:263: error: redefinition of typedef 'IRpcChannelBuffer'
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/objbase.h:379: error: previous declaration of 'IRpcChannelBuffer' was here
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/objidl.h:299: error: redefinition of typedef 'IRpcStubBuffer'
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/objbase.h:378: error: previous declaration of 'IRpcStubBuffer' was here
    In file included from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/objbase.h:383,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/ole2.h:45,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/windows.h:207,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/winsock2.h:47,
                     from Server.c:2:
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/objidl.h:6593: warning: declaration does not declare anything
    In file included from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/msxml.h:273,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/urlmon.h:271,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/objbase.h:852,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/ole2.h:45,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/windows.h:207,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/winsock2.h:47,
                     from Server.c:2:
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/oaidl.h:441:1: pasting "/" and "/" does not give a valid preprocessing token
    In file included from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/msxml.h:273,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/urlmon.h:271,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/objbase.h:852,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/ole2.h:45,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/windows.h:207,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/winsock2.h:47,
                     from Server.c:2:
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/oaidl.h:441: error: syntax error before '/' token
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/oaidl.h:456:1: pasting "/" and "/" does not give a valid preprocessing token
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/oaidl.h:456: error: syntax error before '/' token
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/oaidl.h:484: error: syntax error before '}' token
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/oaidl.h:485: error: syntax error before '}' token
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/oaidl.h:487: error: syntax error before '}' token
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/oaidl.h:488: error: syntax error before '}' token
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/oaidl.h:602: error: field `varDefaultValue' has incomplete type
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/oaidl.h:880: error: field `varValue' has incomplete type
    In file included from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/objbase.h:853,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/ole2.h:45,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/windows.h:207,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/winsock2.h:47,
                     from Server.c:2:
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/propidl.h:309:1: pasting "/" and "/" does not give a valid preprocessing token
    In file included from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/objbase.h:853,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/ole2.h:45,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/windows.h:207,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/winsock2.h:47,
                     from Server.c:2:
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/propidl.h:309: error: syntax error before '/' token
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/propidl.h:309: warning: no semicolon at end of struct or union
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/propidl.h:309: warning: no semicolon at end of struct or union
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/propidl.h:309: warning: no semicolon at end of struct or union
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/propidl.h:370: error: syntax error before '}' token
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/propidl.h:373: error: syntax error before '}' token
    In file included from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/windows.h:236,
                     from C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/winsock2.h:47,
                     from Server.c:2:
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/imm.h:28: error: redefinition of typedef 'LPUINT'
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/mmsystem.h:111: error: previous declaration of 'LPUINT' was here
    In file included from Server.c:4:
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/BluetoothAPIs.h:25: error: redefinition of typedef 'BTH_ADDR'
    C:/Program Files/Microsoft Platform SDK for Windows XP SP2/Include/bthdef.h:278: error: previous declaration of 'BTH_ADDR' was here
    mingw32-make: *** [Server.o] Error 1
    I don't know why this errors.

    Do you know how fix the errors show above? I hope that yes.

    Thanks in advance.

  2. #2
    Join Date
    Mar 2001
    Posts
    2,375

    Re: Troubles with Sockets Bluetooth in Windows XP

    You should define a target.

    #error Must define a target architecture.
    Typically you can do that for gcc with -DTARGET_NAME.

    eg: gcc -g -c -D_WINDOWS test.c

    Have a look at the header file errors to figure out what else you might need.

    If you don't, your just guessing.
    ahoodin
    To keep the plot moving, that's why.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center