|
Thank you but this is not for me.
I am looking to play audio on UPNP device.
|
|
|
|
|
Maybe this[^] article will help.
|
|
|
|
|
This is Vb and not able to debug as it is for Win8 specific.
We need for window7 or lower.Please help.
|
|
|
|
|
sorry, maybe this[^] is better?
|
|
|
|
|
Problem building Platinum.lib with VS2010
error MSB8009: .NET Framework 2.0/3.0/3.5 you need v90-Plattformtoolset
|
|
|
|
|
I'm working on a project and I'm a beginner in VC++.
I'm creating a TCP server that will receive a bitmap and will show it on window.
The motive is to receive the continuous images from a client and show them one by one on server window.
My code is:
#include <winsock2.h>
#include <windows.h>
#include <stdio.h>
#include <io.h>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#pragma comment (lib, "ws2_32.lib")
#define IDC_EDIT_IN 101
//#define IDC_EDIT_OUT 102
//#define IDC_MAIN_BUTTON 103
#define WM_SOCKET 104
#define DEFAULT_BUFLEN 1024
PAINTSTRUCT ps;
int nPort=5552;
HBITMAP hbitmap;
BITMAP cBitmap;
/*HWND hEditIn=NULL;
HWND hEditOut=NULL*/;
SOCKET Socket=NULL;
char szHistory[10000];
sockaddr sockAddrClient;
LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASSEX wClass;
ZeroMemory(&wClass,sizeof(WNDCLASSEX));
wClass.cbClsExtra=NULL;
wClass.cbSize=sizeof(WNDCLASSEX);
wClass.cbWndExtra=NULL;
wClass.hbrBackground=(HBRUSH)COLOR_WINDOW;
wClass.hCursor=LoadCursor(NULL,IDC_ARROW);
wClass.hIcon=NULL;
wClass.hIconSm=NULL;
wClass.hInstance=hInst;
wClass.lpfnWndProc=(WNDPROC)WinProc;
wClass.lpszClassName="Window Class";
wClass.lpszMenuName=NULL;
wClass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClassEx(&wClass))
{
int nResult=GetLastError();
MessageBox(NULL,
"Window class creation failed\r\nError code:",
"Window Class Failed",
MB_ICONERROR);
}
HWND hWnd=CreateWindowEx(NULL,
"Window Class",
"Capture Server",
WS_OVERLAPPEDWINDOW,
200,
200,
640,
480,
NULL,
NULL,
hInst,
NULL);
if(!hWnd)
{
int nResult=GetLastError();
MessageBox(NULL,
"Window creation failed\r\nError code:",
"Window Creation Failed",
MB_ICONERROR);
}
ShowWindow(hWnd,nShowCmd);
MSG msg;
ZeroMemory(&msg,sizeof(MSG));
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{switch(msg)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd,&ps);
if(hbitmap != 0)
{
HDC hdcMem = CreateCompatibleDC(hdc);
SelectObject(hdcMem, hbitmap);
BitBlt(hdc, 10, 10, cBitmap.bmWidth, cBitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
}
EndPaint (hWnd, &ps);
}
break;
case WM_CREATE:
{
ZeroMemory(szHistory,sizeof(szHistory));
// Create incoming message box
/*hEditIn=CreateWindowEx(WS_EX_CLIENTEDGE,
"EDIT",
"",
WS_CHILD|WS_VISIBLE|ES_MULTILINE|
ES_AUTOVSCROLL|ES_AUTOHSCROLL,
20,
20,
200,
20,
hWnd,
(HMENU)IDC_EDIT_IN,
GetModuleHandle(NULL),
NULL);*/
/*if(!hEditIn)
{
MessageBox(hWnd,
"Could not create incoming edit box.",
"Error",
MB_OK|MB_ICONERROR);
}*/
HGDIOBJ hfDefault=GetStockObject(DEFAULT_GUI_FONT);
/*SendMessage(hEditIn,
WM_SETFONT,
(WPARAM)hfDefault,
MAKELPARAM(FALSE,0));*/
/*SendMessage(hEditIn,
WM_SETTEXT,
NULL,
(LPARAM)"Waiting for client to connect...");*/
WSADATA WsaDat;
int nResult=WSAStartup(MAKEWORD(2,2),&WsaDat);
if(nResult!=0)
{
MessageBox(hWnd,
"Winsock initialization failed",
"Critical Error",
MB_ICONERROR);
SendMessage(hWnd,WM_DESTROY,NULL,NULL);
break;
}
Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(Socket==INVALID_SOCKET)
{
MessageBox(hWnd,
"Socket creation failed",
"Critical Error",
MB_ICONERROR);
SendMessage(hWnd,WM_DESTROY,NULL,NULL);
break;
}
SOCKADDR_IN SockAddr;
SockAddr.sin_port=htons(nPort);
SockAddr.sin_family=AF_INET;
SockAddr.sin_addr.s_addr=htonl(INADDR_ANY);
if(bind(Socket,(LPSOCKADDR)&SockAddr,sizeof(SockAddr))==SOCKET_ERROR)
{
MessageBox(hWnd,"Unable to bind socket","Error",MB_OK);
SendMessage(hWnd,WM_DESTROY,NULL,NULL);
break;
}
nResult=WSAAsyncSelect(Socket,
hWnd,
WM_SOCKET,
(FD_CLOSE|FD_ACCEPT|FD_READ));
if(nResult)
{
MessageBox(hWnd,
"WSAAsyncSelect failed",
"Critical Error",
MB_ICONERROR);
SendMessage(hWnd,WM_DESTROY,NULL,NULL);
break;
}
if(listen(Socket,(1))==SOCKET_ERROR)
{
MessageBox(hWnd,
"Unable to listen!",
"Error",
MB_OK);
SendMessage(hWnd,WM_DESTROY,NULL,NULL);
break;
}
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
shutdown(Socket,SD_BOTH);
closesocket(Socket);
WSACleanup();
return 0;
}
break;
case WM_SOCKET:
{
switch(WSAGETSELECTEVENT(lParam))
{
case FD_READ:
{
/*char szIncoming[1024];*/
char recvbuffer[102400];
int filebuflen = DEFAULT_BUFLEN;
ZeroMemory(recvbuffer, filebuflen);
int bytes_read = recv(Socket, recvbuffer, filebuflen, 0 );
/* ZeroMemory(szIncoming,sizeof(szIncoming));*/
/*int inDataLength=recv(Socket,
(char*)szIncoming,
sizeof(szIncoming)/sizeof(szIncoming[0]),
0);*/
/*strncat(szHistory,szIncoming,inDataLength);
strcat(szHistory,"\r\n");*/
/*SendMessage(hEditIn,
WM_SETTEXT,
sizeof(szIncoming)-1,
reinterpret_cast<lparam>(&szHistory));*/
if(bytes_read==0)
/* MessageBox(hWnd,
"File Read Error",
"Corrupt File",
MB_ICONINFORMATION|MB_OK);*/
break;
if(bytes_read <0)
{
MessageBox(hWnd,
"File Read Error",
"Corrupt File",
MB_ICONINFORMATION|MB_OK);
}
std::ifstream is;
char* pbuffer;
/*is.open("image.bmp", std::ios::binary);*/
/*is.seekg(0, std::ios::end);
*/
/* pbuffer = new char[bytes_read];*/
bytes_read = is.tellg();
/* is.seekg(0, std::ios::beg);*/
pbuffer = new char[bytes_read];
is.read(pbuffer, bytes_read);
is.close();
tagBITMAPFILEHEADER bfh = *(tagBITMAPFILEHEADER*)pbuffer;
tagBITMAPINFOHEADER bih = *(tagBITMAPINFOHEADER*)(pbuffer+sizeof(tagBITMAPFILEHEADER));
RGBQUAD rgb = *(RGBQUAD*)(pbuffer+sizeof(tagBITMAPFILEHEADER)+sizeof(tagBITMAPINFOHEADER));
BITMAPINFO bi;
bi.bmiColors[0] = rgb;
bi.bmiHeader = bih;
char* pPixels = (pbuffer+bfh.bfOffBits);
char* ppvBits;
hbitmap = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, (void**) &ppvBits, NULL, 0);
SetDIBits(NULL, hbitmap, 0, bih.biHeight, pPixels, &bi, DIB_RGB_COLORS);
GetObject(hbitmap, sizeof(BITMAP), &cBitmap);
delete[] pbuffer;
/*infile = fopen("test.txt","wb");
fwrite (filebuf, 1, sizeof(filebuf), infile);
fclose (infile);*/
}
break;
case FD_CLOSE:
{
MessageBox(hWnd,
"Client closed connection",
"Connection closed!",
MB_ICONINFORMATION|MB_OK);
/*closesocket(Socket);*/
SendMessage(hWnd,WM_DESTROY,NULL,NULL);
}
break;
case FD_ACCEPT:
{
int size=sizeof(sockaddr);
Socket=accept(wParam,&sockAddrClient,&size);
if (Socket==INVALID_SOCKET)
{
int nret = WSAGetLastError();
WSACleanup();
}
/*SendMessage(hEditIn,
WM_SETTEXT,
NULL,
(LPARAM)"Client connected!");*/
}
break;
}
}
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}
and I'm getting an error. when client is sending the image then it is completely sent from client side but I can't see it on server side.
Help me Please.
Thanks!
|
|
|
|
|
- If you must post code then please use the code button above, to put <pre> tags around it.
- If you are receiving an error then show the exact text or status code, and show the point in your program where it occurs.
|
|
|
|
|
Respected Sir,
As I'm new to VC++ and forum so I was having no idea of this thing.
Well the Problem is- On TCP server I want to receive the images and show it on server window, without saving it.
|
|
|
|
|
Fine, but we cannot help you unless you explain what is going wrong.
|
|
|
|
|
I did tried with this one...
case WM_SOCKET:
{
int i=256;
BYTE* data = new BYTE[256*256*256];
int packetsize, num;
int newWidth, newHeight;
int recvimgsize=0;
bool bAwaitingImage = false;
switch(WSAGETSELECTEVENT(lParam))
{
case FD_READ:
{
num=recv(Socket, (char*)data, 3, 0);
if(num>0)
{
packetsize = data[1]*256+ data[2];
num=recv(Socket, (char*)(data+3), packetsize-3, 0);
}
if(num>0)
{
switch(data[0])
{
case 2:
newWidth = data[3]*256+data[4];
newHeight = data[5]*256+data[6];
if(newHeight!=cBitmap.bmHeight || newWidth!=cBitmap.bmWidth)
{
cBitmap.bmWidth = newWidth;
cBitmap.bmHeight = newHeight;
RECT r;
GetWindowRect(hWnd, &r);
SetWindowPos(hWnd, NULL, r.left, r.top, cBitmap.bmWidth, cBitmap.bmHeight, 0);
HDC ThisDC = GetDC(hWnd);
DeleteDC(RemoteDC);
RemoteDC = CreateCompatibleDC(ThisDC);
DeleteObject(hbitmap);
hbitmap = CreateCompatibleBitmap(ThisDC,cBitmap.bmWidth ,cBitmap.bmHeight);
SelectObject(RemoteDC, hbitmap);
ReleaseDC(hWnd, ThisDC);
}
break;
case 3:
{
BITMAPINFO bi;
int biSize = sizeof(BITMAPINFO);
memcpy(&bi, data+3, biSize);
SetDIBits(RemoteDC, hbitmap, 0,cBitmap.bmHeight, data+biSize+3, &bi, DIB_RGB_COLORS);
InvalidateRect(hWnd, NULL, false);
break;
}
its a long code ,,,
but i got stuck on when client sends image then it is completely sent but from server side program hangs and stopped working and nothing on server.
I'll be highly thankful if you can help me in this!!
Thanks
|
|
|
|
|
toms from newdelhi wrote: it is completely sent but from server side program hangs Sorry, but there is no way I can guess what may be happening. You need to get with your debugger at both ends and trace where it is getting stuck.
|
|
|
|
|
The Problem it is showing in debugger and as I analyzed is that server is unable to
store the data in a buffer.
The buffer is showing problem.
Thanks!
|
|
|
|
|
toms from newdelhi wrote: The buffer is showing problem. I'm sorry but you really need to learn to give exact details. A statement like this tells us nothing.
|
|
|
|
|
Well, you are starting off from the wrong basis here.
A TCP server (in fact a client and server) is implemented in the kernel (on WIndows as TCPIP.sys) and supports am interface called TDI (on older Windows OSs and called something else on newer ones). TDI transports across the IO manager (Kernel to USer mode), providing sockets in the user mode for applications to use.
So what you need are two apps one that opens a socket and sends a bmp file, and another that waits on a socket and can render that bmp file to the screen.
(You can also not directly display UI stuff from the kernel so the stock TCP kernel driver would never be able to display a bmp)
If you really wanted to implement a user mode TCP server/client module then the question is why, and the problem is how you are going to send IP packets to the network card. And if you wanted to send Ethernet packets to the network card you would need to implement IP in user mode too. And if you wanted to do that you would need to write a network driver for your card with a interface accessible to the IO manager that you could open in user mode to get those Ethernet packets to it. All in all a massive and complex problem, so just use sockets, its what they are made for, and made by a lot of very clever people who understood the network stack and provided it for people like you to use.
==============================
Nothing to say.
|
|
|
|
|
I think you misunderstood OP's question.
|
|
|
|
|
Could be, it was an odd question.
==============================
Nothing to say.
|
|
|
|
|
Sir,
I'm creating a simple TCP server with which I can receive the images and display those on server window.
|
|
|
|
|
But like I said the TCP module is embedded in tcpip.sys in the kernel. Why reinvent the wheel?
You already have sockets that provides a transport across the network usually using TCP over IP so why not use it?
==============================
Nothing to say.
|
|
|
|
|
sir this application is for showing the IPAD on a windows screen.
That's why I'm creating this to do so..
I'll have to receive the data from IPAD and will have to show it on
Window or on a GUI in windows 7.
Thanks!
|
|
|
|
|
So what existing transports are there for data between an IPAD and a PC? DO IPADs support WiFi? Bluetooth? How about a USB connection?
https://www.google.fr/search?client=opera&rls=en&q=IPAD+to+PC+communication&sourceid=opera&ie=utf-8&oe=utf-8&channel=suggest
Lots of ways to skin a cat without reinventing the wheel.
==============================
Nothing to say.
|
|
|
|
|
|
Respected Andy Sir,
I've studied your applications written on codeproject
and discussed to my senior but he refuses to use it in a long way.
The thing is only to receive the images and show them without saving,,, its complete thing like you have done..
Can you help me in this??
|
|
|
|
|
Tell your boss I'm available, by a short term contract, to write the application for him. I could produce this application in a short amount of time and to his specifications.
|
|
|
|
|
Hi,
I am writting a OLE app that I want to be MFC based towards that end
I think I need two things
1) A Main Thread CWinApp
2) A main window "m_pMainWnd"
My question is can the main window be a modeless dialog box or does it have
to be CFrameWnd
Thanks
|
|
|
|
|
What do you mean by modeless?
In all MFC dialog based apps, the main dialog acts just like a modeless child dialog.
|
|
|
|
|