Can't find the "error"

Hello,
I've just started with C++ and I'm creating a program where I can start and stop music on my PC with my mobile phone. Everything works fine in the program for my phone (client), but it seems that the server (PC) doesn't start to play the music. I'm using the Windows SDK 7.1 for the Windows Media Player functions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "stdafx.h"
#include "MTServer.h"
#include <iostream>
#include "atlbase.h"
#include "atlwin.h"
#include "wmp.h"

#include <stdlib.h>
#include <string>
#include "atlstr.h"
#include "comutil.h"



/*
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
*/
CWinApp theApp;
SOCKET server;
CComPtr<IWMPControls> spControls;
CComPtr<IWMPPlayer> spPlayer;
using namespace std;

UINT  MTServerThread(LPVOID pParam);
UINT  ClientThread(LPVOID pParam);

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    CoInitialize(NULL);

    HRESULT hr = S_OK;
    CComBSTR bstrVersionInfo; // Contains the version string.

    hr = spPlayer.CoCreateInstance( __uuidof(WindowsMediaPlayer), 0, CLSCTX_INPROC_SERVER );
    //spPlayer->get_controls(&spControls);
    if(SUCCEEDED(hr))
    {
        hr = spPlayer->get_versionInfo(&bstrVersionInfo);
    }
    if(SUCCEEDED(hr))
    {
        // Show the version.
        COLE2T pStr(bstrVersionInfo);
        cout << pStr << endl;
    }
    int nRetCode = 0;    

    cout << "Press ESCAPE to terminate program\r\n";
    hr = spPlayer->get_controls(&spControls);
    if(SUCCEEDED(hr))
    {
        cout << "get_controls successfull!" << endl;
    }
    AfxBeginThread(MTServerThread,0);

    while(_getch()!=27);

    // Clean up.
    //spPlayer.Release();
    //CoUninitialize();

    closesocket(server);
    WSACleanup();
    return nRetCode;
}


UINT  MTServerThread(LPVOID pParam)
{        
    WSADATA wsaData;
    sockaddr_in local;
    int wsaret=WSAStartup(0x101,&wsaData);
    if(wsaret!=0)
    {
        return 0;
    }
    local.sin_family=AF_INET;
    local.sin_addr.s_addr=INADDR_ANY;
    local.sin_port=htons((u_short)4444);
    server=socket(AF_INET,SOCK_STREAM,0);
    if(server==INVALID_SOCKET)
    {
        return 0;
    }
    if(bind(server,(sockaddr*)&local,sizeof(local))!=0)
    {
        return 0;
    }
    if(listen(server,10)!=0)
    {
        return 0;
    }

    SOCKET client;
    sockaddr_in from;
    int fromlen=sizeof(from);

    while(true)
    {
        client=accept(server,(struct sockaddr*)&from,&fromlen);
        AfxBeginThread(ClientThread,(LPVOID)client);    
    }    

    return 0;
}

UINT  ClientThread(LPVOID pParam)
{
    char buff[60];
    char buff3[60] = "Show me 10.mp3";
    int n;
    HRESULT hr = S_OK;
    //int x;
    SOCKET client=(SOCKET)pParam;
    //strcpy(buff,"#Server Ready.\r\n");
    send(client,buff3,strlen(buff3),0);
    while(true)
    {
        n=recv(client,buff,strlen(buff),0);

        if(strcmp(buff, "play") == 0)
        {
            spControls->play();
            cout << "play" << endl;
        }
        else if(strcmp(buff, "play") != 0)
        {
            CString string1 = "E:\\Users\\Kevin\\Music\\Musiklk\\";
            string1 += buff3;

            // Convert to a char*
            const size_t newsize = 200;
            char nstring[newsize];
            strcpy_s(nstring, string1);
            strcat_s(nstring, "");
            //cout << nstring << endl;

            // Convert to a wchar_t*
            // You must first convert to a char * for this to work.
            size_t origsize = strlen(string1) + 1;
            size_t convertedChars = 0;
            wchar_t wcstring[newsize];
            mbstowcs_s(&convertedChars, wcstring, origsize, string1, _TRUNCATE);
            wcscat_s(wcstring, L"");
            //wcout << wcstring << endl;

            BSTR MyBstr = SysAllocString(wcstring);
            spPlayer->put_enabled(true);
            hr=spPlayer->put_URL(MyBstr);
            if(SUCCEEDED(hr))
            {
                cout << "URL Loaded!" << endl;
            }
            //spControls->play();
        }
        cout << buff << endl;
        if(n==SOCKET_ERROR )
            break;
        buff[n]=0;
    }        

    closesocket(client);
    return 0;
}


I don't know what could be wrong. Everything works fine, except that it doesn't start the music...
Used a 3rd party Audio library now...
Topic archived. No new replies allowed.