Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Abstract Class, Socket Programming, JPEG in VC6

Abstract Class, Socket Programming, JPEG in VC6

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadmintutorial
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andy Rama
    wrote on last edited by
    #1

    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?

    C M L D 4 Replies Last reply
    0
    • A Andy Rama

      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?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      1 Reply Last reply
      0
      • A Andy Rama

        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?

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3
        1. 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."

        1 Reply Last reply
        0
        • A Andy Rama

          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?

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          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

          M 1 Reply Last reply
          0
          • L 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

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            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."

            1 Reply Last reply
            0
            • A Andy Rama

              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?

              D Offline
              D Offline
              DLChambers
              wrote on last edited by
              #6

              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
              
              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups