xkingpin
xkingpin

Reputation: 641

How do you free windows handle pointer in Delphi 7?

I am using a third party tool that is pointing to images in memory with a windows handle.

The tool stats that you are responsible for freeing handle. So how would you free that handle in Delphi 7? The datatype for the handle is LONG

Upvotes: 3

Views: 3047

Answers (2)

Rob Kennedy
Rob Kennedy

Reputation: 163357

If the tool tells you that you're responsible for cleaning up, then it should have also told you what you should use. Take a closer look at the documentation.

You need to be more specific about what kind of handle you have. There's no one function that frees all kinds of handles.

Most kernel objects (mutex objects, threads, processes, files, pipes, events, etc.) use CloseHandle.

If you really have an image handle, like HBitmap or HIcon, then you free with DeleteObject.

Window handles (HWND) are released with DestroyWindow.

You might have a memory handle, as returned by GlobalAlloc; use GlobalFree for that.

It might not be a Windows handle at all. It might be a handle specific to your tool's API that requires an API-specific function to destroy it.

The bottom line is that you need to know what you have.

Upvotes: 17

glob
glob

Reputation: 2960

Normally you'd use CloseHandle.

Upvotes: 4

Related Questions