⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ivisreg.cpp

📁 vc++与visio 安装VISIO office(推荐2003以上版本)必须安装visio office 否则程序无法运行 安装VisioSDK(推荐2003以上版本) 默认安装路径为<
💻 CPP
字号:
//	IVISREG.CPP - Helper functions for starting Visio
//	Copyright (C) Microsoft Corporation. All rights reserved.
//
//	<summary>
//	This source file contains helper functions for starting Visio and
//	getting access to the IVisioApplication interface.
//	</summary>
//
#include "StdAfx.h"
#include <windows.h>
#include <ole2.h>
#include "ivisreg.h"

#ifdef USE_VISIO_NAMESPACE
	#define CLSID_VisioApplication VisioNamespace::CLSID_Application
	#define IID_IVisioApplication VisioNamespace::IID_IVApplication
	namespace VisioNamespace
	{
		#include "visio_i.c"
	}
#else
	#define CLSID_VisioApplication CLSID_Application
	#define IID_IVisioApplication IID_IVApplication
	#include "visio_i.c"
#endif

static HRESULT stc_hrLast= NOERROR;

//	vaoGetVisioApp - Get an interface pointer for the active instance of the 
//	Visio application.
//
//	<summary>
//	This method attempts to retrieve the active instance of Visio if one is
//	running.
//	</summary>
//
//	Return Value:
//	short - A result code as defined in Ivisreg.h
//
static short vaoGetVisioApp(IVApplication **lplpIVApp)
{
	IUnknown *pUnk = NULL;

	(*lplpIVApp)= NULL;
	stc_hrLast= GetActiveObject(CLSID_VisioApplication, NULL, &pUnk);

	if (pUnk!=NULL)
	{
		pUnk->QueryInterface(IID_IVisioApplication, (void **) lplpIVApp);
		pUnk->Release();
		pUnk= NULL;
	}

	if ( NULL != (*lplpIVApp) )
		return VAO_GET;
	else
		return VAO_NOT_RUNNING;
}

//	vaoCreateVisioApp - Get an interface pointer for a new instance of the 
//	Visio application.
//
//	<summary>
//	This method attempts to create a new Visio application instance using the
//	proxy support interface.
//	</summary>
//
//	Return Value:
//	short - A result code as defined in Ivisreg.h
//
static short vaoCreateVisioApp(IVApplication **lplpIVApp)
{
	stc_hrLast= CoCreateInstance(CLSID_VisioApplication,
								 NULL,
								 CLSCTX_ALL,
								 IID_IVisioApplication,
								 (void **) lplpIVApp);

	if ( NULL != (*lplpIVApp) )
		return VAO_CREATE;
	else
		return VAO_ERROR;
}

//	vaoGetVisio - Get an interface pointer for an active instance or new 
//	instance of the Visio application.
//
//	<summary>
//	This function gets a Visio application interface by retrieving the active
//	instance, creating a new one or doing both if the user specifies.  If both
//	is specified, the function first tries to get the active instance and if this
//	fails then the function creates a new instance.
//	</summary>
//
//	Return Value:
//	short - A result code as defined in Ivisreg.h
//
#ifdef __cplusplus
extern "C" {
#endif

short vaoGetVisio(					//	VAO_ result code
	BOOL fActive,					//	TRUE => Get Active
	BOOL fCreate,					//	TRUE => Create New
	IVApplication **lplpIVApp)		//	Application Interface
{
	short sResult= VAO_ERROR;

	if ( !fActive && !fCreate )
		return sResult;

	if ( fActive )
		sResult = vaoGetVisioApp(lplpIVApp);

	if ( (VAO_GET != sResult) && fCreate )
		sResult = vaoCreateVisioApp(lplpIVApp);

	return sResult;
}

//	vaoGetObject - Get an interface for a Visio application instance
//
//	<summary>
//	This function attempts to get a running instance of Visio either by
//	getting the active instance or, if that fails, creating a new one.
//	</summary>
//
//	Return Value:
//	short - A result code as defined in Ivisreg.h
//
short vaoGetObject(					//	VAO_ result code
	IVApplication **lplpIVApp)		//	Visio App Interface
{
	short sResult = vaoGetVisio(TRUE, TRUE, lplpIVApp);

	if ( VAO_CREATE == sResult || VAO_GET == sResult )
		sResult = VAO_SUCCESS;

	return sResult;
}

//	vaoGetLastError - Returns the last error encountered by code in this source
//	file.
//
//	<summary>
//	This function returns the last error encountered by the code in this source 
//	file.  This function should be called immediately after the error occurs 
//	because future operations will reset the flag.
//	</summary>
//
//	Return Value:
//	HRESULT - NOERROR or some HRESULT error code
//
HRESULT vaoGetLastError()
{
	return stc_hrLast;
}

#ifdef __cplusplus
}
#endif



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -