home *** CD-ROM | disk | FTP | other *** search
- //
- // client.cpp
- //
- // Copyright (c) 1999, Microsoft Corporation. All rights reserved.
- //
- // This source files demonstrates using a custom class object of a COM object
- // implemented in Java.
- //
-
- #include <stdio.h>
- #include <windows.h>
- #include <olectl.h>
-
- void main(int argc, char *argv[])
- {
- HRESULT hr;
- CLSID clsid;
- IUnknown *punk;
- IClassFactory2 *pFactory2;
- BSTR bstrKey;
-
- hr = CoInitialize(NULL);
-
- if (hr == S_OK) {
-
- hr = CLSIDFromString(L"sample.CustomClassObjectDemo", &clsid);
-
- if (hr == S_OK) {
-
- // Attempt to create an instance of the object. This should fail
- // because we're not "licensed" to create the Java object.
- hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_IUnknown,
- (LPVOID *) &punk);
-
- if (hr == S_OK) {
- printf("successfully called CoCreateInstance\n");
- punk->Release();
- } else if (hr == CLASS_E_NOTLICENSED) {
- printf("failed to CoCreateInstance object as expected (hr=CLASS_E_NOTLICENSED)\n");
- } else {
- printf("failed to CoCreateInstance object (hr=%08x)\n", hr);
- }
-
- hr = CoGetClassObject(clsid, CLSCTX_ALL, NULL, IID_IClassFactory2,
- (LPVOID *) &pFactory2);
-
- if (hr == S_OK) {
-
- hr = pFactory2->RequestLicKey(0, &bstrKey);
-
- if (hr == S_OK) {
-
- hr = pFactory2->CreateInstanceLic(NULL, NULL, IID_IUnknown,
- bstrKey, (LPVOID *) &punk);
-
- if (hr == S_OK) {
- printf("successfully called CreateInstanceLic\n");
- punk->Release();
- } else {
- printf("failed call to CreateInstanceLic (hr=%08x)\n", hr);
- }
-
- SysFreeString(bstrKey);
-
- } else {
- printf("failed to get license key (hr=%08x)\n", hr);
- }
-
- pFactory2->Release();
-
- } else {
- printf("failed to get class object (hr=%08x)\n", hr);
- }
-
- } else {
- printf("failed to convert progid to clsid (hr=%08x)\n", hr);
- }
-
- CoUninitialize();
- }
- }
-