На главную

On-line справка по Win32 API

Написать письмо
БЕСПЛАТНАЯ ежедневная online лотерея! Выигрывай каждый день БЕСПЛАТНО!
Список всех статей A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z | Скачать Вниз

String Management



To carry out a DDE task, many DDEML functions require access to strings. For example, a client must specify a service name and a topic name when it calls the DdeConnect function to request a conversation with a server. An application specifies a string by passing a string handle (HSZ) rather than a pointer in a DDEML function. A string handle is a doubleword value, assigned by the system, that identifies a string.

An application can obtain a string handle for a particular string by calling the DdeCreateStringHandle function. This function registers the string with the system and returns a string handle to the application. The application can pass the handle to DDEML functions that must access the string. The following example obtains string handles for the System topic string and the service name string.

HSZ hszServName;
HSZ hszSysTopic;
.
.
.
hszServName = DdeCreateStringHandle(
idInst, /* instance identifier */
"MyServer", /* string to register */
CP_WINANSI); /* Windows ANSI code page */

hszSysTopic = DdeCreateStringHandle(
idInst, /* instance identifier */
SZDDESYS_TOPIC, /* System topic */
CP_WINANSI); /* Windows ANSI code page */
.
.
.


The idInst parameter in the preceding example specifies the instance identifier obtained by the DdeInitialize function.
An application's DDE callback function receives one or more string handles during most DDE transactions. For example, a server receives two string handles during the XTYP_REQUEST transaction: one identifies a string specifying a topic name, and the other identifies a string specifying an item name. An application can obtain the length of the string that corresponds to a string handle and copy the string to an application-defined buffer by calling the DdeQueryString function, as shown in the following example.

DWORD idInst;
DWORD cb;
HSZ hszServ;
PSTR pszServName;
.
.
.
cb = DdeQueryString(idInst, hszServ, (LPSTR) NULL, 0,
CP_WINANSI) + 1;
pszServName = (PSTR) LocalAlloc(LPTR, (UINT) cb);
DdeQueryString(idInst, hszServ, pszServName, cb, CP_WINANSI);
.
.
.


An instance-specific string handle cannot be mapped from string handle to string and back to string handle. For instance, although DdeQueryString creates a string from a string handle and then DdeCreateStringHandle creates a string handle from that string, the two handles are not the same, as shown in the following example.

DWORD idInst;
DWORD cb;
HSZ hszInst, hszNew;
PSZ pszInst;
.
.
.
DdeQueryString(idInst, hszInst, pszInst, cb, CP_WINANSI);
hszNew = DdeCreateStringHandle(idInst, pszInst, CP_WINANSI);
/* hszNew != hszInst ! */
.
.
.


To compare the values of two string handles, use the DdeCmpStringHandles function.
A string handle passed to an application's DDE callback function becomes invalid when the callback function returns. An application can save a string handle for use after the callback function returns by using the DdeKeepStringHandle function.
When an application calls DdeCreateStringHandle, the system enters the specified string into a string table and generates a handle that it uses to access the string. The system also maintains a usage count for each string in the string table.

When an application calls DdeCreateStringHandle and specifies a string that already exists in the table, the system increments the usage count rather than adding another occurrence of the string. (An application can also increment the usage count by using DdeKeepStringHandle.) When an application calls the DdeFreeStringHandle function, the system decrements the usage count.
A string is removed from the table when its usage count equals zero. Because more than one application can obtain the handle of a particular string, an application must not free a string handle more times than it has created or retained the handle. Otherwise, the application can cause the string to be removed from the table, denying other applications access to the string.

The DDEML string-management functions are based on the Windows atom manager and are subject to the same size restrictions as are atoms.


Пригласи друзей и счет твоего мобильника всегда будет положительным!
Предыдущая статья
 
Сайт Народ.Ру Интернет
Следующая статья
Пригласи друзей и счет твоего мобильника всегда будет положительным!

Управление Строки



Для того, чтобы выполнять задачу DDE, много функции DDEML требуют доступ к строкам. Например, клиент должен определить имя услуги и имя темы когда он называет функцию DdeConnect, чтобы запрашивать разговор с сервером. Приложение определяет строку передавая ручку строки (HSZ) а не указатель в функции DDEML. Ручка строки является величиной двойного слова, назначенной системой, которая идентифицирует строку.

