GdiplusStartup函数

转载 2015年11月19日 11:56:13

GdiplusStartup function

3 out of 4 rated this helpful Rate this topic

Applies to: desktop apps only

The GdiplusStartup function initializes Windows GDI+. Call GdiplusStartup before making any other GDI+ calls, and call GdiplusShutdown when you have finished using GDI+.

函数用来初始化windows gdi+。在调用任何gdi+的函数之前,要先调用GdiplusStartup 

在用完之后,需要调用GdiplusShutdown 。

Syntax

Status GdiplusStartup(
  __out  ULONG_PTR token *token,
  __in   const GdiplusStartupInput *input,
  __out  GdiplusStartupOutput *output
);

Parameters

token [out]

Type: ULONG_PTR token*

Pointer to a ULONG_PTR that receives a token. Pass the token to GdiplusShutdown when you have finished using GDI+.

input [in]

Type: const GdiplusStartupInput*

Pointer to a GdiplusStartupInput structure that contains the GDI+ version, a pointer to a debug callback function, a Boolean value that specifies whether to suppress the background thread, and a Boolean value that specifies whether to suppress external image codecs.

output [out]

Type: GdiplusStartupOutput*

Pointer to a GdiplusStartupOutput structure that receives a pointer to a notification hook function and a pointer to a notification unhook function. If the SuppressBackgroundThread data member of the inputparameter is FALSE, then this parameter can be NULL.

Return value

Type:

Type: Status

If the function succeeds, it returns Ok, which is an element of the Status enumeration.

If the function fails, it returns one of the other elements of the Status enumeration.

Remarks

You must call GdiplusStartup before you create any GDI+ objects, and you must delete all of your GDI+ objects (or have them go out of scope) before you call GdiplusShutdown.

在调用gdiplusshutdown之前,一定要销毁gdi+的对象。这里的先后顺序很重要!! 这点是比较容易犯错误的。

很多时候我们在析构函数里销毁对象,对于全局的对象,析构函数的调用时间是在程序退出点,如果你在这之前就调用了gdiplusshutdown,那么你的程序

很容易在析构函数退出的时候报内存错误。

原因是应为gdi+的对象的内存是由他自己的堆来管理的。gdi对象的new和delete操作符都被重载过。


解决方法:

You can call GdiplusStartup on one thread and call GdiplusShutdown on another thread as long as you delete all of your GDI+ objects (or have them go out of scope) before you call GdiplusShutdown.

Do not call GdiplusStartup or GdiplusShutdown in DllMain or in any function that is called by DllMain. If you want to create a DLL that uses GDI+, you should use one of the following techniques to initialize GDI+:

  • Require your clients to call GdiplusStartup before they call the functions in your DLL and to callGdiplusShutdown when they have finished using your DLL.
  • Export your own startup function that calls GdiplusStartup and your own shutdown function that callsGdiplusShutdown. Require your clients to call your startup function before they call other functions in your DLL and to call your shutdown function when they have finished using your DLL.
  • Call GdiplusStartup and GdiplusShutdown in each of your functions that make GDI+ calls.

Warning  For info about how to use dynamic data exchange (DDE) with GDI+, see Special CWinApp Services.


Examples

For an example of calling GdiplusStartup and GdiplusShutdown in a Windows application, see Getting Started.

The following console application uses a GDI+Image object to retrieve the width and height of a JPEG image. The code calls GdiplusStartup before creating the Image object and calls GdiplusShutdown before terminating. Note that the Image object is deleted before the call to GdiplusShutdown.

In the following code, the variable gdiplusStartupInput is initialized by the default constructor of theGdiplusStartupInput structure. The default constructor sets the data members of the structure to the following values:

  • GdiplusVersion = 1
  • DebugEventCallback = NULL
  • SuppressBackgroundThread = FALSE
  • SuppressExternalCodecs = FALSE
#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;

INT main()
{
   GdiplusStartupInput gdiplusStartupInput;
   ULONG_PTR gdiplusToken;
   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

   Image* image = new Image(L"FakePhoto.jpg");
   printf("The width of the image is %u.\n", image->GetWidth());
   printf("The height of the image is %u.\n", image->GetHeight()); 

   delete image;
   GdiplusShutdown(gdiplusToken);
   return 0;
}

相关文章推荐

GdiplusStartup函数

GdiplusStartup function 3 out of 4 rated this helpful Rate this topic Applies to: desk...

GdiplusStartup API函数的介绍

GdiplusStartup(token, input, output) The GdiplusStartup 作用是初始化GDI+函数库. CallGdiplusStartup before ma...

新唐mini58的函数说明

  • 2017年11月16日 10:25
  • 383KB
  • 下载

Linux内核--网络协议栈深入分析(二)--sk_buff的操作函数

本文分析基于Linux Kernel 3.2.1 原创作品,转载请标明http://blog.csdn.net/yming0221/article/details/7972647 更多请查...
  • avrmcu1
  • avrmcu1
  • 2014年06月19日 09:40
  • 473

JS函数式编程-Functional JavaScript

  • 2017年11月12日 13:34
  • 8.46MB
  • 下载

halcon函数

  • 2017年11月01日 17:30
  • 118KB
  • 下载

python学习之路-基础篇-函数-day03

一.函数的基本语法和特性 1.定义一个函数三要素 1)使用关键字def 2)参数表 3)返回值return python中参数表和返回值不是必须要写的,是一个可选项 以下就是一个函数的简单...

EXCEL函数例子大全

  • 2017年11月17日 11:52
  • 507KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:GdiplusStartup函数
举报原因:
原因补充:

(最多只允许输入30个字)