Mswinsck.ocx and runtime licensing 
Author Message
 Mswinsck.ocx and runtime licensing

I'm using the .ocx as a automation server like this:

Private WithEvents m_wsListen As Winsock

creating it,

    Set m_wsListen = New Winsock

All is well on any computer with Visual Studio, but no computer without it
can create the object. I've done the same thing in a C++ ATL project, and
supplied the runtime key like this:

CoGetClassObject(__uuidof(Winsock), CLSCTX_ALL, NULL, IID_IClassFactory2,
(void**) &pCF
pCF->CreateInstanceLic(NULL, NULL, IID_IUnknown, bstrLicKey, (void**)&pUnk
m_pWinSock = pUnk;
DispEventAdvise(m_pWinSock);

How do I supply the runtime key in Visual Basic, if this is indeed the
problem?

Thanks,

Dale



Tue, 30 Dec 2003 03:23:57 GMT  
 Mswinsck.ocx and runtime licensing
Yes, the licence is missing from the registry. You can simulate exact
behavior of C++ in VB using API calls and a custom type library that defines
IClassFactory2 interface. But there is a simpler way to create control
instances at runtime using Load statement and control arrays. Create a
hidden form and place WinSock control on it. This will force VB to include
runtime licence into executable file. Then set control's Index property to
zero. This will tell VB that you are going to use single control as a contol
array. Then use Load(newIndex) statement to create a new control instance
and Unload(oldIndex) when you no longer need it. Your event procedures will
look like this:

Private Sub Winsock1_Connect(Index As Integer)
  ...
End Sub

Regards,
Dmitriy Zakharov.
Brainbench MVP for Visual Basic
http://www.brainbench.com



Quote:
> I'm using the .ocx as a automation server like this:

> Private WithEvents m_wsListen As Winsock

> creating it,

>     Set m_wsListen = New Winsock

> All is well on any computer with Visual Studio, but no computer without it
> can create the object. I've done the same thing in a C++ ATL project, and
> supplied the runtime key like this:

> CoGetClassObject(__uuidof(Winsock), CLSCTX_ALL, NULL, IID_IClassFactory2,
> (void**) &pCF
> pCF->CreateInstanceLic(NULL, NULL, IID_IUnknown, bstrLicKey, (void**)&pUnk
> m_pWinSock = pUnk;
> DispEventAdvise(m_pWinSock);

> How do I supply the runtime key in Visual Basic, if this is indeed the
> problem?

> Thanks,

> Dale



Tue, 30 Dec 2003 16:16:26 GMT  
 Mswinsck.ocx and runtime licensing
Sure, I'm aware of the hidden form and control array stuff, and have used
it; however, this specific app is an .exe server with no visual objects,
all functionality is in classes that may get split up into separate servers
later, and I really want to avoid the overhead of a Form if possible.

You mentioned API calls in your response; using the API viewer, I can't find
CoGetClassObject or CreateInstanceLic. So, how would you do this in Visual
Basic?

Thanks,

Dale


Quote:
> Yes, the licence is missing from the registry. You can simulate exact
> behavior of C++ in VB using API calls and a custom type library that
defines
> IClassFactory2 interface. But there is a simpler way to create control
> instances at runtime using Load statement and control arrays. Create a
> hidden form and place WinSock control on it. This will force VB to include
> runtime licence into executable file. Then set control's Index property to
> zero. This will tell VB that you are going to use single control as a
contol
> array. Then use Load(newIndex) statement to create a new control instance
> and Unload(oldIndex) when you no longer need it. Your event procedures
will
> look like this:

> Private Sub Winsock1_Connect(Index As Integer)
>   ...
> End Sub

> Regards,
> Dmitriy Zakharov.
> Brainbench MVP for Visual Basic
> http://www.brainbench.com



> > I'm using the .ocx as a automation server like this:

> > Private WithEvents m_wsListen As Winsock

> > creating it,

> >     Set m_wsListen = New Winsock

> > All is well on any computer with Visual Studio, but no computer without
it
> > can create the object. I've done the same thing in a C++ ATL project,
and
> > supplied the runtime key like this:

> > CoGetClassObject(__uuidof(Winsock), CLSCTX_ALL, NULL,
IID_IClassFactory2,
> > (void**) &pCF
> > pCF->CreateInstanceLic(NULL, NULL, IID_IUnknown, bstrLicKey,
(void**)&pUnk
> > m_pWinSock = pUnk;
> > DispEventAdvise(m_pWinSock);

> > How do I supply the runtime key in Visual Basic, if this is indeed the
> > problem?

> > Thanks,

> > Dale



Tue, 30 Dec 2003 21:26:29 GMT  
 Mswinsck.ocx and runtime licensing
Right you are, API viewer cannot help with CoGetClassObject and
CreateInstanceLic. What would you say about using a custom type library?
Compile and reference the IDL below in this message you will be able to
write code like this:

Const IID_IClassFactory2 As String =
"{B196B28F-BAB4-101A-B69C-00AA00341D07}"
Const IID_IUnknown As String = "{00000000-0000-0000-C000-000000000046}"

Dim pFactory As IClassFactory2
Set pFactory = CoGetClassObject(CLSIDFromProgID("MSWinsock.Winsock"),
enuCLSCTX_ALL, 0, IIDFromString(IID_IClassFactory2))

Dim sLicKey  As String
sLicKey = pFactory.RequestLicKey(0)

Dim o As Object
Set o = pFactory.CreateInstanceLic(Nothing, Nothing,
IIDFromString(IID_IUnknown), sLicKey)

Regards,
Dmitriy Zakharov.
Brainbench MVP for Visual Basic
http://www.brainbench.com

======== Type Library Source (IDL) - Begin Cut Here ============

#define STDMETHODCALLTYPE       __stdcall
#define STDMETHODVCALLTYPE      __cdecl

#define STDAPICALLTYPE          __stdcall
#define STDAPIVCALLTYPE         __cdecl

#define EXTERN_C    extern
#define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE

[
  uuid(237D0C8A-86FD-4729-A7F1-CE9070898C2B),
  version(1.0),
  helpstring("OCIDL Type Library 1.0")
]
library OCIDL
{
 interface IClassFactory2;

 typedef enum enuCLSCTX
 {
  enuCLSCTX_INPROC_SERVER    = 1,
  enuCLSCTX_INPROC_HANDLER   = 2,
  enuCLSCTX_LOCAL_SERVER     = 4,
  enuCLSCTX_REMOTE_SERVER    = 16,
  enuCLSCTX_NO_CODE_DOWNLOAD = 400,
  enuCLSCTX_NO_FAILURE_LOG = 4000,
  enuCLSCTX_SERVER    = (1 | 4 | 16),
  enuCLSCTX_ALL       = (2 | 1)
 } CLSCTX;

 typedef struct VB_GUID
 {
  LONG  Data[4];
 } VB_GUID;

 [
  uuid(1BB1ED6D-3D5D-40ff-82A4-EB68D0A74269),
  helpstring("OLE Automation Functions"),
  dllname("OLE32.DLL")
 ]
 module OleAPI
 {

  [
   usesgetlasterror,
   entry("CoGetClassObject"),
   helpstring(""),
  ]
  STDAPI CoGetClassObject(
    VB_GUID* rclsid,  //CLSID associated with the class object
    LONG dwClsContext,
       //Context for running executable code
    LONG pServerInfo,
       //Pointer to machine on which the object is to
       // be instantiated
    VB_GUID* riid,      //Reference to the identifier of the interface
    [out, retval] IUnknown** ppv      //Address of output variable that
receives the
       // interface pointer requested in riid
  );

  [
   usesgetlasterror,
   entry("CLSIDFromProgID"),
   helpstring(""),
  ]
  HRESULT CLSIDFromProgID(
    LPCOLESTR lpszProgID,  //Pointer to the ProgID
    [out, retval] VB_GUID* pclsid         //Pointer to the CLSID
  );

  [
   usesgetlasterror,
   entry("IIDFromString"),
   helpstring(""),
  ]
  STDAPI IIDFromString(
    LPOLESTR lpsz,  //Pointer to the string representation of the IID
    [out, retval] VB_GUID* lpiid     //Pointer to the requested IID on
return
  );

 }

 [
  object,
  uuid(B196B28F-BAB4-101A-B69C-00AA00341D07),
  pointer_default(unique)
 ]

 interface IClassFactory2 : IClassFactory
 {
  typedef IClassFactory2 * LPCLASSFACTORY2;

  typedef struct tagLICINFO {
   LONG cbLicInfo;
   BOOL fRuntimeKeyAvail;
   BOOL fLicVerified;
  } LICINFO;

  typedef struct tagLICINFO * LPLICINFO;

  HRESULT GetLicInfo(
     [out, retval] LICINFO * pLicInfo
    );

  HRESULT RequestLicKey(
     [in] LONG dwReserved,
     [out, retval] BSTR * pBstrKey
    );

  [local]
  HRESULT CreateInstanceLic(
     [in] IUnknown * pUnkOuter,
     [in] IUnknown * pUnkReserved,
     [in] VB_GUID* riid,
     [in] BSTR bstrKey,
     [out, retval, iid_is(riid)] IUnknown ** ppvObj
    );

 }

Quote:
}

======= Type Library Source (IDL) - End  Cut Here ==========



Quote:
> Sure, I'm aware of the hidden form and control array stuff, and have used
> it; however, this specific app is an .exe server with no visual objects,
> all functionality is in classes that may get split up into separate
servers
> later, and I really want to avoid the overhead of a Form if possible.

> You mentioned API calls in your response; using the API viewer, I can't
find
> CoGetClassObject or CreateInstanceLic. So, how would you do this in Visual
> Basic?

> Thanks,

> Dale



> > Yes, the licence is missing from the registry. You can simulate exact
> > behavior of C++ in VB using API calls and a custom type library that
> defines
> > IClassFactory2 interface. But there is a simpler way to create control
> > instances at runtime using Load statement and control arrays. Create a
> > hidden form and place WinSock control on it. This will force VB to
include
> > runtime licence into executable file. Then set control's Index property
to
> > zero. This will tell VB that you are going to use single control as a
> contol
> > array. Then use Load(newIndex) statement to create a new control
instance
> > and Unload(oldIndex) when you no longer need it. Your event procedures
> will
> > look like this:

> > Private Sub Winsock1_Connect(Index As Integer)
> >   ...
> > End Sub

> > Regards,
> > Dmitriy Zakharov.
> > Brainbench MVP for Visual Basic
> > http://www.brainbench.com



> > > I'm using the .ocx as a automation server like this:

> > > Private WithEvents m_wsListen As Winsock

> > > creating it,

> > >     Set m_wsListen = New Winsock

> > > All is well on any computer with Visual Studio, but no computer
without
> it
> > > can create the object. I've done the same thing in a C++ ATL project,
> and
> > > supplied the runtime key like this:

> > > CoGetClassObject(__uuidof(Winsock), CLSCTX_ALL, NULL,
> IID_IClassFactory2,
> > > (void**) &pCF
> > > pCF->CreateInstanceLic(NULL, NULL, IID_IUnknown, bstrLicKey,
> (void**)&pUnk
> > > m_pWinSock = pUnk;
> > > DispEventAdvise(m_pWinSock);

> > > How do I supply the runtime key in Visual Basic, if this is indeed the
> > > problem?

> > > Thanks,

> > > Dale



Thu, 01 Jan 2004 00:11:21 GMT  
 Mswinsck.ocx and runtime licensing
Please try
Q194751 - FILE: VB6Cli.exe Fixes License Problems with Visual Basic 6.0 at
http://support.microsoft.com/support/kb/articles/Q194/7/51.ASP

Regards,



Fri, 02 Jan 2004 19:51:05 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Licensing mswinsck.ocx?

2. Licensing Issues with mswinsck.ocx and others...

3. MSWINSCK.OCX Not Licensed????

4. Licensing VBSQL.OCX for using it in runtime

5. Licensing VBSQL.OCX for using it in runtime

6. MSINET.OCX and MSWINSCK.OCX....Please help!

7. MsWinsck.ocx

8. mswinsck.ocx

9. Using MSWinsck.ocx on a web page

10. MSWINSCK.OCX

11. mswinsck.ocx

12. Blue Screen of Death/MSWINSCK.OCX Hell

 

 
Powered by phpBB® Forum Software