Приложение может получить ручку строки для конкретной строки вызывая функцию DdeCreateStringHandle. Эта функция регистрирует строку с системой и возвращает ручку строки в приложение. Приложение может передать ручку в функции DDEML, которые должны иметь доступ к строке. Следующий пример получает ручкам строки для строки темы Системы и строка имени услуги.

HSZ hszServName;
HSZ hszSysTopic;
.
.
.
hszServName = DdeCreateStringHandle( idInst, /* ИДЕНТИФИКАТОР примера */ "MyServer", /* строка, чтобы регистрироваться */ CP_WINANSI); /* Кодовая страница Windows ANSI */

hszSysTopic = DdeCreateStringHandle( idInst, /* ИДЕНТИФИКАТОР примера */ SZDDESYS_TOPIC, /* тема Системы */ CP_WINANSI); /* Кодовая страница Windows ANSI */
.
.
.


Параметр idInst в предыдущем примере определяет идентификатор примера полученный функцией DdeInitialize.
Прикладная функция возврата DDE получает одно или более нанизывать ручки в течение большинства сделок DDE. Например, сервер получает два нанизывать ручки в течение сделки XTYP_REQUEST: один идентифицирует строку, определяющую имя темы, и другой идентифицирует строку, определяющую имя пункта. Приложение может получить длину строки, которая переписывается в ручку строки и копирует строку в определенный прикладной буфер вызывая функцию DdeQueryString, как показано в следующем примере.

DWORD idInst;
cb DWORD;
HSZ hszServ;
PSTR pszServName;
.
.
.
cb = DdeQueryString(idInst, hszServ, (LPSTR) НЕДЕЙСТВИТЕЛЬНЫЙ, 0, CP_WINANSI) + 1;
pszServName = (PSTR) LocalAlloc(LPTR, (UINT) cb);
DdeQueryString(idInst, hszServ, pszServName, cb, CP_WINANSI);
.
.
.


Пример-специфическая ручка строки не может быть отображена из ручки строки, чтобы нанизывать и, чтобы нанизывать ручку. Например, хотя DdeQueryString создает строку из ручки строки и затем DdeCreateStringHandle создает ручку строки из этой строки, две ручки - не тот же, как показано в следующем примере.

DWORD idInst;
cb DWORD;
HSZ hszInst, hszNew;
PSZ pszInst;
.
.
.
DdeQueryString(idInst, hszInst, pszInst, cb, CP_WINANSI);
hszNew = DdeCreateStringHandle(idInst, pszInst, CP_WINANSI);
/* hszNew != hszInst! */
.
.
.


Для того, чтобы сравнивать величины двух ручек строки, используйте функцию DdeCmpStringHandles.
Ручка строки пройденная в прикладную функцию возврата DDE становится инвалидом когда функция возврата возвращается. Приложение может сохранить строке ручку для использования после того, как функция возврата возвращает используя функцию DdeKeepStringHandle.
Когда приложение называет DdeCreateStringHandle, система вводит определенную строку в таблицу строки и генерирует ручку, которую она использует, чтобы иметь доступ к строке. Система также поддерживается, использование имеет значение каждую строку в таблице строки.

Когда приложение называет DdeCreateStringHandle и определяет строку, которая уже существует в таблице, система увеличивает счет использования а не добавляя другой случай строки. ( Приложение может также увеличить счет использования используя DdeKeepStringHandle.) Когда приложение называет функцию DdeFreeStringHandle, системные декременты счет использования.
Строка удалена из таблицы когда счет использования равняется нуль. Поскольку более, чем одно приложение может получить ручку конкретной строки, приложение не должно освобождать ручке строки более время чем это создало или удерживало ручку. В противном случае, приложение может вызвать строку, которая нужно удаляться из таблицы, запрещать других приложений имеет доступ к строке.

Строка-управление функций DDEML основана на менеджере атома Windows и подвергнуться тому же размеру ограничений что - атомы.


Вверх Version 1.3, Oct 26 2010 © 2007, 2010, mrhx Вверх
 mrhx software  Русский перевод OpenGL  Русский перевод Win32 API
 
Используются технологии uCoz