• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 900
  • Last Modified:

Creating SSL Socket

Dear Friends,

    I would like to know if it is possible to create a SSL connection oriented Socket using Visual Basic 6.0 or Visual C++ 6.0, I think it can be done using SChannel but till now i could'nt find any samples on that though i found one for HTTPS protocol.

   Any solution with a sample would be greatly appreciated.

   Thanking you in advance

1 Solution
Do you want to create an MFC project?
In reading MSN, this doesn't seem to be something that you would to via C++/VB.

The following info comes from MSN docs:
Securing HTTP Transmissions (SSL)
SSL (Secure Sockets Layer) is a protocol that is used to protect HTTP transmissions from unwanted eavesdropping. Visual InterDev supports the optional use of SSL over the client/server link at design time and when performing a Web Copy operation. You can also use SSL during run time. You choose to use an SSL connection when you create a new Web project or initiate a Web Copy operation.

When an SSL connection is in use, all HTTP requests and replies are encrypted before transmission and decrypted after receipt. This process does require additional time and slows performance.

Except for this encryption/decryption step, all Visual InterDev operations take place exactly as they would over a non-SSL connection. You must obtain and install an SSL certificate on your Web server before you can initiate an SSL connection. For more information on obtaining and installing an SSL certificate on an Internet Information Server, see Securing Your Site Against Intruders in the Internet Information Server documentation.

It's quite possible, I've done it a while back. MSDN has an example (or actually, the platform SDK does...).
You should be aware though that SChannel isn't easy to use (SSPI in general is hard) and it may be just a lot simpler to use WinInet.
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tommy HuiEngineerCommented:
Yes, it is possible. Here's sample code in C++ using WinInet:

#include <windows.h>
#include <tchar.h>
#include <wininet.h>
#include <stdio.h>
#include <string>

#import "msxml.dll"
using namespace MSXML;

using namespace std;

#pragma comment(lib, "wininet.lib")

TComInitialize g_ComInit;

int _tmain(int argc, _TCHAR* argv[], _TCHAR* envp[])
     if (argc < 1)
          _tprintf(_T("Failed to find arguments.\n"));
          return -1;

     HINTERNET hSession = InternetOpen(_T("HttpGet"),

     if (hSession)
          bool isSsl = false;

          for (int i = 1; i < argc; i++)
               if (strcmpi(argv[i], "-s") == 0)
                    isSsl = true;

               HINTERNET hFile = InternetOpenUrl(hSession, argv[i], NULL, 0,
                                                         isSsl ? INTERNET_FLAG_SECURE : 0, 0);
               if (hFile)
                    DWORD bytesAvailable = 0;
                    if (InternetQueryDataAvailable(hFile, &bytesAvailable, 0, 0))
                         _tprintf(_T("Bytes available: %d\n"), bytesAvailable);

                    const int BUFFLEN = 1024;
                    TCHAR buffer[BUFFLEN];
                    DWORD dwRead;
                    string result;

                    while (InternetReadFile(hFile, buffer, BUFFLEN - sizeof(TCHAR), &dwRead))
                         if (dwRead == 0)

                         buffer[dwRead / sizeof(TCHAR)] = _T('\0');
                         result += buffer;

                    _tprintf(_T("%s\n"), argv[i]);
                    _tprintf(_T("%s\n"), result.c_str());

     return 0;

Run the program with -s to use secure or not.

For example,

  httpget http://www.microsoft.com

to see Microsoft's web page. Or

  httpget -s {path starting with https://)

to retrieve the secured web page.
ArvindtnAuthor Commented:
 I want to have it as a COM component not as a MFC Project

  Iam using a TCP socket and iam not using the HTTP protocol. I think SSL in SCHannel is supported only in Windows 2000 and Windows NT.

  This what i have done so far, i have created a Socket in Visual Basic and i take full advantage of the event model it gives me. when i want to do some processing on the message i receive from the client socket, i pass the message with the Socket handle to Visual C++ which in turn process the message in a thread and sends the processed message back to the client through the socket handle in Visual C++. Now the problem is in having a SSL

  I think i have found the solution.
i have found a site which provides me an Activex dll which enables me to have a SSL over a Socket. Check this Site out www.nsoftware.com iam yet to test it and see if it is working for me.

  I would really like to write the establishing SSL over TCP Socket on my own as part of my self development and i like to use the existing code for my project.

   So kindly send me if it is ok to use the activex, for which i have provided the link above or to implement it through SChannel.

Thank you in Advance
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and PAQ at zero points.

The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

This dormant question will be placed in PAQ.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now