Abstract Class, Socket Programming, JPEG in VC6
-
Hi to all, 1) What is use of Abstract Class? What it's advantage over normal Class? 2) As I know, =>Steps in TCP Server are, (1).Create TCP Socket (using SOCK_STREAM), (2).Bind to a Port, (3).Listen, (4).Accept a connection (from Client), (5).Send & Receive Data =>Steps in TCP Client are, (1).Create TCP Socket (using SOCK_STREAM), (2).Connect to a Socket(TCP Server), (3).Send & Receive Data =>Steps in UDP Client are, (1).Create UDP Socket (using SOCK_DGRAM), (3).Send Data to a UDP Socket; Receive Data from a UDP Socket Am I right? What are the step to be done in UDP Server? When I searched it in Google, I found that UDP Socket can use 'Connect()' ! But how it is possible if UDP is Connectonless? 3) In VC6, how to get Pixels of a JPEG Image? How to show image using it's pixels on the Dialog?
-
Hi to all, 1) What is use of Abstract Class? What it's advantage over normal Class? 2) As I know, =>Steps in TCP Server are, (1).Create TCP Socket (using SOCK_STREAM), (2).Bind to a Port, (3).Listen, (4).Accept a connection (from Client), (5).Send & Receive Data =>Steps in TCP Client are, (1).Create TCP Socket (using SOCK_STREAM), (2).Connect to a Socket(TCP Server), (3).Send & Receive Data =>Steps in UDP Client are, (1).Create UDP Socket (using SOCK_DGRAM), (3).Send Data to a UDP Socket; Receive Data from a UDP Socket Am I right? What are the step to be done in UDP Server? When I searched it in Google, I found that UDP Socket can use 'Connect()' ! But how it is possible if UDP is Connectonless? 3) In VC6, how to get Pixels of a JPEG Image? How to show image using it's pixels on the Dialog?
Aniket Salunkhe wrote:
What is use of Abstract Class? What it's advantage over normal Class?
It can define an interface with no implimentation. C# has interfaces, C++ does not, this is one way to get them.
Aniket Salunkhe wrote:
In VC6, how to get Pixels of a JPEG Image?
Use GDI+ ( this involves finding a PSDK that works with VC6 ), or use a library like CXImage or Paintlib. Or, get a decent C++ compiler :-)
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hi to all, 1) What is use of Abstract Class? What it's advantage over normal Class? 2) As I know, =>Steps in TCP Server are, (1).Create TCP Socket (using SOCK_STREAM), (2).Bind to a Port, (3).Listen, (4).Accept a connection (from Client), (5).Send & Receive Data =>Steps in TCP Client are, (1).Create TCP Socket (using SOCK_STREAM), (2).Connect to a Socket(TCP Server), (3).Send & Receive Data =>Steps in UDP Client are, (1).Create UDP Socket (using SOCK_DGRAM), (3).Send Data to a UDP Socket; Receive Data from a UDP Socket Am I right? What are the step to be done in UDP Server? When I searched it in Google, I found that UDP Socket can use 'Connect()' ! But how it is possible if UDP is Connectonless? 3) In VC6, how to get Pixels of a JPEG Image? How to show image using it's pixels on the Dialog?
- An abstract class has at least one pure virtual function. That means that an object can't be created of that class' type. It can only be used as a base class. This defines virtual methods for a class heirarchy while forcing derived class(es) to provide an implementation. I guess one advantage is that using a pointer/reference to an abstract type, you are assured that any pure virtual functions have a derived class implementation. 2) connect() when used on a UDP socket just sets the default destination address so if you use send(), the datagram will be sent to the "connected" address. If you don't use connect then you have to use sendto() to send a datagram. If you do use connect() then you can use send() and/or sendto(). 3) The JPEG compressed data needs to be uncompressed to get pixel data suitable for displaying.
"If you can dodge a wrench, you can dodge a ball."
-
Hi to all, 1) What is use of Abstract Class? What it's advantage over normal Class? 2) As I know, =>Steps in TCP Server are, (1).Create TCP Socket (using SOCK_STREAM), (2).Bind to a Port, (3).Listen, (4).Accept a connection (from Client), (5).Send & Receive Data =>Steps in TCP Client are, (1).Create TCP Socket (using SOCK_STREAM), (2).Connect to a Socket(TCP Server), (3).Send & Receive Data =>Steps in UDP Client are, (1).Create UDP Socket (using SOCK_DGRAM), (3).Send Data to a UDP Socket; Receive Data from a UDP Socket Am I right? What are the step to be done in UDP Server? When I searched it in Google, I found that UDP Socket can use 'Connect()' ! But how it is possible if UDP is Connectonless? 3) In VC6, how to get Pixels of a JPEG Image? How to show image using it's pixels on the Dialog?
Aniket Salunkhe wrote:
What is use of Abstract Class? What it's advantage over normal Class?
Good Grief... are you kidding? JFGI[^] An abstract class, or abstract base class (ABC), is one that is designed only as a parent class and from which child classes may be derived, and which is not itself suitable for instantiation. Abstract classes are often used to represent abstract concepts or entities. The incomplete features of the abstract class are then shared by a group of sibling sub-classes which add different variations of the missing pieces. In C++, an abstract class is defined as a class having at least one pure virtual method, i.e., an abstract method, which may or may not possess an implementation.
led mike
-
Aniket Salunkhe wrote:
What is use of Abstract Class? What it's advantage over normal Class?
Good Grief... are you kidding? JFGI[^] An abstract class, or abstract base class (ABC), is one that is designed only as a parent class and from which child classes may be derived, and which is not itself suitable for instantiation. Abstract classes are often used to represent abstract concepts or entities. The incomplete features of the abstract class are then shared by a group of sibling sub-classes which add different variations of the missing pieces. In C++, an abstract class is defined as a class having at least one pure virtual method, i.e., an abstract method, which may or may not possess an implementation.
led mike
blah blah bla...a bunch of useless techno-babble. Everyone knows the advantage is being able to say "I used an abstract class" and nobody knows what you're talking about. :rolleyes:
"If you can dodge a wrench, you can dodge a ball."
-
Hi to all, 1) What is use of Abstract Class? What it's advantage over normal Class? 2) As I know, =>Steps in TCP Server are, (1).Create TCP Socket (using SOCK_STREAM), (2).Bind to a Port, (3).Listen, (4).Accept a connection (from Client), (5).Send & Receive Data =>Steps in TCP Client are, (1).Create TCP Socket (using SOCK_STREAM), (2).Connect to a Socket(TCP Server), (3).Send & Receive Data =>Steps in UDP Client are, (1).Create UDP Socket (using SOCK_DGRAM), (3).Send Data to a UDP Socket; Receive Data from a UDP Socket Am I right? What are the step to be done in UDP Server? When I searched it in Google, I found that UDP Socket can use 'Connect()' ! But how it is possible if UDP is Connectonless? 3) In VC6, how to get Pixels of a JPEG Image? How to show image using it's pixels on the Dialog?
You can use OleLoadPicture(). The following code two-steps it - loads the JPG into a HBITMAP then draws the HBITMAP If you just wanted load & draw it w/o the intermediate BMP you could call pPic->Render() into the dialog's DC.
#include <Ole2.h>
#include <olectl.h>
#define HIMETRIC_INCH 2540
HBITMAP LoadJpgFile(LPCTSTR filename)
{
HBITMAP hBmp = NULL;if(filename && *filename)
{
HANDLE hFile = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if(hFile)
{
DWORD dwFileSize = GetFileSize(hFile, NULL);
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
if(hGlobal)
{
LPVOID pvData = GlobalLock(hGlobal);
if(pvData)
{
DWORD dwBytesRead = 0;
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
GlobalUnlock(hGlobal);if(bRead && (dwBytesRead==dwFileSize)) { LPSTREAM pstm = NULL; HRESULT hr = ::CreateStreamOnHGlobal(hGlobal, TRUE, &pstm); if(pstm) { LPPICTURE pPic = NULL; hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID\_IPicture, (LPVOID\*)&pPic); if(pPic) { // Retrieve logical dimensions long lWidth=0, lHeight=0; pPic->get\_Width(&lWidth); pPic->get\_Height(&lHeight); HDC hMemDC = CreateCompatibleDC(NULL); if(hMemDC) { // Map logical dimensions to physical device int nWidth = MulDiv(lWidth, GetDeviceCaps(hMemDC, LOGPIXELSX), HIMETRIC\_INCH); int nHeight = MulDiv(lHeight, GetDeviceCaps(hMemDC, LOGPIXELSY), HIMETRIC\_INCH); if((nWidth>=0) && (nHeight>=0)) { HDC dcScreen = GetDC(NULL); if(dcScreen) { HBITMAP hJpgBmp = ::CreateCompatibleBitmap(dcScreen, nWidth, nHeight); if(hJpgBmp) { HBITMAP hPrevBmp = (HBITMAP)::SelectObject(hMemDC, hJpgBmp); RECT rect = {0,0, nWidth,nHeight}; hr = pPic->Render(hMemDC, 0, 0, nWidth, nHeight, 0, lHeight, lWidth, -lHeight, &rect); ::SelectObject(hMemDC, hPrevBmp); if(SUCCEEDED(hr)) hBmp