|
toms from newdelhi wrote: ifstream is basically for a file and not for a binary data. What does this have to do with your problem?
As I understand it you are trying to transfer a bitmap from one computer to another via a network socket. So it is just a matter of transferring the binary data without any changes to its structure, and displaying the bitmap on the target system.
|
|
|
|
|
yes exactly this is the thing.
But not getting the exact thing how to do this?
|
|
|
|
|
toms from newdelhi wrote: yes exactly this is the thing. But not getting the exact thing how to do this? Too many things here. What exactly do you not understand about transferring a stream of bytes from one PC to another through network sockets? You can find plenty of samples via a Google search.
|
|
|
|
|
either you need to have a protocol implementation in your Clien-Server communication or you have to make sure that you send all the buffer at one time. If you are choosing a protocol means you first send a message to the server that am going to send a image buffer with size/length X and at the server store this and use this value for the next receive command.
If you are going to use whole buffer at one time, just use that buffer as such to create re-create your image. having a protocol is the best choice. if you google you can find many protocols choose the simplest one that suits your requirement.
Jibesh V P
|
|
|
|
|
Hello everybody i have a small question , not big enough for the quick answers . I am working on a MFC project a little bit old. And i had to add a header to the print result. My problem was with the font Size. After some tries i found the really useful Article about Printing trics. The problem was when i used
PrinterFont.lfHeight = -MulDiv(12, dc->GetDeviceCaps(LOGPIXELSY), 72);
Printing was ok but the PrintPreview wasnt. The font size was still small and i know why the GetDeviceCaps was returning the dpi of the monitor. This was understandable . After some digging in the code i found that for the rest printed text the font size was calculated a little bit different. For the font Height was taken the absolute value of the height multiplied by the zoom and all divided by some constant. My question is is there some practice about that kind of calculation . To be honest i don't think its a good idea to use it. I don't believe that all printers will print the same thing. But the PrintPreview and the Print result are pretty much the same.
What do you think ?
Thank you
|
|
|
|
|
Normally for printing the mapping mode is set to MM_TWIPS . Is that the practice you are looking for?
Blog : http://sujay-ghosh.blogspot.com
|
|
|
|
|
I created a MFC Smart Device App with Visual C++ in Visual Std 2008. I have dialog forms, I created SQLite database in VS2008. And I imported sqlite.dll sqlite.def etc. files. Now, I want to select data from my database, show in my textlist for example. But I don't know How can I do this.
What is my sqlconnection sentence? How can I create test.db? Which class will I write my sqlconnection sentence, or my select, insert, delete, update sql code? Can anybody explain this step by step?
It is my Job. I research this topic since a week, but still I can not solve this problem. Please help me!
|
|
|
|
|
|
We have developed a COM DLL 64 bit on Windows Server 2008 R2 - 64 bit and this dll is successfully register when visual studio 2010 is installed on the machine but when on a fresh machine its unable to register with following error:
module xxxx.dll failed to load
make sure the binary is stored at the specified path or debug it to check for prob with the binary or dependent dll files
After a lot of investigation, we found that if Microsoft C++ runtime 2010 10.0.3019 is installed, then only dll will be registered. Can anyone provide the required list of dependecy. Thanks in advance.
|
|
|
|
|
|
I need to play a mp3 file on UPNP device (TV) using program.
Could you help me with related articles or any other information?
|
|
|
|
|
Is this[^] article suitable for you ?
|
|
|
|
|
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.
|
|
|
|
|