|
MAIN.CPP (BROWSEH OLE Sample)
/*************************************************************************
-
- OLE Automation TypeLibrary Browse Helper Sample
-
- main.cpp
-
- new and delete operator redefinition to use memory manager of calling
- task.
- LibMain, WEP, DllGetClassObject, DllCanUnloadNow, DLL initialization.
- Procedure to create standard dispatch implementation.
-
- Written by Microsoft Product Support Services, Windows Developer Support
- (c) Copyright Microsoft Corp. 1994 All Rights Reserved
-
- ***********************************************************************/
#include <windows.h>
#include <windowsx.h>
#ifdef WIN16
#include <ole2.h>
#include <compobj.h>
#include <dispatch.h>
#include <variant.h>
#include <olenls.h>
#endif
#include <initguid.h>
#include "browseh.h"
// Globals
HINSTANCE g_hinst; // Instance of application
//Count number of objects and number of
locks.
ULONG g_cObj=0;
ULONG g_cLock=0;
// String resource buffers
TCHAR g_szServerName[STR_LEN];
/*
* new
*
* Purpose:
* Since this is an InProcServer object, the memory allocator used by
* the calling task must be used.
* This is done by redefining the global new operator and using new
* for all memory allocations.
*/
- oid FAR* operator new(size_t size)
{
IMalloc FAR* pMalloc;
LPVOID lpv;
if (CoGetMalloc(MEMCTX_TASK, &pMalloc) == NOERROR)
{
lpv = pMalloc->Alloc(size);
pMalloc->Release();
return lpv;
}
return NULL;
}
/*
* delete
*
* Purpose:
* Use the memory manager of the calling task to free memory.
*/
- oid operator delete(void FAR* lpv)
{
IMalloc FAR* pMalloc;
if (lpv == NULL) return;
if( CoGetMalloc(MEMCTX_TASK, &pMalloc) == NOERROR)
{
if (pMalloc->DidAlloc(lpv))
pMalloc->Free(lpv);
pMalloc->Release();
}
}
#ifdef WIN16
/*
* LibMain
*
* Purpose:
* Called by Win16 on DLL load. Does any one-time initializations.
*
*/
int PASCAL LibMain (HINSTANCE hinst, WORD wDataSeg, WORD cbHeapSize, LPSTR
lpCmdLine)
{
if (cbHeapSize != 0)
UnlockData(0);
g_hinst = hinst;
if (!InitDLL(hinst))
return FALSE;
return TRUE;
}
/*
* WEP
*
* Purpose:
* Called by Windows on DLL unload.
*
*/
extern "C" void FAR PASCAL _WEP(int bSystemExit)
{
return;
}
#else //Win 32
BOOL WINAPI DllMain (HINSTANCE hinst, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
if (!InitDLL(hinst))
return FALSE;
else return TRUE;
default:
return TRUE;
}
}
#endif
/*
* DLLGetClassObject
*
* Purpose:
* OLE calls this funtion to obtain the class factory. Note that the class
* factory is not registered by the inproc server.
*
*/
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid,
LPVOID FAR *ppv)
{
LPCLASSFACTORY pcf;
HRESULT hr;
*ppv = NULL;
// Check if this CLSID is supported.
if (rclsid != CLSID_BrowseHelper)
return ResultFromScode(E_FAIL);
// Create class factory and return it
pcf = new CBrowseHelperCF;
if (!pcf)
return ResultFromScode(E_OUTOFMEMORY);
hr = pcf->QueryInterface(riid, ppv);
if (FAILED(hr))
{
delete pcf;
return hr;
}
return NOERROR;
}
/*
* DLLCanUnloadNow
*
* Purpose:
* DllCanUnloadNow is called by OLE to determine if the DLL can be unloded.
*
*/
STDAPI DllCanUnloadNow(void)
{
if (g_cObj==0L && g_cLock==0L)
return ResultFromScode(S_OK);
else return ResultFromScode(S_FALSE);
}
/*
* InitDLL
*
* Purpose:
* Load strings & Registers the window class
*
* Parameters:
* hinstance hinstance of application
*
*/
BOOL InitDLL (HINSTANCE hinst)
{
return LoadString(hinst, IDS_SERVERNAME, g_szServerName,
sizeof(g_szServerName));
}
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|