Automation provides a way to expose and access objects within an application in a late bound way. Automation defines the following dispatch interfaces and functions.
IDispatch()
interface--Exposes objects,
methods, and properties to Automation programming tools and other applications.
Dispatch API functions--Simplifies the implementation
of the
IDispatch()
interface.
Use these functions to generate
an
IDispatch()
interface automatically.
IEnumVARIANT
interface--Provides a
way for COM clients to iterate over collection objects.
This is a dispatch
interface.
The following table describes the member functions of the
IDispatch()
interface.
Interface |
Member function |
Purpose |
IDispatch()
|
GetIDsOfNames
|
Maps a single member name and an optional
set of argument names to a corresponding set of integer dispatch identifiers
(DISPID s), which can then be used on subsequent calls to
Invoke .
|
GetTypeInfo
|
Retrieves the type information for an object. | |
GetTypeInfoCount
|
Retrieves the number of type information interfaces that an object provides (either 0 or 1). | |
Invoke
|
Provides access to properties and methods exposed by an object. |
IDispatch()
is located in the Oleauto.h header file
on 32-bit systems, and in Dispatch.h on 16-bit systems.
ActiveX or COM objects can implement the
IDispatch()
interface for access by ActiveX clients, such as Visual Basic.
The object's
properties and methods can be accessed using
IDispatch::GetIDsOfNames()
and
IDispatch::Invoke()
.
The following examples show how to access a COM object through the
IDispatch()
interface.
The code is abbreviated for brevity, and omits
error handling.
// Declarations of variables used. DEFINE_GUID(CLSID_Hello, // Portions omitted for brevity. HRESULT hresult;IUnknown()
* punk;IDispatch()
* pdisp; OLECHAR FAR* szMember = ``SayHello''; DISPID dispid; DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; EXCEPINFO excepinfo; UINT nArgErr;
In the following code, the
OleInitialize
function
loads the COM dynamic-link libraries (DLLs), and the
CoCreateInstance()
function initializes the COM object'
s class
factory.
// Initialize OLE DLLs.
hresult = OleInitialize(NULL);
// OLE function CoCreateInstance()
starts application using GUID.
hresult = CoCreateInstance(CLSID_Hello, NULL, CLSCTX_SERVER, IID_IUnknown, \
(void FAR* FAR*)&punk);
QueryInterface()
checks whether the object supports
IDispatch()
.
(As with any call to
QueryInterface()
,
the returned pointer must be released when it is no longer needed.)
// CallQueryInterface()
to see if object supportsIDispatch()
. hresult = punk->QueryInterface(IID_IDispatch, &pdisp);
GetIDsOfNames
retrieves the
DISPID
for the indicated method or property, in this case,
szMember
.
// Retrieve the dispatch identifier for the SayHello method. // Use defaults where possible. hresult = pdisp->GetIDsOfNames( IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid);
In the following call to
Invoke
, the
DISPID
indicates the property or method to invoke.
The
SayHello
method does not take any parameters, so the fifth argument (&dispparamsNoArgs), contains a
NULL
and
0, as initialized at declaration.
To invoke a property or method that requires parameters, supply the
parameters in the
DISPPARAMS
structure.
// Invoke the method. Use defaults where possible. hresult = pdisp->Invoke( dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &dispparamsNoArgs, NULL, NULL, NULL);
These functions let you identify a running instance of an object.
When an application is started with the
/Automation
switch on its command-line, it should initialize its Application object as
the active object by calling
RegisterActiveObject()
.
Applications can also register other top-level objects as the active object. For example, an application that exposes a Document object may want to let COM clients retrieve and modify the currently active document.
The National Language Support (NLS) functions provide support for applications that use multiple locales at one time, especially applications that support Automation. Locale information is passed to allow the application to interpret both the member names and the argument data in the proper locale context. The information in this appendix applies only to 16-bit Windows systems.
Implemented by |
Used by |
Header filename |
Import library name |
Ole2nls.dll |
Applications that support multiple national languages | Olenls.h |
Ole2nls.lib |
For Automation, applications need to get locale information and to compare and transform strings into the proper format for each locale.
A locale is simply user-preference information, represented as a list of values describing the user's language and sublanguage. National language support incorporates several disparate definitions of a locale into one coherent model. This model is designed to be general enough at a low level to support multiple, distinct, high-level functions, such as the ANSI C locale functions.
A code page is the mapping between character glyphs (shapes) and the 1-byte or 2-byte numeric values that are used to represent them. Microsoft Windows uses one of several code pages, depending on the installed localized version of Windows. For example, the Russian version uses code page 1251 (Cyrillic), while the English U.S. and Western European versions use code page 1252 (Multilingual). For historical reasons, the Windows code page in effect is referred to as the ANSI code page.
Because only one code page is in effect at a time, it is impossible for a computer running English U.S. Windows to display or print data correctly from the Cyrillic code page. The fonts do not contain the Cyrillic characters. However, it can still manipulate the characters internally, and they will display correctly again if moved back to a machine running Russian Windows.
All NLS functions use the locale identifier (LCID) to identify which code page a piece of text is assumed to lie in. For example, when returning locale information (such as month names) for Russian, the returned string can be meaningfully displayed in the Cyrillic code page only, because other code pages do not contain the appropriate characters. Similarly, when attempting to change the case of a string with the Russian locale, the case-mapping rules assume the characters are in the Cyrillic code page.
These functions can be divided into two categories.
String transformation--NLS functions support uppercasing, lowercasing, generating sort keys (all locale-dependent), and getting string type information.
Locale manipulation--NLS functions return information about installed locales for use in string transformations.
The following table lists the NLS functions.
Function |
Purpose |
CompareString() |
Compares two strings of the same locale. |
LCMapString() |
Transforms the case or sort order of a string. |
GetLocaleInfo() |
Retrieves locale information from the user's system. |
GetStringType() |
Retrieves locale type information about each character in a string. |
GetSystemDefaultLangID() |
Retrieves the default language ID (LANGID) from a user's system. |
GetSystemDefaultLCID() |
Retrieves the default LCID from a user's system. |
GetUserDefaultLangID() |
Retrieves the default LANGID from a user's system. |
GetUserDefaultLCID() |
Retrieves the default LCID from a user's system. |
An application may expose a set of objects whose members have names
that differ across localized versions of a product.
This poses a problem for
programming languages that want to access such objects, because it means that
late binding is sensitive to the locale of the application.
The
IDispatch()
and virtual function table (VTBL) interfaces allow software
developers a range of solutions that vary in cost of implementation and quality
of national language support.
All methods of the
IDispatch()
interface that are potentially sensitive to language are passed an LCID.
Following are some of the possible approaches a class implementation may take:
Accept any LCID and use the same member names in all locales. This is acceptable if the interface will typically be accessed only by advanced users. For example, the member names for COM interfaces will never be localized.
Simply return an error (DISP_E_UNKNOWNLCID
)
if the caller's LCID doesn't match the localized version of the class.
This
would prevent users from being able to write late-bound code which runs on
machines with different localized implementations of the class.
Recognize the particular version's localized names, as well as one language that is recognized in all versions. For example, a French version might accept French and English names, where English is the language supported in all versions. This would constrain users to use English when writing code that runs in all countries,.
Accept all LCIDs supported by all versions of the product.
This means that the implementation of
GetIDsOfNames
would
need to interpret the passed array of names based on the given LCID.
This
is the preferred solution because users would be able to write code in their
national language and run the code on any localized version of the application.
At the very least, the application must check the LCID before interpreting
member names.
Also note that the meaning of parameters passed to a member
function may depend on the caller's national language.
For example, a spreadsheet
application might interpret the arguments to a
SetFormula
method differently, depending on the LCID.
The
IDispatch
interface uses the 32-bit Windows definition
of a LCID to identify locales.
An LCID is a
DWORD
value
that contains the
LANGID
in the lower word and a reserved
value in the upper word.
This LCID has the components necessary to uniquely identify one of the installed system-defined locales.
/* * LCID creation/extraction macros: * MAKELCID - construct locale ID from language ID and country code. */ #define MAKELCID(l) ((DWORD)(((WORD)(l))|(((DWORD)((WORD)(0))) << 16)))
There are two predefined LCID values.
LOCALE_SYSTEM_DEFAULT
is the system default locale, and
LOCALE_USER_DEFAULT
is the current user's locale.
However, when querying the NLS APIs
for information, it is more efficient to query once for the current locale
with
GetSystemDefaultLCID()
or
GetUserDefaultLCID()
, rather than using these constants.
A
LANGID
is a 16-bit value that is the combination
of a primary and sublanguage ID.
Macros are provided for constructing a
LANGID
and extracting the fields.
LANGID
creation/extraction macros include:
MAKELANGID
- construct
LANGID
from primary LANGID and sublanguage ID.
PRIMARYLANGID
- extract primary
LANGID
from a LANGID.
SUBLANGID
- extract sublanguage identifier
(ID) from a
LANGID
.
LANGIDFROMLCID
- get the LANGID from an
LCID.
#define MAKELANGID(p, s) ((((USHORT)(s)) << 10) | (USHORT)(p)) #define PRIMARYLANGID(lgid) ((USHORT)(lgid) & 0x3ff) #define SUBLANGID(lgid) ((USHORT)(lgid) >> 10) #define LANGIDFROMLCID(lcid) ((WORD)(lcid))
The following three combinations of primary and sublanguage IDs have special meanings:
PRIMARYLANGID |
SUBLANGID |
Meaning |
LANG_NEUTRAL |
SUBLANG_NEUTRAL |
Language neutral |
LANG_NEUTRAL |
SUBLANG_SYS_DEFAULT |
System default language |
LANG_NEUTRAL |
SUBLANG_DEFAULT |
User default language |
For primary language IDs, the range 0x200 to 0x3ff is user definable.
The range 0x000 to 0x1ff is reserved for system use.
The following table lists
the primary
LANGID
s supported by Automation:
Language
|
PRIMARYLANGID
|
Neutral | 0x00 |
Chinese | 0x04 |
Czech | 0x05 |
Danish | 0x06 |
Dutch | 0x13 |
English | 0x09 |
Finnish | 0x0b |
French | 0x0c |
German | 0x07 |
Greek | 0x08 |
Hungarian | 0x0e |
Icelandic | 0x0F |
Italian | 0x10 |
Japanese | 0x11 |
Korean | 0x12 |
Norwegian | 0x14 |
Polish | 0x15 |
Portuguese | 0x16 |
Russian | 0x19 |
Serbo Croatian | 0x1a |
Slovak | 0x1b |
Spanish | 0x0a |
Swedish | 0x1d |
Turkish | 0x1F |
For sublanguage IDs, the range 0x20 to 0x3f is user definable. The range 0x00 to 0x1f is reserved for system use. The following table lists the sublanguage IDs supported by Automation:
Sublanguage
|
SUBLANGID
|
Neutral | 0x00 |
Default | 0x01 |
System Default | 0x02 |
Chinese (Simplified) | 0x02 |
Chinese (Traditional) | 0x01 |
Dutch | 0x01 |
Dutch (Belgian) | 0x02 |
English (U.S.) | 0x01 |
English (U.K.) | 0x02 |
English (Australian) | 0x03 |
English (Canadian) | 0x04 |
English (Irish) | 0x06 |
English (New Zealand) | 0x05 |
French | 0x01 |
French (Belgian) | 0x02 |
French (Canadian) | 0x03 |
French (Swiss) | 0x04 |
German | 0x01 |
German (Swiss) | 0x02 |
German (Austrian) | 0x03 |
Greek | 0x01 |
Icelandic | 0x01 |
Italian | 0x01 |
Italian (Swiss) | 0x02 |
Japanese | 0x01 |
Korean | 0x01 |
Norwegian (Bokmal) | 0x01 |
Norwegian (Nynorsk) | 0x02 |
Portuguese | 0x02 |
Portuguese (Brazilian) | 0x01 |
Serbo Croatian (Latin) | 0x01 |
Spanish (Castilian)1 | 0x01 |
Spanish (Mexican) | 0x02 |
Spanish (Modern) (See note below) | 0x03 |
Turkish | 0x01 |
The only difference between Spanish (Castilian) and Spanish (Modern) is the sort ordering. All of the
LCType
values are the same.
An
LCTYPE
is a constant that specifies a particular
piece of locale information.
For example:
typedef DWORD LCTYPE;
The list of supported
LCTYPES
follows.
All values
are null-terminated, variable-length strings.
Numeric values are expressed
as strings of decimal digits, unless otherwise noted.
The values in the brackets
indicate the maximum number of characters allowed for the string (including
the null termination).
If no maximum is indicated, the string may be of variable
length.
Constant name
|
Description
|
LOCALE_ILANGUAGE |
A
LANGID
represented in
hexadecimal digits.
See the previous sections.
[5] |
LOCALE_SLANGUAGE |
The full localized name of the language. |
LOCALE_SENGLANGUAGE |
The full English U.S. name of the language from the ISO Standard 639. This will always be restricted to characters that can be mapped into the ASCII 127-character subset. |
LOCALE_SABBREVLANGNAME |
The abbreviated name of the language, created by taking the two-letter language abbreviation, as found in ISO Standard 639, and adding a third letter as appropriate to indicate the sublanguage. |
LOCALE_SNATIVELANGNAME |
The native name of the language. |
LOCALE_ICOUNTRY |
The country code, based on international phone codes, also referred to as IBM country codes. [6] |
LOCALE_SCOUNTRY |
The full localized name of the country. |
LOCALE_SENGCOUNTRY |
The full English U.S. name of the country. This will always be restricted to characters that can be mapped into the ASCII 127-character subset. |
LOCALE_SABBREVCTRYNAME |
The abbreviated name of the country as found in ISO Standard 3166. |
LOCALE_SNATIVECTRYNAME |
The native name of the country. |
LOCALE_IDEFAULTLANGUAGE |
LANGID
for the principal
language spoken in this locale.
This is provided so that partially specified
locales can be completed with default values.
[5] |
LOCALE_IDEFAULTCOUNTRY |
Country code for the principal country in this locale. This is provided so that partially specified locales can be completed with default values. [6] |
LOCALE_IDEFAULTANSICODEPAGE |
The ANSI code page associated with this locale.Format: 4 Unicode decimal digits plus a Unicode null terminator. [10] [6] |
LOCALE_IDEFAULTCODEPAGE |
The OEM code page associated with the country. [6] |
LOCALE_SLIST |
Characters used to separate list items. For example, a comma is used in many locales. |
LOCALE_IMEASURE |
This value is 0 for the metric system (S.I.) and 1 for the U.S. system of measurements. [2] |
LOCALE_SDECIMAL |
Characters used for the decimal separator. |
LOCALE_STHOUSAND |
Characters used as the separator between groups of digits left of the decimal. |
LOCALE_SGROUPING |
Sizes for each group of digits to the left
of the decimal.
An explicit size is required for each group.
Sizes are separated
by semicolons.
If the last value is 0, the preceding value is repeated.
To
group thousands, specify
3;0 .
|
LOCALE_IDIGITS |
The number of fractional digits. [3] |
LOCALE_ILZERO |
Whether to use leading zeros in decimal fields. [2] A setting of 0 means use no leading zeros; 1 means use leading zeros. |
LOCALE_SNATIVEDIGITS |
The ten characters that are the native equivalent of the ASCII 0-9. |
LOCALE_INEGNUMBER |
Negative number mode. [2] 0 (1.1) 1 -1.1 2 -1.1 3 1.1 4 1.1 |
LOCALE_SCURRENCY |
The string used as the local monetary symbol. |
LOCALE_SINTLSYMBOL |
Three characters of the International monetary symbol specified in ISO 4217, Codes for the Representation of Currencies and Funds, followed by the character separating this string from the amount. |
LOCALE_SMONDECIMALSEP |
Characters used for the monetary decimal separators. |
LOCALE_SMONTHOUSANDSEP |
Characters used as monetary separator between groups of digits left of the decimal. |
LOCALE_SMONGROUPING |
Sizes for each group of monetary digits to
the left of the decimal.
An explicit size is needed for each group.
Sizes
are separated by semicolons.
If the last value is 0, the preceding value is
repeated.
To group thousands, specify
3;0 .
|
LOCALE_ICURRDIGITS |
Number of fractional digits for the local monetary format. [3] |
LOCALE_IINTLCURRDIGITS |
Number of fractional digits for the international monetary format. [3] |
LOCALE_ICURRENCY |
Positive currency mode. [2] 0 Prefix, no separation.1 Suffix, no separation.2 Prefix, 1-character separation.3 Suffix, 1-character separation. |
LOCALE_INEGCURR |
Negative currency mode. [2] 0 ($1.1) 1 -$1.1 2 $-1.1 3 $1.1- 4 $(1.1$) 5 -1.1$ 6 1.1-$ 7 1.1$- 8 -1.1 $ (space before $) 9 -$ 1.1 (space after $) 10 1.1 $- (space before $) |
LOCALE_ICALENDARTYPE |
The type of calendar currently in use. [2] 1 Gregorian (as in U.S.) 2 Gregorian (always English strings) 3 Era: Year of the Emperor (Japan) 4 Era: Year of the Republic of China 5 Tangun Era (Korea) |
LOCALE_IOPTIONALCALENDAR |
The additional calendar types available for this LCID. Can be a null-separated list of all valid optional calendars. [2] 0 None available 1 Gregorian (as in U.S.) 2 Gregorian (always English strings) 3 Era: Year of the Emperor (Japan) 4 Era: Year of the Republic of China 5 Tangun Era (Korea) |
LOCALE_SDATE |
Characters used for the date separator. |
LOCALE_STIME |
Characters used for the time separator. |
LOCALE_STIMEFORMAT |
Time-formatting string. [80] |
LOCALE_SSHORTDATE |
Short Date_Time formatting strings for this locale. |
LOCALE_SLONGDATE |
Long Date_Time formatting strings for this locale. |
LOCALE_IDATE |
Short Date format-ordering specifier. [2] 0 Month - Day - Year 1 Day - Month - Year 2 Year - Month - Day |
LOCALE_ILDATE |
Long Date format ordering specifier. [2] 0 Month - Day - Year 1 Day - Month - Year 2 Year - Month - Day |
LOCALE_ITIME |
Time format specifier. [2] 0 AM/PM 12-hour format. 1 24-hour format. |
LOCALE_ITIMEMARKPOSN |
Whether the time marker string (AM|PM) precedes or follows
the time string.
(The registry value is named
ITimePrefix
for previous Far East version compatibility.) 0 Suffix (9:15 AM).
1 Prefix
(AM 9:15).
|
LOCALE_ICENTURY |
Whether to use full 4-digit century. [2] 0 Two digit. 1 Full century. |
LOCALE_ITLZERO |
Whether to use leading zeros in time fields. [2] 0 No leading zeros. 1 Leading zeros for hours. |
LOCALE_IDAYLZERO |
Whether to use leading zeros in day fields. [2] 0 No leading zeros. 1 Leading zeros. |
LOCALE_IMONLZERO |
Whether to use leading zeros in month fields. [2] 0 No leading zeros. 1 Leading zeros. |
LOCALE_S1159 |
String for the AM designator. |
LOCALE_S2359 |
String for the PM designator. |
LOCALE_IFIRSTWEEKOFYEAR |
Specifies which week of the year is considered first. [2] 0 Week containing 1/1 is the first week of the year. 1 First full week following 1/1is the first week of the year. 2 First week with at least 4 days is the first week of the year. |
LOCALE_IFIRSTDAYOFWEEK |
Specifies the day considered first in the
week.
[2] 0
SDAYNAME1
1
SDAYNAME2
2
SDAYNAME3
3
SDAYNAME4
4
SDAYNAME5
5
SDAYNAME6
6
SDAYNAME7 |
LOCALE_SDAYNAME1 |
Long name for Monday. |
LOCALE_SDAYNAME2 |
Long name for Tuesday. |
LOCALE_SDAYNAME2 |
Long name for Tuesday. |
LOCALE_SDAYNAME3 |
Long name for Wednesday. |
LOCALE_SDAYNAME4 |
Long name for Thursday. |
LOCALE_SDAYNAME5 |
Long name for Friday. |
LOCALE_SDAYNAME6 |
Long name for Saturday. |
LOCALE_SDAYNAME7 |
Long name for Sunday. |
LOCALE_SABBREVDAYNAME1 |
Abbreviated name for Monday. |
LOCALE_SABBREVDAYNAME2 |
Abbreviated name for Tuesday. |
LOCALE_SABBREVDAYNAME3 |
Abbreviated name for Wednesday. |
LOCALE_SABBREVDAYNAME4 |
Abbreviated name for Thursday. |
LOCALE_SABBREVDAYNAME5 |
Abbreviated name for Friday. |
LOCALE_SABBREVDAYNAME6 |
Abbreviated name for Saturday. |
LOCALE_SABBREVDAYNAME7 |
Abbreviated name for Sunday. |
LOCALE_SMONTHNAME1 |
Long name for January. |
LOCALE_SMONTHNAME2 |
Long name for February. |
LOCALE_SMONTHNAME3 |
Long name for March. |
LOCALE_SMONTHNAME4 |
Long name for April. |
LOCALE_SMONTHNAME5 |
Long name for May. |
LOCALE_SMONTHNAME6 |
Long name for June. |
LOCALE_SMONTHNAME7 |
Long name for July. |
LOCALE_SMONTHNAME8 |
Long name for August. |
LOCALE_SMONTHNAME9 |
Long name for September. |
LOCALE_SMONTHNAME10 |
Long name for October. |
LOCALE_SMONTHNAME11 |
Long name for November. |
LOCALE_SMONTHNAME12 |
Long name for December. |
LOCALE_SMONTHNAME13 |
Native name for 13th month, if it exists. |
LOCALE_SABBREVMONTHNAME1 |
Abbreviated name for January. |
LOCALE_SABBREVMONTHNAME2 |
Abbreviated name for February. |
LOCALE_SABBREVMONTHNAME3 |
Abbreviated name for March. |
LOCALE_SABBREVMONTHNAME4 |
Abbreviated name for April. |
LOCALE_SABBREVMONTHNAME5 |
Abbreviated name for May. |
LOCALE_SABBREVMONTHNAME6 |
Abbreviated name for June. |
LOCALE_SABBREVMONTHNAME7 |
Abbreviated name for July. |
LOCALE_SABBREVMONTHNAME8 |
Abbreviated name for August. |
LOCALE_SABBREVMONTHNAME9 |
Abbreviated name for September. |
LOCALE_SABBREVMONTHNAME10 |
Abbreviated name for October. |
LOCALE_SABBREVMONTHNAME11 |
Abbreviated name for November. |
LOCALE_SABBREVMONTHNAME12 |
Abbreviated name for December. |
LOCALE_SABBREVMONTHNAME13 |
Native abbreviated name for 13th month, if it exists. |
LOCALE_SPOSITIVESIGN |
String value for the positive sign. |
LOCALE_SNEGATIVESIGN |
String value for the negative sign. |
LOCALE_IPOSSIGNPOSN |
Formatting index for positive values. [2] 0 Parentheses surround the amount and the monetary symbol. 1 The sign string precedes the amount and the monetary symbol. 2 The sign string precedes the amount and the monetary symbol. 3 The sign string precedes the amount and the monetary symbol. 4 The sign string precedes the amount and the monetary symbol. |
LOCALE_INEGSIGNPOSN |
Formatting index for negative values. [2] 0 Parentheses surround the amount and the monetary symbol. 1 The sign string precedes the amount and the monetary symbol. 2 The sign string precedes the amount and the monetary symbol. 3 The sign string precedes the amount and the monetary symbol. 4 The sign string precedes the amount and the monetary symbol. |
LOCALE_IPOSSYMPRECEDES |
If the monetary symbol precedes, 1. If it succeeds a positive amount, 0. [2] |
LOCALE_IPOSSEPBYSPACE |
If the monetary symbol is separated by a space from a positive amount, 1. Otherwise, 0. [2] |
LOCALE_INEGSYMPRECEDES |
If the monetary symbol precedes, 1. If it succeeds a negative amount, 0. [2] |
LOCALE_INEGSEPBYSPACE |
If the monetary symbol is separated by a space from a negative amount, 1. Otherwise, 0. [2] |
The following table shows the equivalence between
LCTYPE
values and the information stored in the [intl] section of
Win.ini
.
These values are retrieved from
Win.ini
if
information for the current system locale is queried.
Values for
LCTYPE
s that are not in the following table do not depend on information
stored in
Win.ini
.
Win.ini settings
|
LCTYPE
|
sLanguage
(See note below) |
LOCALE_SABBREVLANGNAME |
ICountry |
LOCALE_ICOUNTRY |
SCountry |
LOCALE_SCOUNTRY |
SList |
LOCALE_SLIST |
IMeasure |
LOCALE_IMEASURE |
SDecimal |
LOCALE_SDECIMAL |
SThousand |
LOCALE_STHOUSAND |
IDigits |
LOCALE_IDIGITS |
ILZero |
LOCALE_ILZERO |
SCurrency |
LOCALE_SCURRENCY |
ICurrDigits |
LOCALE_ICURRDIGITS |
ICurrency |
LOCALE_ICURRENCY |
INegCurr |
LOCALE_INEGCURR |
SDate |
LOCALE_SDATE |
STime |
LOCALE_STIME |
SShortDate |
LOCALE_SSHORTDATE |
SLongDate |
LOCALE_SLONGDATE |
IDate |
LOCALE_IDATE |
ITime |
LOCALE_ITIME |
ITLZero |
LOCALE_ITLZERO |
s1159 |
LOCALE_S1159 |
s2359 |
LOCALE_S2359 |
Unlike in
Win.ini
, values returned byLOCALE_SABBREVLANGNAME
are always in uppercase.
- Maps a single member and an optional set of argument names to
a corresponding set of integer
IDispatch::GetIDsOfNames()
DISPID
s.
HRESULT GetIDsOfNames(
#include <Oaidl.h>
REFIID riid,
OLECHAR FAR * FAR * rgszNames,
unsigned int cNames,
LCID lcid,
DISPID FAR * rgDispId
);
Maps a single member and an optional set of argument names to a corresponding
set of integer
DISPID
s, which can be used on subsequent
calls to
IDispatch::Invoke()
.
The dispatch function
DispGetIDsOfNames()
provides a standard implementation of
GetIDsOfNames
.
An
IDispatch()
implementation can associate any positive
integer ID value
with a given name.
Zero is reserved for the default, or
Value
property;
-1 is reserved to indicate an unknown name; and other negative values are
defined for other purposes.
For example, if
GetIDsOfNames
is called, and
the implementation does not recognize one or more of the names, it returns
DISP_E_UNKNOWNNAME
, and the
rgDispId
array contains
DISPID_UNKNOWN
for
the entries that correspond to the unknown names.
The member and parameter
DISPID
s must remain constant
for the lifetime of the
object.
This allows a client to obtain the
DISPID
s once,
and cache them for
later use.
When
GetIDsOfNames
is called with more than one name,
the first name
(rgszNames[0]) corresponds to the member name, and subsequent
names
correspond to the names of the member's
parameters.
The same name may map to different
DISPID
s, depending
on context.
For example,
a name may have a
DISPID
when it is used as a member name
with a particular
interface, a different ID as a member of a different interface, and different
mapping for each time it appears as a parameter.
The
IDispatch()
interface binds to names at run time.
To bind at compile
time instead, an
IDispatch()
client can map names to
DISPID
s by
using the type information interfaces described in
Chapter 18.
This allows a client to
bind to members at compile time and avoid calling
GetIDsOfNames
at run
time.
For a description of binding at compile time, see
Section
Section 18.1.
The implementation of
GetIDsOfNames
is case insensitive.
Users that need
case-sensitive name mapping should use type information interfaces to map
names
to
DISPID
s, rather than call
GetIDsOfNames
.
Reserved for future use.
Must be
IID_NULL
.
Passed-in array of names to be mapped.
Count of the names to be mapped.
The locale context in which to interpret the names.
Caller-allocated array, each element of which contains an identifier (ID) corresponding to one of the names passed in the rgszNames array. The first element represents the member name. The subsequent elements represent each of the member's parameters.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
DISP_E_UNKNOWNNAME
One or more of the names were not known.
The returned array
of
DISPID
s contains
DISPID_UNKNOWN
for
each entry
that corresponds to an unknown name.
DISP_E_UNKNOWNLCID
The locale identifier (LCID) was not recognized.
The following code from the Lines sample file Lines.cpp implements the
GetIDsOfNames
member function for the CLine class.
The
COM
object uses the standard implementation,
DispGetIDsOfNames()
.
STDMETHODIMP CLine::GetIDsOfNames( REFIID riid, OLECHAR FAR* FAR* rgszNames, UINT cNames, LCID lcid, DISPID FAR* rgDispId) { return DispGetIDsOfNames(m_ptinfo, rgszNames, cNames, rgDispId); }
The following code might appear in an ActiveX client that calls
GetIDsOfNames
to get the
DISPID
of the
CLine Color
property.
HRESULT hresult;IDispatch()
FAR* pdisp = (IDispatch()
FAR*)NULL; DISPID dispid; OLECHAR FAR* szMember = ``color''; // Code that sets a pointer to the dispatch (pdisp) is omitted. hresult = pdisp->GetIDsOfNames( IID_NULL, &szMember, 1, LOCALE_SYSTEM_DEFAULT, &dispid);
CreateStdDispatch()
,
DispGetIDsOfNames()
,
ITypeInfo::GetIDsOfNames
- Retrieves the type information for an object, which can then be
used to get the type information for an interface.
IDispatch::GetTypeInfo()
HRESULT GetTypeInfo(
#include <Oaidl.h>
unsigned int iTInfo,
LCID lcid,
ITypeInfo FAR * FAR * ppTInfo
);
The type information to return.
Pass 0 to retrieve type information
for the
IDispatch()
implementation.
The locale identifier for the type information. An object may be able to return different type information for different languages. This is important for classes that support localized member names. For classes that do not support localized member names, this parameter can be ignored.
Receives a pointer to the requested type information object.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success; the type information element exists.
DISP_E_BADINDEX
Failure; iTInfo argument was not 0.
TYPE_E_ELEMENTNOTFOUND
Failure; iTInfo argument was not 0.
Retrieves the type information for an object, which can then be used to get the type information for an interface.
The following code from the sample file Lines.cpp loads information
from the
type library and implements the member function
GetTypeInfo
:
// These lines are from CLines::Create load type information for the
// Lines collection from the type library.
hr = LoadTypeInfo(&pLines->m_ptinfo, IID_ILines);
if (FAILED(hr))
goto error;
// Additional code omitted for brevity.
// This function implements GetTypeInfo for the CLines collection.
STDMETHODIMP
CLines::GetTypeInfo(
UINT iTInfo,
LCID lcid,
ITypeInfo()
FAR* FAR* ppTInfo)
{
*ppTInfo = NULL;
if(iTInfo != 0)
return ResultFromScode(DISP_E_BADINDEX);
m_ptinfo->AddRef();
*ppTInfo = m_ptinfo;
return NOERROR;
}
CreateStdDispatch, CreateDispTypeInfo
.
- Retrieves the number of type information interfaces that an object
provides (either 0 or 1).
IDispatch::GetTypeInfoCount()
HRESULT GetTypeInfoCount(
#include <Oaidl.h>
unsigned int FAR * pctinfo
);
Retrieves the number of type information interfaces that an object provides (either 0 or 1).
The function may return zero, which indicates that the object does not
provide
any type information.
In this case, the object may still be programmable
through
IDispatch()
, but does not provide type information
for browsers,
compilers, or other programming tools that access type information.
This can
be
useful for hiding an object from browsers or for preventing early binding
on an
object.
Points to a location that receives the number of type information interfaces provided by the object. If the object provides type information, this number is 1; otherwise the number is 0.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_NOTIMPL
Failure.
This code from the Lines sample file Lines.cpp implements the
GetTypeInfoCount
member function for the
CLines
class (ActiveX or
OLE object).
STDMETHODIMP CLines::GetTypeInfoCount(UINT FAR* pctinfo) { *pctinfo = 1; return NOERROR; }
- Provides access to properties and methods exposed by an object.
IDispatch::Invoke()
HRESULT Invoke(
DISPID dispIdMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS FAR * pDispParams,
VARIANT FAR * pVarResult,
EXCEPINFO FAR * pExcepInfo,
unsigned int FAR * puArgErr
);
Provides access to properties and methods exposed by an object.
The
dispatch
function
DispInvoke()
provides a standard implementation
of
IDispatch::Invoke()
.
Generally, you should not implement
Invoke
directly.
Instead, use the
dispatch interface create functions
CreateStdDispatch()
and
DispInvoke()
.
For details, refer to
CreateStdDispatch
and
DispInvoke
in this chapter, and Section
Section 19.1.1.
If some application-specific processing needs to be performed before
calling a
member, the code should perform the necessary actions, and then call
ITypeInfo::Invoke()
to invoke the member.
ITypeInfo::Invoke()
acts exactly like
IDispatch::Invoke()
.
The standard implementations
of
IDispatch::Invoke()
created by
CreateStdDispatch()
and
DispInvoke
defer to
ITypeInfo::Invoke()
.
In an ActiveX client,
IDispatch::Invoke()
should
be used to get and set
the values of properties, or to call a method of an ActiveX object.
The
dispIdMember
argument identifies the member to invoke.
The
DISPID
s that
identify members are defined by the implementor of the object and can be
determined by using the object's
documentation, the
IDispatch::GetIDsOfNames()
function,
or the
ITypeInfo()
interface.
The information that follows addresses developers of ActiveX clients and others who use code to expose ActiveX objects. It describes the behavior that users of exposed objects should expect.
Invoke
returns
DISP_E_MEMBERNOTFOUND
if one of the following
conditions occurs:
A member or parameter with the specified
DISPID
and matching
cArgs
cannot be found,
and the parameter
is not optional.
The member is a void function, and the caller did not set
pVarResult
to
NULL
.
The member is a read-only property, and the caller set
wFlags
to
DISPATCH_PROPERTYPUT
or
DISPATCH_PROPERTYPUTREF
.
If
Invoke
finds the member, but uncovers errors in
the argument
list, it returns one of several other errors.
DISP_E_BAD_PARAMCOUNT means
that
the
DISPPARAMS
structure contains an incorrect number of
parameters for the
property or method.
DISP_E_NONAMEDARGS
means that
Invoke
received named
arguments, but they are not supported by the member.
DISP_E_PARAMNOTFOUND
means that the correct number
of parameters was passed,
but the
DISPID
for one or more parameters was incorrect.
If
Invoke
cannot convert one of the arguments to the desired
type, it returns
DISP_E_TYPEMISMATCH
.
In these two cases, if it can identify
which argument is
incorrect,
Invoke
sets *puArgErr
to
the index within
rgvarg
of the argument with the error.
For example, if
an Automation
method expects a reference to a double-precision number as an argument, but
receives a reference to an integer, the argument is coerced.
However, if the
method receives a date,
IDispatch::Invoke()
returns
DISP_E_TYPEMISMATCH
and sets
*puArgErr
to the index of the integer in the
argument array.
Automation provides functions to perform standard conversions of
VARIANT
, and
these functions should be used for consistent operation.
DISP_E_TYPEMISMATCH
is
returned only when these functions fail.
When you implement
IDispatch::Invoke,
errors can
be communicated
either through the normal return value or by raising an exception.
An exception
is a special situation that is normally handled by jumping to the nearest
routine enclosing the exception handler.
To raise an exception,
IDispatch::Invoke()
returns
DISP_E_EXCEPTION
and
fills the structure passed through
pExcepInfo
with information
about the
cause of the exception or error.
You can use the information to understand
the
cause of the exception and proceed as necessary.
The exception information structure includes an error code number that identifies the kind of exception (a string that describes the error in a human-readable way). It also includes a Help file and a Help context number that can be passed to Windows Help for details about the error. At a minimum, the error code number must be filled with a valid number.
If you consider
IDispatch()
another way to call C++
methods in an
interface,
EXCEPINFO
models the raising of an exception
or
longjmp()
call by such a method.
When you invoke indexed properties of any dimension, you must pass the
indexes as additional arguments.
To set an indexed property, place the
new value in the first element of the
rgvarg[ ] vector,
and the indexes
in the subsequent elements.
To get an indexed property, pass the indexes in
the
first
n
elements of
rgvarg, and
the number of indexes in
cArg.Invoke
returns the value of the
property in
pVarResult.
Automation stores array data in column-major order, which is the same
ordering
scheme used by Visual Basic and FORTRAN, but different from C, C++, and Pascal.
If you are programming in C, C++, or Pascal, you must pass the indexes in
the
reverse order.
The following example shows how to fill the
DISPPARAMS
structure
in C++.
dispparams.rgvarg[0].vt = VT_I2; dispparams.rgvarg[0].iVal = 99; dispparams.rgvarg[1].vt = VT_I2; dispparams.rgvarg[1].iVal = 2; dispparams.rgvarg[2].vt = VT_I2; dispparams.rgvarg[2].iVal = 1; dispparams.rgdispidNamedArgs = DISPID_PROPERTYPUT; dispparams.cArgs = 3; dispparams.cNamedArgs = 1;
The example changes the value of Prop[1,2] to 99.
The new property value
is passed
in
rgvarg[0].
The right-most index is passed in
rgvarg[1]
, and
the next index in
rgvarg[2]
.
The
cArgs
field specifies
the number of elements of
rgvarg[ ]
that contain data,
and
cNamedArgs
is
1
, indicating the new
value for the property.
Property collections are an extension of this feature.
Arguments to the method or property being invoked are passed in the
DISPPARAMS
structure.
This structure consists of a pointer
to an array of
arguments represented as variants, a pointer to an array of
DISPID
s for named
arguments, and the number of arguments in each array.
typedef struct FARSTRUCT tagDISPPARAMS{ VARIANTARG FAR* rgvarg; // Array of arguments. DISPID FAR* rgdispidNamedArgs; // Dispatch IDs of named arguments. unsigned int cArgs; // Number of arguments. unsigned int cNamedArgs; // Number of named arguments. } DISPPARAMS;
The arguments are passed in the array
rgvarg[ ],
with the number of
arguments passed in
cArgs.
The arguments in the array
should be
placed from last to first, so
rgvarg[0] has the last
argument and
rgvarg[cArgs
-1] has the first
argument.
The method or property
may change the values of elements within the array
rgvarg,
but only if
it has set the
VT_BYREF
flag.
Otherwise, consider the elements
as
read-only.
A dispatch invocation can have named arguments as well as positional
arguments.
If
cNamedArgs
is 0, all the elements of
rgvarg[ ] represent
positional arguments.
If
cNamedArgs
is not 0, each element
of
rgdispidNamedArgs[ ] contains the
DISPID
of a named argument, and the
value of the argument is in the matching element of
rgvarg[
].
The
DISPID
s of the named arguments are always contiguous in
rgdispidNamedArgs, and their values are in the first
cNamedArgs
elements of
rgvarg.
Named arguments cannot be accessed
positionally, and
positional arguments cannot be named.
The
DISPID
of an argument is its zero-based position
in the argument list.
For
example, the following method takes three arguments.
BOOL _export CDECL CCredit::CheckCredit(BSTR bstrCustomerID, // DISPID = 0. BSTR bstrLenderID, // DISPID = 1. CURRENCY cLoanAmt) // DISPID = 2. { // Code omitted. }
If you include the
DISPID
with each named argument,
you can pass the named
arguments to
Invoke
in any order.
For example, if a method
is to be
invoked with two positional arguments, followed by three named arguments (A,
B,
and
C), using the following hypothetical
syntax, then
cArgs
would be 5, and
cNamedArgs
would be 3.
object.method("arg1", "arg2", A := "argA", B := "argB", C := "argC")
The first positional argument would be in
rgvarg[4].
The second
positional argument would be in
rgvarg[3].
The ordering
of named
arguments is not important to the
IDispatch()
implementation,
but these
arguments are generally passed in reverse order.
The argument
A
would be
in
rgvarg[2], with the
DISPID
of
A
in
rgdispidNamedArgs[2].
The argument
B
would be in
rgvarg[1], with the corresponding
DISPID
in
rgdispidNamedArgs[1].
The argument
C
would be in
rgvarg[0], with the
DISPID
corresponding
to
C
in
rgdispidNamedArgs[0].
You can also use
Invoke
on members with optional arguments,
but all
optional arguments must be of type
VARIANT
.
As with required
arguments, the
contents of the argument vector depend on whether the arguments are positional
or named.
The invoked member must ensure that the arguments are valid.
Invoke
merely passes the
DISPPARAMS
structure it receives.
Omitting named arguments is straightforward.
You would pass the arguments
in
rgvarg
and their
DISPID
s in
rgdispidNamedArgs.
To omit the
argument named
B
(in the preceding example) you would
set
rgvarg[0] to the value of
C, with
its
DISPID
in
rgdispidNamedArgs[0]; and
rgvarg[1]
to the value of
A,
with its
DISPID
in
rgdispidNamedArgs[1].
The subsequent positional
arguments would occupy elements 2 and 3 of the arrays.
In this case,
cArgs
is 4 and
cNamedArgs
is 2.
If the arguments are positional (unnamed), you would set
cArgs
to the
total number of possible arguments,
cNamedArgs
to 0,
and pass
VT_ERROR
as the type of the omitted arguments, with the status code
DISP_E_PARAMNOTFOUND
as the value.
For example, the following code invokes
ShowMe (,1)
.
VARIANT FAR *pVarResult; EXCEPINFO FAR *pExcepInfo; unsigned int FAR *puArgErr; DISPPARAMS dispparams; // Code omitted for brevity. szMember = ``ShowMe''; hresult = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid) ; dispparams.rgvarg[0].vt = VT_I2; dispparams.rgvarg[0].ival = 1; dispparams.rgvarg[1].vt = VT_ERROR; dispparams.rgvarg[1].scode = DISP_E_PARAMNOTFOUND; dispparams.cArgs = 2; dispparams.cNamedArgs = 0; hresult = pdisp->Invoke( dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparams, pVarResult, pExcepInfo, puArgErr);
The example takes two positional arguments, but omits the first.
Therefore,
rgvarg[0] contains 1, the value of the last argument
in the argument
list, and
rgvarg[1] contains
VT_ERROR
and the error return value,
indicating the omitted first argument.
The calling code is responsible for releasing all strings and objects
referred
to by
rgvarg[ ] or placed in
*pVarResult.
As with other
parameters that are passed by value, if the invoked member must maintain access
to a string after returning, you should copy the string.
Similarly, if the
member needs access to a passed-object pointer after returning, it must call
the
AddRef()
function on the object.
A common example occurs
when
an object property is changed to refer to a new object, using the
DISPATCH_PROPERTYPUTREF
flag.
For those implementing
IDispatch::Invoke,
Automation
provides the
DispGetParam()
function to retrieve parameters from the
argument
vector and coerce them to the proper type.
For details, see
DispGetParam()
.
Properties are accessed in the same way as methods, except you specify
DISPATCH_PROPERTYGET
or
DISPATCH_PROPERTYPUT
instead of
DISPATCH_METHOD
.
Some languages can not distinguish
between retrieving a property and
calling a method.
In this case, you should set the flags
DISPATCH_PROPERTYGET
and
DISPATCH_METHOD
.
The following example gets the value of a property named
On.
You
can assume that the object has been created, and that its interfaces have
been
queried, as in the previous example.
VARIANT FAR *pVarResult; // Code omitted for brevity. szMember = ``On''; hresult = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid); hresult = pdisp->Invoke( dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dispparamsNoArgs, pVarResult, NULL, NULL);
As in the previous example, the code calls
GetIDsOfNames
for the
DISPID
of
the
On
property, and then passes the ID to
Invoke
.
Then,
Invoke
returns the property's
value in
pVarResult
.
In general, the
return value does
not set
VT_BYREF
.
However, this bit may be set and a pointer
returned to the
return value, if the lifetime of the return value is the same as that of the
object.
To change the property's value, the call looks like this:
VARIANT FAR *pVarResult; DISPPARAMS dispparams; DISPID mydispid = DISP_PROPERTYPUT // Code omitted for brevity. szMember = ``On''; dispparams.rgvarg[0].vt = VT_BOOL; dispparams.rgvarg[0].bool = FALSE; dispparams.rgdispidNamedArgs = &mydispid; dispparams.cArgs = 1; dispparams.cNamedArgs = 1; hresult = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid); hresult = pdisp->Invoke( dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
The new value for the property (the Boolean value
FALSE
)
is passed as an argument
when the
On
property's
Put
function is invoked.
The
DISPID
for the argument is
DISPID_PROPERTYPUT
.
This
DISPID
is defined by Automation to designate the parameter
that contains the
new value for a property's
Put
function.
The remaining details of the
DISPPARAMS
structure
are described in
the next section.
The
DISPATCH_PROPERTYPUT
flag in the previous example
indicates that a property
is being set by value.
In Visual Basic, the following statement assigns the
Value
property (the default) of
YourObj
to the
Prop
property:
MyObj.Prop = YourObj
This statement should be flagged as a
DISPATCH_PROPERTYPUT
.
Similarly, statements
like the following assign the
Value
property of one object
to the
Value
property of another object.
Worksheet.Cell(1,1) = Worksheet.Cell(6,6) MyDoc.Text1 = YourDoc.Text1
These statements result in a
PROPERTY_PUT
operation
on
Worksheet.Cell(1,1)
and
MyDoc.Text1
.
Use the
DISPATCH_PROPERTYPUTREF
flag to indicate
a property or data member that
should be set by reference.
For example, the following Visual Basic statement
assigns the pointer
YourObj
to the property
Prop,
and should be
flagged as
DISPATCH_PROPERTYPUTREF
.
Set MyObj.Prop = YourObj
The
Set
statement causes a reference assignment,
rather than a value
assignment.
The parameter on the right side is always passed by name, and should not be accessed positionally.
The simplest use of
Invoke
is to call a method that
does not have
any arguments.
You only need to pass the
DISPID
of the
method, a LCID, the
DISPATCH_METHOD
flag, and an empty
DISPPARAMS
structure.
For example:
HRESULT hresult; IUnknown FAR* punk; IDispatch FAR* pdisp = (IDispatch FAR*)NULL; OLECHAR FAR* szMember = ``Simple''; DISPID dispid; DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; hresult = CoCreateInstance(CLSID_CMyObject, NULL, CLSCTX_SERVER, IID_Unknown, (void FAR* FAR*)&punk); hresult = punk->QueryInterface(IID_IDispatch, (void FAR* FAR*)&pdisp); hresult = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid); hresult = pdisp->Invoke( dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparamsNoArgs, NULL, NULL, NULL);
The example invokes a method named
Simple
on an object
of the class
CMyObject
.
First, it calls
CoCreateInstance()
,
which instantiates the
object and returns a pointer to the
object's
IUnknown()
interface
(punk
).
Next, it calls
QueryInterface()
,
receiving a pointer to
the object's
IDispatch()
interface
(pdisp
).
It then uses
pdisp
to call
the
object's
GetIDsOfNames
function,
passing the string
Simple
in
szMember
to get the
DISPID
for the
Simple
method.
With the
DISPID
for
Simple
in
dispid,
it calls
Invoke
to invoke the
method, specifying
DISPATCH_METHOD
for the
wFlags
parameter
and using the system default
locale.
To further simplify the code, the example declares a
DISPPARAMS
structure named
dispparamsNoArgs
that is appropriate to an
Invoke
call
with no arguments.
Because the
Simple
method does not take any arguments
and does not
return a result, the
puArgErr
and
pVarResult
parameters are
NULL
.
In addition, the example passes
NULL
for
pExcepInfo,
indicating that it is not prepared to handle
exceptions
and will handle only
HRESULT
errors.
Most methods, however, take one or more arguments.
To invoke these methods,
the
DISPPARAMS
structure should be filled in, as described
in
``Passing Parameters'' below.
Automation defines special
DISPID
s for invoking an
object's
Value
property (the
default), and the members _NewEnum,
and
Evaluate
.
See
Chapter 18.
Identifies the member.
Use
GetIDsOfNames
or the object's
documentation to obtain the dispatch identifier.
Reserved for future use.
Must be
IID_NULL
.
The locale context in which to interpret arguments.
The
lcid
is used by the
GetIDsOfNames
function,
and
is also passed to
Invoke
to allow the object to interpret
its arguments specific to a locale.
Applications that do not support multiple national languages can ignore this parameter. For more information, refer to Section Section 19.3.
Flags describing the context of the
Invoke
call,
include:
Value
|
Description
|
DISPATCH_METHOD |
The member is invoked as a method.
If a property
has the same name, both this and the
DISPATCH_PROPERTYGET
flag may be set.
|
DISPATCH_PROPERTYGET |
The member is retrieved as a property or data member. |
DISPATCH_PROPERTYPUT |
The member is changed as a property or data member. |
DISPATCH_PROPERTYPUTREF |
The member is changed by a reference assignment, rather than a value assignment. This flag is valid only when the property accepts a reference to an object. |
Pointer to a structure containing an array of arguments, an
array of
argument
DISPID
s for named arguments, and counts for the number
of elements in the
arrays.
See the Description section that follows for a description of the
DISPPARAMS
structure.
Pointer to the location where the result is to be stored,
or
NULL
if the caller
expects no result.
This argument is ignored if
DISPATCH_PROPERTYPUT
or
DISPATCH_PROPERTYPUTREF
is specified.
Pointer to a structure that contains exception information.
This
structure should be filled in if
DISP_E_EXCEPTION
is returned.
Can be
NULL
.
The index within
rgvarg
of the first
argument that
has an error.
Arguments are stored in
pDispParams->rgvarg
in reverse
order, so the
first argument is the one with the highest index in the array.
This parameter
is returned only when the resulting return value is
DISP_E_TYPEMISMATCH
or
DISP_E_PARAMNOTFOUND
.
For details, see Description.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
DISP_E_BADPARAMCOUNT
The number of elements provided to
DISPPARAMS
is
different from the number of arguments accepted by the method or property.
DISP_E_BADVARTYPE
One of the arguments in rgvarg is not a valid variant type.
DISP_E_EXCEPTION
The application needs to raise an exception. In this case, the structure passed in pExcepInfo should be filled in.
DISP_E_MEMBERNOTFOUND
The requested member does not exist, or the call to Invoke tried to set the value of a read-only property.
DISP_E_NONAMEDARGS
This implementation of
IDispatch()
does
not support
named arguments.
DISP_E_OVERFLOW
One of the arguments in rgvarg could not be coerced to the specified type.
DISP_E_PARAMNOTFOUND
One of the parameter
DISPID
s does not correspond
to a parameter on the method.
In this case,
puArgErr
should be set to the first argument that contains the error.
DISP_E_TYPEMISMATCH
One or more of the arguments could not be coerced. The index within rgvarg of the first parameter with the incorrect type is returned in the puArgErr parameter.
DISP_E_UNKNOWNINTERFACE
The interface identifier passed in
riid
is not
IID_NULL
.
DISP_E_UNKNOWNLCID
The member being invoked interprets string arguments according to the LCID, and the LCID is not recognized. If the LCID is not needed to interpret arguments, this error should not be returned.
DISP_E_PARAMNOTOPTIONAL
A required parameter was omitted.
In 16-bit versions, you can define your own errors using the
MAKE_SCODE
value
macro.
This code from the Lines sample file Lines.cpp implements the
Invoke
member function for the CLines class.
STDMETHODIMP CLines::Invoke( DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult, EXCEPINFO FAR* pExcepInfo, UINT FAR* puArgErr) { return DispInvoke( this, m_ptinfo, dispidMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); }
The next code example calls the
CLines::Invoke
member
function to get the
value of the
Color
property:
HRESULT hr; EXCEPINFO excepinfo; UINT nArgErr; VARIANT vRet; DISPPARAMS FAR* pdisp; OLECHAR FAR* szMember; DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; // Initialization code omitted for brevity. szMember = ``Color''; hr = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid); // Get Color property. hr = pdisp->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, &dispparams, &vRet, &excepinfo, &nArgErr);
CreateStdDispatch()
,
DispInvoke
,
DispGetParam()
,
ITypeInfo::Invoke
The
ICreateTypeInfo()
interface provides the tools
for creating and administering
the type information defined through the type description.
-
ICreateTypeInfo::AddFuncDesc()
HRESULT AddFuncDesc(
#include <Oaidl.h>
unsigned int index,
FUNCDESC FAR* pFuncDesc
);
AddFuncDesc
adds a function description to the type
description.
The index specifies the order of the functions within the type information.
The
first function has an index of zero.
If an index is specified that exceeds
one
less than the number of functions in the type information, an error is
returned.
Calling this function does not pass ownership of the
FUNCDESC
structure to
ICreateTypeInfo()
.
Therefore, the caller must
still
de-allocate the
FUNCDESC
structure.
The passed-in virtual function table (VTBL) field (oVft)
of the
FUNCDESC
is ignored.
This attribute is set when
ICreateTypeInfo::LayOut
is called.
The function
AddFuncDesc
uses the passed-in member
identifier (ID)
fields within each
FUNCDESC
for classes with
TYPEKIND
=
TKIND_DISPATCH
or
TKIND_INTERFACE
.
If the member IDs are set to
MEMBERID_NIL
,
AddFuncDesc
assigns member IDs to
the functions.
Otherwise, the member
ID
fields within
each
FUNCDESC
are ignored.
Any
HREFTYPE
fields in the
FUNCDESC
structure must have been produced by the
same instance of
ITypeInfo()
for which
AddFuncDesc
is called.
The
get
and
put
accessor functions
for the same property must
have the same dispatch identifier (DISPID
).
Index of the new
FUNCDESC
in the type information.
pFuncDesc
Pointer to a
FUNCDESC
structure that
describes the function.
The
bstrIDLInfo
field in
the
FUNCDESC
should be set to
NULL
for
future compatibility.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_WRONGTYPEKIND
Type mismatch.
- Specifies an inherited interface, or an interface implemented
by a component
object class (coclass).
ICreateTypeInfo::AddImplType()
HRESULT AddImplType(
#include <Oaidl.h>
unsigned int index,
HREFTYPE hRefType
);
To specify an inherited interface, use
index
=
0.
For a dispinterface
with Syntax 2, call
ICreateTypeInfo::AddImplType()
twice,
once with
nindex
= 0 for the inherited
IDispatch()
and once with
nindex
= 1 for the interface that is being wrapped.
For
a dual
interface, call
ICreateTypeInfo::AddImplType()
with
nindex
= -1 for
the
TKIND_INTERFACE
type information component of the dual
interface.
Index of the implementation class to be added. Specifies the order of the type relative to the other type.
hRefType
Handle to the referenced type description
obtained from the
AddRefType
description.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_WRONGTYPEKIND
Type mismatch.
- Adds a type description to those referenced by the type description
being
created.
ICreateTypeInfo::AddRefTypeInfo()
HRESULT AddRefTypeInfo(
#include <Oaidl.h>
ITypeInfo FAR* pTInfo,
HREFTYPE FAR* phRefType
);
The second parameter returns a pointer to the handle of the added type
information.
If
AddRefTypeInfo
has been called previously
for the same
type information, the index that was returned by the previous call is returned
in
phRefType.
If the referenced type description is in
the type library
being created, its type information can be obtained by calling
IUnknown::QueryInterface(
IID_ITypeInfo
,
...)
on the
ICreateTypeInfo()
interface of that type description.
Pointer to the type description to be referenced.
phRefType On return, pointer to the handle that this type description associates with the referenced type information.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_WRONGTYPEKIND
Type mismatch.
- Adds a variable or data member description to the type description.
ICreateTypeInfo::AddVarDesc()
HRESULT AddVarDesc(
#include <Oaidl.h>
unsigned int index,
VARDESC FAR* pVarDesc
);
The index specifies the order of the variables.
The first variable has
an index
of zero.
ICreateTypeInfo::AddVarDesc()
returns an error
if the specified
index is greater than the number of variables currently in the type
information.
Calling this function does not pass ownership of the
VARDESC
structure to
ICreateTypeInfo()
.
The instance field (oInst) of the
VARDESC
structure is ignored.
This attribute is set only
when
ICreateTypeInfo::LayOut
is called.
Also, the member ID fields within the
VARDESC
s
are ignored unless
the
TYPEKIND
of the class is
TKIND_DISPATCH
.
Any
HREFTYPE
fields in the
VARDESC
structure must have been produced by the
same instance of
ITypeInfo()
for which
AddVarDesc
is called.
AddVarDesc
ignores the contents of the
idldesc
field of the
ELEMDESC
.
Index of the variable or data member to be added to the type description.
pVarDesc Pointer to the variable or data member description to be added.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_WRONGTYPEKIND
Type mismatch.
- Associates a DLL entry point with the function that has the specified
index.
ICreateTypeInfo::DefineFuncAsDllEntry()
HRESULT DefineFuncAsDllEntry(
#include <Oaidl.h>
unsigned int index,
OLECHAR FAR* szDllName,
OLECHAR FAR* szProcName
);
If the high word of szProcName is zero, then the low word must contain the ordinal of the entry point; otherwise, szProcName points to the zero-terminated name of the entry point.
Index of the function.
szDllName Name of the DLL that contains the entry point.
szProcName Name of the entry point or an ordinal (if the high word is zero).
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
TYPE_E_ELEMENTNOTFOUND
The element cannot be found.
TYPE_E_WRONGTYPEKIND
Type mismatch.
- Assigns VTBL offsets for virtual functions and instance offsets
for
per-instance data members, and creates the two type descriptions for dual
interfaces.
ICreateTypeInfo::LayOut()
HRESULT LayOut(
);
LayOut
also assigns member ID numbers to the functions
and variables,
unless the
TYPEKIND
of the class is
TKIND_DISPATCH
.
Call
LayOut
after
all members of the type information are defined, and before the type library
is
saved.
Use
ICreateTypeLib
::SaveAllChanges
to save the type information after calling
LayOut
.
Other
members of the
ICreateTypeInfo()
interface should not be called after
calling
LayOut
.
Different implementations of
ICreateTypeInfo()
or other interfaces that create type information are free to assign any member ID numbers, provided that all members (including inherited members), have unique IDs. For examples, seeICreateTypeInfo2
.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_UNDEFINEDTYPE
Bound to unrecognized type.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
TYPE_E_WRONGTYPEKIND
Type mismatch.
TYPE_E_ELEMENTNOTFOUND
The element cannot be found.
TYPE_E_AMBIGUOUSNAME
More than one item exists with this name.
TYPE_E_SIZETOOBIG
The type information is too long.
TYPE_E_TYPEMISMATCH
Type mismatch.
- Specifies the data alignment for an item of
ICreateTypeInfo::SetAlignment()
TYPEKIND
=TKIND_RECORD
.
HRESULT SetAlignment(
#include <Oaidl.h>
unsigned short cbAlignment
);
The alignment is the minimum of the natural alignment (for example, byte data on byte boundaries, word data on word boundaries, and so on), and the alignment denoted by cbAlignment.
Alignment method for the type. A value of 0 indicates alignment on the 64K boundary; 1 indicates no special alignment. For other values, n indicates alignment on byte n.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
- Sets the documentation string displayed by type browsers.
ICreateTypeInfo::SetDocString()
HRESULT SetDocString(
#include <Oaidl.h>
OLECHAR FAR* pStrDoc
);
The documentation string is a brief description of the type description being created.
Pointer to the documentation string.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
- Sets the name of a function and the names of its parameters to
the names in the
array of pointers
rgszNames.
ICreateTypeInfo::SetFuncAndParamNames()
HRESULT SetFuncAndParamNames(
#include <Oaidl.h>
unsigned int index,
OLECHAR FAR* FAR* rgszNames,
unsigned int cNames
);
The function
SetFuncAndParamNames
needs to be used
once for each
property.
The last parameter for
put
and
putref
accessor
functions is unnamed.
Index of the function whose function name and parameter names are to be set.
rgszNames Array of pointers to names. The first element is the function name. Subsequent elements are names of parameters.
cNames Number of elements in the rgszNames array.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_ELEMENTNOTFOUND
The element cannot be found.
- Sets the documentation string for the function with the specified
index.
ICreateTypeInfo::SetFuncDocString()
HRESULT SetFuncDocString(
#include <Oaidl.h>
unsigned int index,
OLECHAR FAR* szDocString
);
The documentation string is a brief description of the function intended
for
use by tools such as type browsers.
SetFuncDocString
only
needs to be
used once for each property, because all property accessor functions are
identified by one name.
Index of the function.
szDocString Pointer to the documentation string.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_ELEMENTNOTFOUND
The element cannot be found.
- Sets the Help context ID for the function with the specified
index.
ICreateTypeInfo::SetFuncHelpContext()
HRESULT SetFuncHelpContext(
#include <Oaidl.h>
unsigned int index,
unsigned long dwHelpContext
);
SetFuncHelpContext
only needs to be set once for
each property, because
all property accessor functions are identified by one name.
Index of the function.
dwHelpContext Help context ID for the Help topic.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_ELEMENTNOTFOUND
The element cannot be found.
E_INVALIDARG
One or more of the arguments is invalid.
- Sets the globally unique identifier (GUID) associated with the
type
description.
ICreateTypeInfo::SetGuid()
HRESULT SetGuid(
#include <Oaidl.h>
REFGUID guid
);
For an interface, this is an interface ID (IID); for a coclass, it is a class ID (CLSID). For information on GUIDs, see Chapter 18.
Globally unique ID to be associated with the type description.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_ACCESSDENIED
Cannot write to the destination.
- Sets the Help context ID of the type information.
ICreateTypeInfo::SetHelpContext()
HRESULT SetHelpContext(
#include <Oaidl.h>
unsigned long dwHelpContext
);
Handle to the Help context.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
E_ACCESSDENIED
Cannot write to the destination.
- Sets the attributes for an implemented or inherited interface
of a type.
ICreateTypeInfo::SetImplTypeFlags()
HRESULT SetImplTypeFlags(
#include <Oaidl.h>
unsigned int index,
int implTypeFlags
);
SetImplTypeFlags
sets the
IMPLTYPE
flags for the indexed interface.
See
Chapter 18
Index of the interface for which to set type flags.
implTypeFlags
IMPLTYPE
flags
to be set.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
E_ACCESSDENIED
Cannot write to the destination.
- Sets the marshaling
opcode
string associated
with the type description
or the function.
ICreateTypeInfo::SetMops()
HRESULT SetMops(
#include <Oaidl.h>
unsigned int index,
BSTR bstrMops
);
Index of the member for which to set the opcode string. If index is -1, sets the opcode string for the type description.
bstrMops The marshaling opcode string.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
E_ACCESSDENIED
Cannot write to the destination.
- Sets the type description for which this type description is an
alias, if
ICreateTypeInfo::SetTypeDescAlias()
TYPEKIND
=TKIND_ALIAS
.
HRESULT SetTypeDescAlias(
#include <Oaidl.h>
TYPEDESC FAR* pTDescAlias
);
To set the type for an alias, call
SetTypeDescAlias
for a type
description whose
TYPEKIND
is
TKIND_ALIAS
.
Pointer to a type description that describes the type for which this is an alias.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_WRONGTYPEKIND
Type mismatch.
- Sets type flags of the type description being created.
ICreateTypeInfo::SetTypeFlags()
HRESULT SetTypeFlags(
#include <Oaidl.h>
unsigned int uTypeFlags
);
Use
SetTypeFlags
to set the flags for the type description.
For details,
see
Chapter 18.
Settings for the type flags.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_WRONGTYPEKIND
Type mismatch.
- Sets the documentation string for the variable with the specified
index.
ICreateTypeInfo::SetVarDocString()
HRESULT SetVarDocString(
#include <Oaidl.h>
unsigned int index,
OLECHAR FAR* szDocString
);
Index of the variable being documented.
szDocString The documentation string to be set.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_ELEMENTNOTFOUND
The element was not found.
- Sets the Help context ID for the variable with the specified
index.
ICreateTypeInfo::SetVarHelpContext()
HRESULT SetVarHelpContext(
#include <Oaidl.h>
unsigned int index,
unsigned long dwHelpContext
);
Index of the variable described by the type description.
dwHelpContext Handle to the Help context ID for the Help topic on the variable.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_ELEMENTNOTFOUND
The element cannot be found.
- Sets the name of a variable.
ICreateTypeInfo::SetVarName()
HRESULT SetVarName(
#include <Oaidl.h>
unsigned int index,
OLECHAR FAR* szName
);
Index of the variable whose name is being set.
szName Name for the variable.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_ELEMENTNOTFOUND
The element cannot be found.
- Sets the major and minor version number of the type information.
ICreateTypeInfo::SetVersion()
HRESULT SetVersion(
#include <Oaidl.h>
unsigned short wMajorVerNum,
unsigned short wMinorVerNum
);
Major version number for the type.
wMinorVerNum Minor version number for the type.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
E_ACCESSDENIED
Cannot write to the destination.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
The
ICreateTypeInfo2
interface derives from
ICreateTypeInfo()
,
and adds methods for deleting items that have been added through
ICreateTypeInfo()
.
The
ICreateTypeInfo::LayOut
method provides a way for the creator of the type information to check for
any
errors.
A call to
QueryInterface()
can be made to the
ICreateTypeInfo()
instance at any time for its
ITypeInfo()
interface.
Calling any of the methods in the
ITypeInfo()
interface
that require
layout information lays out the type information automatically.
interface ICreateTypeInfo2 : ICreateTypeInfo
- Sets the name of the typeinfo.
ICreateTypeInfo2::SetName()
HRESULT SetName(
#include <Oaidl.h>
OLECHAR FAR* szName
);
Name to be assigned to the typeinfo.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
TYPE_E_INVALIDSTATE
The state of the type info is not valid for this operation.
- Deletes a function description specified by the index number.
ICreateTypeInfo2::DeleteFuncDesc()
HRESULT DeleteFuncDesc(
#include <Oaidl.h>
unsigned int index
);
Index of the function whose description is to be deleted. The index should be in the range of 0 to 1 less than the number of functions in this type.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Deletes the function description (ICreateTypeInfo2::DeleteFuncDescByMemId()
FUNCDESC
)
specified by
memid.
HRESULT DeleteFuncDescByMemId(
#include <Oaidl.h>
MEMBERID memid,
INVOKEKIND invKind
);
Member identifier of the
FUNCDESC
to delete.
invKind The type of the invocation.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Deletes the specified
ICreateTypeInfo2::DeleteVarDesc()
VARDESC
structure.
HRESULT DeleteVarDesc(
#include <Oaidl.h>
unsigned int index
);
Index number of the
VARDESC
structure.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
TYPE_E_IOERROR
The function cannot read from the file.
TYPE_E_INVDATAREAD
The function cannot read from the file.
TYPE_E_UNSUPFORMAT
The type library has an old format.
TYPE_E_INVALIDSTATE
The type library cannot be opened.
Example
ptypeinfo->DeleteVarDesc
(index);
- Deletes the specified
ICreateTypeInfo2::DeleteVarDescByMemId()
VARDESC
structure.
HRESULT DeleteVarDescByMemId(
#include <Oaidl.h>
MEMBERID memid
);
Member identifier of the
VARDESC
to be
deleted.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
TYPE_E_IOERROR
The function cannot read from the file.
TYPE_E_INVDATAREAD
The function cannot read from the file.
TYPE_E_UNSUPFORMAT
The type library has an older format.
TYPE_E_INVALIDSTATE
The type library cannot be opened.
- Deletes the
ICreateTypeInfo2::DeleteImplType()
IMPLTYPE
flags for the indexed
interface.
HRESULT DeleteImplType(
#include <Oaidl.h>
unsigned int index
);
Index of the interface for which to delete the type flags.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Sets a value for custom data.
ICreateTypeInfo2::SetCustData()
HRESULT SetCustData(
#include <Oaidl.h>
REFGUID guid,
VARIANT * pVarVal
);
Unique identifier that can be used to identify the data.
pVarVal The data to store (any variant except an object).
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Sets the context number for the specified Help string.
ICreateTypeInfo2::SetHelpStringContext()
HRESULT SetHelpStringContext(
#include <Oaidl.h>
DWORD * dwHelpStringContext
);
Pointer to the Help string context number.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
Argument is invalid.
- Sets a value for a specified custom function.
ICreateTypeInfo2::SetFuncCustData()
HRESULT SetFuncCustData(
#include <Oaidl.h>
unsigned int index,
REFGUID guid,
VARIANT * pVarVal
);
The index of the function for which to set the custom data.
guid Unique identifier used to identify the data.
pVarVal The data to store (any variant except an object).
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Sets a Help context value for a specified
custom function.
ICreateTypeInfo2::SetFuncHelpStringContext()
HRESULT SetFuncHelpStringContext(
#include <Oaidl.h>
unsigned int index,
DWORD dwHelpStringContext,
);
The index of the function for which to set the custom data.
dwHelpStringContext Help string context for a localized string
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Sets a custom data variable.
ICreateTypeInfo2::SetVarCustData()
HRESULT SetVarCustData(
#include <Oaidl.h>
unsigned int index,
REFGUID guid,
VARIANT * pVarVal
);
Index of the variable for which to set the custom data.
guid Globally unique ID (GUID) used to identify the data.
pVarVal Data to store (any legal variant except an object).
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Sets the specified parameter for the custom data.
ICreateTypeInfo2::SetParamCustData()
HRESULT SetParamCustData(
#include <Oaidl.h>
unsigned int indexFunc,
unsigned int indexParam,
REFGUID guid,
VARIANT * pVarVal
);
Index of the function for which to set the custom data.
indexParam Index of the parameter of the function for which to set the custom data.
guid Globally unique identifier (GUID) used to identify the data.
pvarVal The data to store (any legal variant except an object).
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Sets the implementation type for custom data.
ICreateTypeInfo2::SetImplTypeCustData()
HRESULT SetImplTypeCustData(
#include <Oaidl.h>
unsigned int index,
REFGUID guid,
VARIANT * pVarVal,
);
Index of the variable for which to set the custom data.
guid Unique identifier used to identify the data.
pVarVal Reference to the value of the variable.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Sets a Help context value for a specified variable.
ICreateTypeInfo2::SetVarHelpStringContext()
HRESULT SetVarHelpStringContext(
#include <Oaidl.h>
unsigned int index,
DWORD dwHelpStringContext,
);
The index of the variable.
dwHelpStringContext Help string context for a localized string
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
The
ICreateTypeLib
interface provides the methods
for creating and managing the
component or file that contains type information.
Type libraries are created
from
type descriptions using the
MkTypLib
utility or the MIDL
compiler.
These type
libraries are accessed through the
ITypeLib()
interface.
- Creates a new type description instance within the type library.
ICreateTypeLib::CreateTypeInfo()
HRESULT CreateTypeInfo(
#include <Oaidl.h>
OLECHAR FAR* szName,
TYPEKIND tkind,
ICreateTypeInfo FAR* FAR* ppCTInfo
);
Use the function
CreateTypeInfo
to create a new type
description
instance within the library.
An error is returned if the specified name already
appears in the library.
Valid
tkind
values are described
in the
Chapter 18.
To get the type information
of the type description that is being created, call
IUnknown::QueryInterface(
IID_ITypeInfo
,
...)
on the returned
ICreateTypeInfo()
.
This type information can be used by
other type
descriptions that reference it by using
ICreateTypeInfo::AddRefTypeInfo
.
Name of the new type.
tkind
TYPEKIND
of the type description
to be created.
ppCTInfo On return, contains a pointer to the type description.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
TYPE_E_NAMECONFLICT
The provided name is not unique.
TYPE_E_WRONGTYPEKIND
Type mismatch.
- Saves the
ICreateTypeLib::SaveAllChanges()
ICreateTypeLib
instance following
the layout of type
information.
HRESULT SaveAllChanges(
);
You should not call any other
ICreateTypeLib
methods
after calling
SaveAllChanges
.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
TYPE_E_IOERROR
The function cannot write to the file.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
All
FACILITY_STORAGE
errors.
- Sets the documentation string associated with the library.
ICreateTypeLib::SetDocString()
HRESULT SetDocString(
#include <Oaidl.h>
OLECHAR FAR* szDoc
);
The documentation string is a brief description of the library intended for use by type information browsing tools.
A documentation string that briefly describes the type library.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Sets the universal unique identifier (UUID) associated with the
type library
(Also known as the globally unique identifier (GUID)).
ICreateTypeLib::SetGuid()
HRESULT SetGuid(
#include <Oaidl.h>
REFGUID guid
);
Universal unique identifiers (UUIDs) are described in Chapter 18.
The globally unique identifier to be assigned to the library.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
- Sets the Help context ID for retrieving general Help information
for the type
library.
ICreateTypeLib::SetHelpContext()
HRESULT SetHelpContext(
#include <Oaidl.h>
unsigned long dwHelpContext
);
Calling
SetHelpContext
with a Help context of zero
is equivalent to not
calling it at all, because zero indicates a
NULL
Help context.
Help context ID to be assigned to the library.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
- Sets the name of the Help file.
ICreateTypeLib::SetHelpFileName()
HRESULT SetHelpFileName(
#include <Oaidl.h>
OLECHAR FAR* szHelpFileName
);
Each type library can reference a single Help file.
The
GetDocumentation
method of the created
ITypeLib()
returns a
fully qualified path for the Help file, which is formed by appending the name
passed into
szHelpFileName
to the registered Help directory
for the type
library.
The Help directory is registered under:
\TYPELIB\
guid of library\Major.Minorversion\HELPDIR
The name of the Help file for the library.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
- Sets library flags, such as
ICreateTypeLib::SetLibFlags()
LIBFLAG_FRESTRICTED
.
HRESULT SetLibFlags(
#include <Oaidl.h>
unsigned int uLibFlags
);
The flags to set for the library.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
- Sets the binary Microsoft national language ID associated with
the library.
ICreateTypeLib::SetLcid()
HRESULT SetLcid(
#include <Oaidl.h>
LCID lcid
);
For more information on national language IDs, see Section Section 19.3.
Represents the locale ID for the type library.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
- Sets the name of the type library.
ICreateTypeLib::SetName()
HRESULT SetName(
#include <Oaidl.h>
OLECHAR FAR* szName
);
Name to be assigned to the library.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
- Sets the major and minor version numbers of the type library.
ICreateTypeLib::SetVersion()
HRESULT SetVersion(
#include <Oaidl.h>
unsigned short wMajorVerNum,
unsigned short wMinorVerNum
);
Major version number for the library.
wMinorVerNum Minor version number for the library.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
ICreateTypeLib2()
inherits from
ICreateTypeLib
, and has four member functions.
The
ICreateTypeInfo()
instance returned from ICreateTypeLib
can be accessed
through a
QueryInterface()
call to
ICreateTypeInfo2
.
interface ICreateTypeLib2 : ICreateTypeLib
- Sets the name of the type library.
ICreateTypeLib2::SetName()
HRESULT SetName(
#include <Oaidl.h>
OLECHAR FAR* szName
);
Name to be assigned to the library.
The return value of the returned
HRESULT
is one of
the following:
S_OK
Success.
STG_E_INSUFFICIENTMEMORY
Out of memory.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
TYPE_E_INVALIDSTATE
The state of the type library is not valid for this operation.
- Deletes a specified type information from the type library.
ICreateTypeLib2::DeleteTypeInfo()
HRESULT DeleteTypeInfo(
#include <Oaidl.h>
OLECHAR FAR* szName
);
Name of the type information to remove.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Sets a value to custom data.
ICreateTypeLib2::SetCustData()
HRESULT SetCustData(
#include <Oaidl.h>
REFGUID guid,
VARIANT * pVarVal
);
Unique identifier used to identify the data.
pVarVal The data to store (any variant except an object).
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Sets the Help string context number.
ICreateTypeLib2::SetHelpStringContext()
HRESULT SetHelpStringContext(
#include <Oaidl.h>
DWORD * dwHelpStringContext
);
The Help string context number.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Sets the DLL name to be used for Help string lookup (for localization
purposes).
ICreateTypeLib2::SetHelpStringDll()
HRESULT SetHelpStringDll(
#include <Oaidl.h>
LPOLESTR szFileName
);
The DLL file name.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
One or more of the arguments is invalid.
- Returns a
BstrFromVector()
BSTR
, assigning each element of the vector
to a character in the
BSTR
.
HRESULT BstrFromVector((
#include <oleauto.h>
SAFEARRAY FAR* psa,
BSTR FAR* pbstr
);
The vector to be converted to a
BSTR
.
On exit,
pbstr
points to a
BSTR
,
each character of which is assigned to an element from the vector.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
E_OUTOFMEMORY
Out of memory.
E_INVALIDARG
The argument
psa
is
NULL
.
DISP_E_TYPEMISMATCH
The argument psa is not a vector (not an array of bytes).
Returns a
BSTR
, assigning each element of the vector
to a character in the
BSTR
.
- Creates simplified type information for use in an implementation of
CreateDispTypeInfo()
IDispatch()
.
HRESULT CreateDispTypeInfo((
#include <oleauto.h>
INTERFACEDATA pidata,
LCID lcid,
ITypeInfo FAR * FAR * pptinfo
);
Creates simplified type information for use in an implementation of
IDispatch()
.
You can construct type information at run time by using
CreateDispTypeInfo()
and an
INTERFACEDATA
structure that describes the
object being exposed.
The type information returned by this function is primarily designed
to
automate the implementation of
IDispatch()
.
CreateDispTypeInfo()
does
not return all of the type information described in
Chapter 18.
The argument
pidata
is not a complete description of
an interface.
It does not
include Help information, comments, optional parameters, and other type
information that is useful in different contexts.
Accordingly, the recommended method for providing type information about
an
object is to describe the object using the Object Description Language (ODL),
and to compile the object description into a type library using the Microsoft
Interface Definition Language (MIDL) compiler or the
MkTypLib
utility.
To use type information from a type library, use the
LoadTypeLib
and
GetTypeInfoOfGuid
functions instead of
CreateDispTypeInfo()
.
For more information, see
Chapter 18.
The interface description that this type information describes.
The locale identifier for the names used in the type information.
On return, pointer to a type information implementation for
use in
DispGetIDsOfNames()
and
DispInvoke()
.
The return value obtained from the returned
HRESULT
is one of the
following:
S_OK
The interface is supported.
E_INVALIDARG
Either the interface description or the LCID is invalid.
E_OUTOFMEMORY
Insufficient memory to complete the operation.
The code that follows creates type information from
INTERFACEDATA
to expose the
CCalc
object.
static METHODDATA NEARDATA rgmdataCCalc[] = { PROPERTY(VALUE, IMETH_ACCUM, IDMEMBER_ACCUM, VT_I4) PROPERTY(ACCUM, IMETH_ACCUM, IDMEMBER_ACCUM, VT_I4) PROPERTY(OPND, IMETH_OPERAND, IDMEMBER_OPERAND, VT_I4) PROPERTY(OP, IMETH_OPERATOR, IDMEMBER_OPERATOR, VT_I2) METHOD0(EVAL, IMETH_EVAL, IDMEMBER_EVAL, VT_BOOL) METHOD0(CLEAR, IMETH_CLEAR, IDMEMBER_CLEAR, VT_EMPTY) METHOD0(DISPLAY, IMETH_DISPLAY, IDMEMBER_DISPLAY, VT_EMPTY) METHOD0(QUIT, IMETH_QUIT, IDMEMBER_QUIT, VT_EMPTY) METHOD1(BUTTON, IMETH_BUTTON, IDMEMBER_BUTTON, VT_BOOL) }; INTERFACEDATA NEARDATA g_idataCCalc = { rgmdataCCalc, DIM(rgmdataCCalc) }; // Use Dispatch interface API functions to implement IDispatch. CCalc FAR* CCalc::Create() { HRESULT hresult; CCalc FAR* pcalc; CArith FAR* parith; ITypeInfo FAR* ptinfo; IUnknown FAR* punkStdDisp; extern INTERFACEDATA NEARDATA g_idataCCalc; if((pcalc = new FAR CCalc()) == NULL) return NULL; pcalc->AddRef(); parith = &(pcalc->m_arith); // Build type information for the functionality on this object that // is being exposed for external programmability. hresult = CreateDispTypeInfo( &g_idataCCalc, LOCALE_SYSTEM_DEFAULT, &ptinfo); if(hresult != NOERROR) goto LError0; // Create an aggregate with an instance of the default // implementation of IDispatch that is initialized with // type information. hresult = CreateStdDispatch( pcalc, // Controlling unknown. parith, // Instance to dispatch on. ptinfo, // Type information describing the instance. &punkStdDisp); ptinfo->Release(); if(hresult != NOERROR) goto LError0; pcalc->m_punkStdDisp = punkStdDisp; return pcalc; LError0:; pcalc->Release(); return NULL; }
- Creates a standard implementation of the
CreateStdDispatch()
IDispatch()
interface
through a single function call.
This simplifies exposing objects through Automation.
HRESULT CreateStdDispatch((
#include <oleauto.h>
IUnknown FAR * punkOuter,
void FAR * pvThis,
ITypeInfo FAR * ptinfo,
IUnknown FAR * FAR * ppunkStdDisp
);
Creates a standard implementation of the
IDispatch()
interface through
a single function call.
This simplifies exposing objects through Automation.
You can use
CreateStdDispatch()
when creating an
object instead of
implementing the
IDispatch()
member functions for the object.
However, the
implementation that
CreateStdDispatch()
creates has these
limitations:
Supports only one national language.
Supports only dispatch-defined exception codes returned from
Invoke
.
LoadTypeLib
,
GetTypeInfoOfGuid
,
and
CreateStdDispatch()
comprise the minimum set of functions
that you need to
call to expose an object using a type library.
For more information on
LoadTypeLib
and
GetTypeInfoOfGuid
, see
Chapter 18.
CreateDispTypeInfo()
and
CreateStdDispatch()
comprise the
minimum set of dispatch components you need to call to expose an object using
type information provided by the
INTERFACEDATA
structure.
Pointer to the object's
IUnknown()
implementation.
Pointer to the object to expose.
Pointer to the type information that describes the exposed object.
This is the private unknown for the object that implements
the
IDispatch()
interface
QueryInterface()
call.
This
pointer is
NULL
if the function fails.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
E_INVALIDARG
One of the first three arguments is invalid.
E_OUTOFMEMORY
There was insufficient memory to complete the operation.
The following code implements the
IDispatch
interface
for the
CCalc
class using
CreateStdDispatch()
.
CCalc FAR* CCalc::Create() { HRESULT hresult; CCalc FAR* pcalc; CArith FAR* parith; ITypeInfo FAR* ptinfo; IUnknown FAR* punkStdDisp; extern INTERFACEDATA NEARDATA g_idataCCalc; if((pcalc = new FAR CCalc()) == NULL) return NULL; pcalc->AddRef(); parith = &(pcalc->m_arith); // Build type information for the functionality on this object that // is being exposed for external programmability. hresult = CreateDispTypeInfo( &g_idataCCalc, LOCALE_SYSTEM_DEFAULT, &ptinfo); if(hresult != NOERROR) goto LError0; // Create an aggregate with an instance of the default // implementation of IDispatch that is initialized with // type information. hresult = CreateStdDispatch( pcalc, // Controlling unknown. parith, // Instance to dispatch on. ptinfo, // Type information describing the instance. &punkStdDisp); ptinfo->Release(); if(hresult != NOERROR) goto LError0; pcalc->m_punkStdDisp = punkStdDisp; return pcalc; LError0:; pcalc->Release(); return NULL; }
- Uses type information to convert a set of names to
DispGetIDsOfNames()
DISPID
s.
This is the recommended implementation of
IDispatch::GetIDsOfNames()
.
HRESULT DispGetIDsOfNames((
#include <oleauto.h>
ITypeInfo * ptinfo,
OLECHAR FAR * FAR * rgszNames,
unsigned int cNames,
DISPID FAR * rgdispid
);
Pointer to the type information for an interface. This type information is specific to one interface and language code, so it is not necessary to pass an interface identifier (IID) or LCID to this function.
An array of name strings that can be the same array passed
to
DispInvoke()
in the
DISPPARAMS
structure.
If
cNames
is greater than 1, the first name is interpreted
as a method
name, and subsequent names are interpreted as parameters to that method.
The number of elements in rgszNames.
Pointer to an array of
DISPID
s to be filled
in by
this function.
The first
ID
corresponds to the method name.
Subsequent IDs are interpreted as parameters to the method.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
The interface is supported.
E_INVALIDARG
One of the arguments is invalid.
DISP_E_UNKNOWNNAME
One or more of the given names were not known.
The returned
array of
DISPID
s contains
DISPID_UNKNOWN
for each entry
that corresponds to an unknown name.
Any of the
ITypeInfo::Invoke()
errors can
also be
returned.
Uses type information to convert a set of names to
DISPID
s.
This is the
recommended implementation of
IDispatch::GetIDsOfNames()
.
This code from the Lines sample file Points.cpp implements the member
function
GetIDsOfNames
for the CPoints class using
DispGetIDsOfNames()
.
STDMETHODIMP CPoints::GetIDsOfNames( REFIID riid, char FAR* FAR* rgszNames, UINT cNames, LCID lcid, DISPID FAR* rgdispid) { return DispGetIDsOfNames(m_ptinfo, rgszNames, cNames, rgdispid); }
CreateStdDispatch()
,
IDispatch::GetIDsOfNames
- Retrieves a parameter from the
DispGetParam()
DISPPARAMS
structure.
HRESULT DispGetParam((
#include <oleauto.h>
DISPPARAMS FAR * pdispparams,
unsigned int position,
VARTYPE vtTarg,
VARIANT FAR * pvarResult,
unsigned int FAR * puArgErr
);
Retrieves a parameter from the
DISPPARAMS
structure,
checking both named
parameters and positional parameters, and coerces the parameter to the
specified type.
The output parameter
pvarResult
must be a valid
variant.
Any existing
contents are released in the standard way.
The contents of the variant are
freed with
VariantFree
.
If you have used
DispGetParam()
to get the right
side of a property put
operation, the second parameter should be
DISPID_PROPERTYPUT
.
For example:
DispGetParam(&dispparams, DISPID_PROPERTYPUT, VT_BOOL, &varResult)
Named parameters cannot be accessed positionally, and vice versa.
Pointer to the parameters passed to
IDispatch::Invoke()
.
The position of the parameter in the parameter list.
DispGetParam()
starts at the end of the array, so if position
is 0, the last parameter in the array is returned.
The type the argument should be coerced to.
Pointer to the variant to pass the parameter into.
On return, pointer to the index of the argument that caused
a
DISP_E_TYPEMISMATCH
error.
This pointer is returned to
Invoke
to indicate the position of the argument in
DISPPARAMS
that caused the error.
The return value obtained from the
HRESULT
is one
of the following:
S_OK
Success.
DISP_E_BADVARTYPE
The variant type vtTarg is not supported.
DISP_E_OVERFLOW
The retrieved parameter could not be coerced to the specified type.
DISP_E_PARAMNOTFOUND
The parameter indicated by position could not be found.
DISP_E_TYPEMISMATCH
The argument could not be coerced to the specified type.
E_INVALIDARG
One of the arguments was invalid.
E_OUTOFMEMORY
Insufficient memory to complete operation.
The following example uses
DispGetParam()
to set
X and Y
properties:
STDMETHODIMP CPoint::Invoke( DISPID dispidMember, REFIID riid, LCID lcid, unsigned short wFlags, DISPPARAMS FAR* pdispparams, VARIANT FAR* pvarResult, EXCEPINFO FAR* pExcepInfo, unsigned int FAR* puArgErr) { unsigned int uArgErr; HRESULT hresult; VARIANTARG varg0; VARIANT varResultDummy; UNUSED(lcid); UNUSED(pExcepInfo); // Make sure the wFlags are valid. if(wFlags & ~(DISPATCH_METHOD | DISPATCH_PROPERTYGET | DISPATCH_PROPERTYPUT | DISPATCH_PROPERTYPUTREF)) return ResultFromScode(E_INVALIDARG); // This object only exposes a ``default'' interface. if(!IsEqualIID(riid, IID_NULL)) return ResultFromScode(DISP_E_UNKNOWNINTERFACE); // It simplifies the following code if the caller // ignores the return value. if(puArgErr == NULL) puArgErr = &uArgErr; if(pvarResult == NULL) pvarResult = &varResultDummy; VariantInit(&varg0); // Assume the return type is void, unless otherwise is found. VariantInit(pvarResult); switch(dispidMember){ case IDMEMBER_CPOINT_GETX: V_VT(pvarResult) = VT_I2; V_I2(pvarResult) = GetX(); break; case IDMEMBER_CPOINT_SETX: hresult = DispGetParam(pdispparams, 0, VT_I2, &varg0, puArgErr); if(hresult != NOERROR) return hresult; SetX(V_I2(&varg0)); break; case IDMEMBER_CPOINT_GETY: V_VT(pvarResult) = VT_I2; V_I2(pvarResult) = GetY(); break; case IDMEMBER_CPOINT_SETY: hresult = DispGetParam(pdispparams, 0, VT_I2, &varg0, puArgErr); if(hresult != NOERROR) return hresult; SetY(V_I2(&varg0)); break; default: return ResultFromScode(DISP_E_MEMBERNOTFOUND); } return NOERROR; }
CreateStdDispatch()
,
IDispatch::Invoke()
- Automatically calls member functions on an interface.
DispInvoke()
HRESULT DispInvoke((
#include <oleauto.h>
void FAR *_this,
ITypeInfo FAR * ptinfo,
DISPID dispidMember,
unsigned short wFlags,
DISPPARAMS FAR * pparams,
VARIANT FAR * pvarResult,
EXCEPINFO pexcepinfo,
unsigned int FAR * puArgErr
);
Automatically calls member functions on an interface, given the type
information for the interface.
You can describe an interface with type
information and implement
IDispatch::Invoke()
for the interface
using this single call.
The parameter
_this
is a pointer to an implementation
of the interface
that is being deferred to.
DispInvoke()
builds a stack
frame, coerces
parameters using standard coercion rules, pushes them on the stack, and then
calls the correct member function in the VTBL.
_this
IDispatch()
interface
described byptinfo.
Pointer to the type information that describes the interface.
Identifies the member.
Use
GetIDsOfNames
or the object's
documentation to obtain the
DISPID
.
Flags describing the context of the
Invoke
call,
as follows:
Value
|
Description
|
DISPATCH_METHOD |
The member is invoked as a method.
If a property
has the same name, both this and the
DISPATCH_PROPERTYGET
flag can be set.
|
DISPATCH_PROPERTYGET |
The member is retrieved as a property or data member. |
DISPATCH_PROPERTYPUT |
The member is changed as a property or data member. |
DISPATCH_PROPERTYPUTREF |
The member is changed by a reference assignment, rather than a value assignment. This flag is valid only when the property accepts a reference to an object. |
Pointer to a structure containing an array of arguments, an
array of
argument
DISPID
s for named arguments, and counts for number of elements
in the arrays.
Pointer to where the result is to be stored, or
NULL
if the caller
expects no result.
This argument is ignored if
DISPATCH_PROPERTYPUT
or
DISPATCH_PROPERTYPUTREF
is specified.
Pointer to a structure containing exception information.
This
structure
should be filled in if
DISP_E_EXCEPTION
is returned.
The index within
rgvarg
of the first
argument that
has an error.
Arguments are stored in
pdispparams->rgvarg
in reverse
order, so the
first argument is the one with the highest index in the array.
This parameter
is returned only when the resulting return value is
DISP_E_TYPEMISMATCH
or
DISP_E_PARAMNOTFOUND
.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
DISP_E_BADPARAMCOUNT
The number of elements provided in
DISPPARAMS
is
different from the number of arguments accepted by the method or property.
DISP_E_BADVARTYPE
One of the arguments in
DISPPARAMS
is not
a valid
variant type.
DISP_E_EXCEPTION
The application needs to raise an exception. In this case, the structure passed in pexcepinfo should be filled in.
DISP_E_MEMBERNOTFOUND
The requested member does not exist.
DISP_E_NONAMEDARGS
This implementation of
IDispatch()
does
not support
named arguments.
DISP_E_OVERFLOW
One of the arguments in
DISPPARAMS
could
not be coerced
to the specified type.
DISP_E_PARAMNOTFOUND
One of the parameter IDs does not correspond to a parameter on the method. In this case, puArgErr is set to the first argument that contains the error.
DISP_E_PARAMNOTOPTIONAL
A required parameter was omitted.
DISP_E_TYPEMISMATCH
One or more of the arguments could not be coerced. The index of the first parameter with the incorrect type within rgvarg is returned in puArgErr.
E_INVALIDARG
One of the arguments is invalid.
E_OUTOFMEMORY
Insufficient memory to complete the operation.
Any of the
ITypeInfo::Invoke()
errors can
also be
returned.
The following code from the Lines sample file Lines.cpp implements
IDispatch::Invoke()
using
DispInvoke()
.
This function uses
m_bRaiseException
to signal that an error occurred during
the
DispInvoke()
call.
STDMETHODIMP CLines::Invoke( DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR* pdispparams, VARIANT FAR* pvarResult, EXCEPINFO FAR* pexcepinfo, UINT FAR* puArgErr) { return DispInvoke( this, m_ptinfo, dispidMember, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr); }
CreateStdDispatch()
,
IDispatch::Invoke()
- Converts the MS-DOS representation of time to the date and time
representation stored in a variant.
DosDateTimeToVariantTime()
int DosDateTimeToVariantTime((
#include <oleauto.h>
unsigned short wDOSDate,
unsigned short wDOSTime,
double FAR* pvtime
);
Converts the MS-DOS representation of time to the date and time representation stored in a variant.
MS-DOS records file dates and times as packed 16-bit values. An MS-DOS date has the following format.
Bits
|
Contents
|
0-4 | Day of the month (1-31) |
5-8 | Month (1 = January, 2 = February, and so on) |
9-15 | Year offset from 1980 (add 1980 to get the actual year) |
An MS-DOS time has the following format.
Bits
|
Contents
|
0-4 | Second divided by 2 |
5-10 | Minute (0-59) |
11-15 | Hour (0- 23 on a 24-hour clock) |
The MS-DOS date to convert.
The MS-DOS time to convert.
Pointer to the location to store the converted time.
The return value obtained from the returned
HRESULT
is one of the following:
TRUE
Success.
FALSE
Failure.
- Retrieves a pointer to a running object that has been registered with COM.
GetActiveObject()
HRESULT GetActiveObject((
#include <oleauto.h>
REFCLSID rclsid,
void FAR * pvReserved,
IUnknown FAR * FAR * ppunk
);
Pointer to the class identifier (CLSID) of the active object from the COM registration database.
Reserved for future use.
Must be
NULL
.
On return, a pointer to the requested active object.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
Failure.
Retrieves a pointer to a running object that has been registered with
OLE.
- Registers an object as the active object for its class.
RegisterActiveObject()
HRESULT RegisterActiveObject((
#include <oleauto.h>
IUnknown FAR * punk,
REFCLSID rclsid,
DWORD dwFlags,
Unsigned long FAR * pdwRegister
);
Registers an object as the active object for its class.
The
RegisterActiveObject()
function registers the
object to which
punkpoints as the active object for the
class denoted by
rclsid.Registration causes the object
to be listed in the running object table
(ROT) of COM, a globally accessible lookup table that keeps track of objects
that are currently running on the computer.
(For more information about the
running object table, see the
OLE Programmer's Reference.)
The
dwFlags
parameter specifies the strength or weakness
of the
registration, which affects the way the object is shut down.
In general, ActiveX objects should behave in the following manner:
If the object is visible, it should shut down only in response
to an explicit user command (such as the
Exit
command on
the
File
menu), or to the equivalent command from an ActiveX client (invoking the
Quit
or
Exit
method on the Application
object).
If the object is not visible, it should shut down only when the last external connection to it is gone.
Strong registration performs an
AddRef()
on the object,
incrementing the reference count of the object (and its associated stub) in
the
running object table.
A strongly registered object must be explicitly revoked
from the table with
RevokeActiveObject()
.
The default is
strong
registration (ACTIVEOBJECT_STRONG
).
Weak registration keeps a pointer to the object in the running object table, but does not increment the reference count. Consequently, when the last external connection to a weakly registered object disappears, COM releases the object's stub, and the object itself is no longer available.
To ensure the desired behavior, consider not only the default actions of COM, but also the following:
Even though code can create an invisible object, the object may become visible at some later time. Once the object is visible, it should remain visible and active until it receives an explicit command to shut down. This can occur after references from the code disappear.
Other ActiveX clients may be using the object. If so, the code should not force the object to shut down.
To avoid possible conflicts, you should always register ActiveX objects
with
ACTIVEOBJECT_WEAK
, and call
CoLockObjectExternal,
when
necessary, to guarantee the object remains active.
CoLockObjectExternal()
adds a strong lock, thereby preventing
the
object's reference count from reaching
zero.
For detailed information about this function, refer to the
OLE
Programmer's Reference.
Most commonly, objects need to call
CoLockObjectExternal()
when they
become visible, so they remain active until the user requests the object to
shut down.
The following procedure lists the steps your code should follow
to
shut down an object correctly.
When the object becomes visible, make the following call to add a lock for the user:
CoLockObjectExternal(punk, TRUE, TRUE)
The lock remains in effect until a user explicitly requests the object
to be
shut down, such as with a
Quit
or
Exit
command.
When the user requests the object to be shut down, call
CoLockObjectExternal()
again to free the lock, as
follows:
CoLockObjectExternal(punk, FALSE, TRUE)
Call
RevokeActiveObject()
to make the object
inactive.
To end all connections from remote processes, call
CoDisconnectObject()
as follows:
CoDisconnectObject(punk, 0)
This function is described in more detail in the OLE Programmer's Reference.
Pointer to the
IUnknown()
interface of
the active
object.
Pointer to the CLSID of the active object.
Flags controlling registration of the object.
Possible values
are
ACTIVEOBJECT_STRONG
and
ACTIVEOBJECT_WEAK
.
On return, a pointer to a handle.
This handle must be passed
to
RevokeActiveObject()
to end the object's active status.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
Failure.
- Ends an object's status as active.
RevokeActiveObject()
HRESULT RevokeActiveObject((
#include <oleauto.h>
Unsigned long dwRegister,
void FAR * pvReserved
);
A handle previously returned by
RegisterActiveObject()
.
Reserved for future use.
Must be
NULL
.
The return value obtained from the returned
HRESULT
is one of the following:
S_OK
Success.
Failure.
Ends an object's status as active.
- Compares two character strings of the same locale according to the supplied
LCID.
CompareString()
int CompareString((
#include <Winnls.h>
LCID lcid,
DWORD dwCmpFlags,
LPCWSTR lpString1,
integer cchCount1,
LPWSTR lpString2,
integer cchCount2,
);
Compares two character strings of the same locale according to the supplied LCID.
When used without any flags, this function uses the same sorting algorithm
as
lstrcmp in the given locale.
When used with
NORM_IGNORECASE
,
the same algorithm
as lstrcmpi is used.
For double-byte character set (DBCS
) locales, the
flag
NORM_IGNORECASE
has an
effect on all the wide (two-byte) characters as well as the narrow (one-byte)
characters.
This includes the wide Greek and Cyrillic characters.
In Chinese Simplified, the sorting order used to compare the strings is based on the following sequence: symbols, digit numbers, English letters, and Chinese Simplified characters. The characters within each group sort in character-code order.
In Chinese Traditional, the sorting order used to compare the strings is based on the number of strokes in the characters. Symbols, digit numbers, and English characters are considered to have zero strokes. The sort sequence is symbols, digit numbers, English letters, and Chinese Traditional characters. The characters within each stroke-number group sort in character-code order.
In Japanese, the sorting order used to compare the strings is based on the Japanese 50-on sorting sequence. The Kanji ideographic characters sort in character-code order.
In Japanese, the flag
NORM_IGNORENONSPACE
has an
effect on the daku-on,
handaku-on, chou-on, you-on, and soku-on modifiers, and on the repeat
kana/kanji characters.
In Korean, the sort order is based on the sequence: symbols, digit numbers, Jaso and Hangeul, Hanja, and English. Within the Jaso-Hangeul group, each Jaso character is followed by the Hangeuls that start with that Jaso. Hanja characters are sorted in Hangeul pronunciation order. Where multiple Hanja have the same Hangeul pronunciation, they are sorted in character-code order.
The
NORM_IGNORENONSPACE
flag only has an effect for
the locales in which
accented characters are sorted in a second pass from main characters.
All
characters in the string are first compared without regard to accents and
(if
the strings are equal) a second pass over the strings to compare accents is
performed.
In this case, this flag causes the second pass to not be performed.
Some locales sort accented characters in the first pass, in which case this
flag will have no effect.
If the return value is 2, the two strings are equal in the collation sense, though not necessarily identical (the case might be ignored, and so on).
If the two strings are of different lengths, they are compared up to the length of the shortest one. If they are equal to that point, the return value will indicate that the longer string is greater.
To maintain the C run-time convention of comparing strings, the value 2 can be subtracted from a non-zero return value. The meaning of < 0, == 0, and > 0 is then consistent with the C run-time conventions.
Locale context for the comparison. The strings are assumed to be represented in the default ANSI code page for this locale.
Flags that indicate the character traits to use or ignore when comparing the two strings. Several flags can be combined , or none can be used. (In the case of this function, there are no illegal combinations of flags.) Compare flags include the following.
Value
|
Meaning
|
NORM_IGNORECASE |
Ignore case. Default is Off. |
NORM_IGNOREKANATYPE |
Ignore Japanese hiragana/katakana character differences. Default is Off. |
NORM_IGNORENONSPACE |
Ignore nonspacing marks (accents, diacritics, and vowel marks). Default is Off. |
NORM_IGNORESYMBOLS |
Ignore symbols. Default is Off. |
NORM_IGNOREWIDTH |
Ignore character width. Default is Off. |
The two strings to be compared.
The character counts of the two strings.
The count does not
include
the
NULL
-terminator (if any).
If either
cchCount1
or
cchCount2
is *1, the corresponding string is assumed
to be
NULL
-terminated, and the length is calculated automatically.
Failure.
lpString1 is less than lpString2.
lpString1 is equal to lpString2.
lpString1 is greater than lpString2.
- Transforms the case or sort order of a string.
LCMapString()
int LCMapString((
#include <Winnls.h>
LCID lcid,
DWORD dwMapFlags,
LPCWSTR lpSrcStr,
int cchSrc,
LPWSTR lpDestStr,
int cchDest,
);
Transforms the case or sort order of a string.
LCMapStringA maps one character string to another, performing the specified locale-dependent translation.
The flag
LCMAP_UPPER
produces the same result as
AnsiUpper
in the given locale.
The flag
LCMAP_LOWER
produces the same result as
AnsiLower
.
This function
always maps a single character to a single character.
The mapped string is
NULL
-terminated if the source
string is
NULL
-terminated.
When used with
LCMAP_UPPER
and
LCMAP_LOWER
, the
lpSrcStr
and
lpDestStr
may be
the same to produce an in-place mapping.
When
LCMAP_SORTKEY
is used, the
lpSrcStr
and
lpDestStr
pointers
may not be the same.
In this case, an error
will result.
The
LCMAP_SORTKEY
transforms two strings so that
when they are compared with
the standard C library function strcmp (by strict numerical valuation of their
characters), the same order will result, as if the original strings were
compared with
CompareStringA
.
When
LCMAP_SORTKEY
is specified, the output
string is a string (without
NULL
s, except for the terminator),
but the
character values will not be meaningful display values.
This is similar
behavior to the ANSI C function
strxfrm
.
Locale ID context for mapping. The strings are assumed to be represented in the default ANSI code page for this locale.
Flags that indicate what type of transformation is to occur during mapping. Several flags can be combined on a single transformation (though some combinations are illegal). Mapping options include the following.
Name
|
Meaning
|
LCMAP_LOWERCASE |
Lowercase. |
LCMAP_UPPERCASE |
Uppercase. |
LCMAP_SORTKEY |
Character sort key. |
LCMAP_HALFWIDTH |
Narrow characters (where applicable). |
LCMAP_FULLWIDTH |
Wide characters (where applicable). |
LCMAP_HIRAGANA |
Hiragana. |
LCMAP_KATAKANA |
Katakana. |
LCMAP_IGNORECASE |
Ignore case. Default is Off. |
LCMAP_IGNORENONSPACE |
Ignore nonspacing. Default is Off. |
LCMAP_IGNOREWIDTH |
Ignore character width. Default is Off. |
LCMAP_IGNOREKANATYPE |
Ignore Japanese hiragana/katakana character differences. Default is Off. |
LCMAP_IGNORESYMBOLS |
Ignore symbols. Default is Off. |
The latter five options (LCMAP_IGNORECASE
,
LCMAP_IGNORENONSPACE
,
LCMAP_IGNOREWIDTH
,
LCMAP_IGNOREKANATYPE
, and
LCMAP_IGNORESYMBOLS
)
are normalization options that can only be used in combination with the
LCMAP_SORTKEY
conversion option.
Conversion options can be combined only when they are taken from the following three groups, and then only when there is no more than one option from each group:
Casing options (LCMAP_LOWERCASE
,
LCMAP_UPPERCASE
)
Width options (LCMAP_HALFWIDTH
,
LCMAP_FULLWIDTH
)
Kana options (LCMAP_HIRAGANA
,
LCMAP_KATAKANA
)
Pointer to the supplied string to be mapped.
Character count of the input string buffer.
If *1,
lpSrcStr
is assumed to be
NULL
-terminated and
the length
is calculated automatically.
Pointer to the memory buffer that stores the resulting mapped string.
Character count of the memory buffer pointed to by lpDestStr. If cchDest is 0, then the return value of this function is the number of characters required to hold the mapped string. In this case, the lpDestStr pointer is not referenced.
Failure.
Success.
If the function succeeds, and the value of cchDest is nonzero, the return
value is the
number of characters, or bytes if
LCMAP_SORTKEY
is specified,
written
to the buffer.
This count includes room for a
NULL
terminator.
If the function succeeds, and the value of
cchDest
is zero,
the return value is the size of the buffer in characters, or bytes if
LCMAP_SORTKEY
is specified, required to receive the translated
string or sort key.
This size includes room for a
NULL
terminator.
If the function fails, the return value is 0.
To get extended error
information,
call
GetLastError()
.
GetLastError()
may return one of the following error codes:
ERROR_INSUFFICIENT_BUFFER
ERROR_INVALID_FLAGS
ERROR_INVALID_PARAMETER
- Retrieves locale information from the user's system.
GetLocaleInfo()
int GetLocaleInfoA(
LCID lcid,
LCTYPE LCType,
LPSTR lpLCData,
int cchData,
);
Retrieves locale information from the user's system.
GetLocaleInfoA
returns one of the various pieces
of information about a locale
by querying the stored locale database or
Win.ini
.
The
call also indicates how
much memory is necessary to contain the desired information.
The information returned is always a
NULL
-terminated
string.
No integers are
returned by this function and numeric values are returned as text.
(See the
format descriptions under
LCTYPE
).
The locale ID. The returned string is represented in the default ANSI code page for this locale.
Flag that indicates the type of information to be returned
by the call.
See the listing of constant values defined in this chapter.
LOCALE_NOUSEROVERRIDE
|
LCTYPE
indicates that the desired information
will always be retrieved from the locale database, even if the LCID is the
current one and the user has changed some of the values in the Windows 95
Control Panel.
If this flag is not specified, the values in
Win.ini
take precedence over the database settings when getting values
for the current system default locale.
Pointer to the memory where
GetLocaleInfoA
will return
the requested data.
This pointer is not referenced if
cchData
is 0.
Character count of the supplied
lpLCData
memory
buffer.
If
cchData
is 0, the return value is the number
of characters required to hold the string, including the terminating
NULL
character.
In this case,
lpLCData
is not
referenced.
Failure.
Success.
If the function succeeds, the return value is the number of bytes (ANSI version) or characters (Unicode version) written to the destination buffer, or, if the cchData parameter is zero, the number of bytes or characters required to hold the locale information.
If the function fails, the return value is zero.
To get extended error
information, call
GetLastError()
.
GetLastError()
may return
one of
the following error codes:
ERROR_INSUFFICIENT_BUFFER
ERROR_INVALID_FLAGS
ERROR_INVALID_PARAMETER
- Retrieves locale type information about each character in a string.
GetStringType()
BOOL GetStringTypeA(
#include <winnls.h>
LCID lcid,
DWORD dwInfoType,
LPCSTR lpSrcStr,
int cchSrc,
LPWORD lpCharType,
);
Retrieves locale type information about each character in a string.
The
lpSrcStr
and
lpCharType
pointers cannot be the same.
In this case, the
error
ERROR_INVALID_PARAMETER
results.
The character type bits are divided up into several levels. One level's information can be retrieved by a single call.
This function supports three character types:
CT_CTYPE1
CT_CTYPE2
CT_CTYPE3
CT_CTYPE1
character types support ANSI C and POSIX
character typing functions.
A
bitwise OR of these values is returned when
dwInfoType
is set to CT_CTYPE1.
For
DBCS
locales, the
CT_CTYPE1
attributes
apply to both narrow characters and wide
characters.
The Japanese hiragana and katakana characters, and the kanji
ideograph characters all have the C1_ALPHA attribute.
The following table lists the Ctype 1 character types.
Name |
Value |
Meaning |
0x0001 | Uppercase1. | |
0x0002 | Lowercase1. | |
0x0004 | Decimal digits. | |
0x0008 | Space characters. | |
0x0010 | Punctuation. | |
0x0020 | Control characters. | |
0x0040 | Blank characters. | |
0x0080 | Hexadecimal digits. | |
0x0100 | Any letter. |
The Windows version 3.1 functions
IsCharUpper
andIsCharLower
do not always produce correct results for characters in the range 0x80-0x9f, so they may produce different results than this function for characters in that range. (For example, the German Windows version 3.1 language driver incorrectly reports 0x9a, lowercase s hacek, as uppercase).
CT_CTYPE2
character types support the proper layout
of text.
For
DBCS
locales,
CT_CTYPE2
applies to both narrow and wide characters.
The
directional attributes
are assigned so that the
BiDi
layout algorithm standardized
by Unicode produces
the correct results.
For more information on the use of these attributes,
see
The Unicode Standard: Worldwide Character Encoding from Addison-Wesley
publishers.
Attribute |
Name |
Value |
Meaning |
C2_LEFTTORIGHT |
0x1 | Left to right. | |
C2_RIGHTTOLEFT |
0x2 | Right to left. | |
C2_EUROPENUMBER |
0x3 | European number, European digit. | |
C2_EUROPESEPARATOR |
0x4 | European numeric separator. | |
C2_EUROPETERMINATOR |
0x5 | European numeric terminator. | |
C2_ARABICNUMBER |
0x6 | Arabic number. | |
C2_COMMONSEPARATOR |
0x7 | Common numeric separator. | |
C2_BLOCKSEPARATOR |
0x8 | Block separator. | |
C2_SEGMENTSEPARATOR |
0x9 | Segment separator. | |
C2_WHITESPACE |
0xA | White space. | |
C2_OTHERNEUTRAL |
0xB | Other neutrals. | |
C2_NOTAPPLICABLE |
0x0 | No implicit direction (for example, control codes). |
CT_CTYPE3
character types are general text-processing
information.
A bitwise OR
of these values is returned when
dwInfoType
is set to
CT_CTYPE3.
For
DBCS
locales, the
CT_CTYPE3
attributes apply to both narrow
characters and wide
characters.
The Japanese hiragana and katakana characters, and the kanji
ideograph characters all have the C3_ALPHA attribute.
Name |
Value |
Meaning |
C3_NONSPACING |
0x1 | Nonspacing mark. |
C3_DIACRITIC |
0x2 | Diacritic nonspacing mark. |
C3_VOWELMARK |
0x4 | Vowel nonspacing mark. |
C3_SYMBOL |
0x8 | Symbol. |
C3_KATAKANA |
0x10 | Katakana character. |
C3_HIRAGANA |
0x20 | Hiragana character. |
C3_HALFWIDTH |
0x40 | Narrow character. |
C3_FULLWIDTH |
0x80 | Wide character. |
C3_IDEOGRAPH |
0x100 | Ideograph. |
C3_ALPHA |
0x8000 | Any letter. |
C3_NOTAPPLICABLE |
0x0 | Not applicable. |
Locale context for the mapping. The string is assumed to be represented in the default ANSI code page for this locale.
Type of character information to retrieve. The various types are divided into different levels. (See the Description section for a list of information included in each type). The options are mutually exclusive. The following types are supported:
CT_CTYPE1
CT_CTYPE2
CT_CTYPE3
String for which character types are requested.
If
cchSrc
is *1,
lpSrcStr
is assumed to be
NULL
-terminated.
Character count of
lpSrcStr.
If
cchSrc
is *1,
lpSrcStr
is assumed to be
NULL
-terminated.
This must also be the character count of
lpCharType.
Array of the same length as lpSrcStr (cchSrc). On output, the array contains one word corresponding to each character in lpSrcStr.
Failure.
Success.
- Retrieves the default
GetSystemDefaultLangID()
LANGID
from a user's
system.
LANGID GetSystemDefaultLangID((
#include <Winnls.h>
);
Returns the system default
LANGID
.
For information
on how this value is
determined, see
GetSystemDefaultLCID()
.
Failure.
LANGID
Success.
- Retrieves the default LCID from a user's system.
GetSystemDefaultLCID()
LCID GetSystemDefaultLCID((
#include <Winnls.h>
);
Returns the system default LCID.
The return value is determined by examining
the values of
sLanguage
and
iCountry
in
Win.ini
,
and comparing the values to
those in the stored locale database.
If no matching values are found, or the
required values cannot be read from
Win.ini
, or if the
stored locale database
cannot be loaded, the value 0 is returned.
Failure.
Success.
- Retrieves the default
GetUserDefaultLangID()
LANGID
from a user's system.
LANGID GetUserDefaultLangID((
#include <Winnls.h>
);
Returns the user default
LANGID
.
On single-user systems,
the value returned
from this function is always the same as that returned from
GetSystemDefaultLangID()
.
Failure.
LANGID
Success.
- Retrieves the default LCID from a user's system.
GetUserDefaultLCID()
LCID GetUserDefaultLCID((
#include <Winnls.h>
);
Returns the user default LCID.
On single-user systems, the value returned
by
this function is always the same as that returned from
GetSystemDefaultLCID()
.
Failure.
Success.
- Increments the lock count of an array, and retrieves a pointer to the array
data.
SafeArrayAccessData()
HRESULT SafeArrayAccessData((
#include <oleauto.h>
SAFEARRAY FAR* psa,
void HUGEP* FAR* ppvdata
);
Pointer to an array descriptor created by
SafeArrayCreate()
.
On exit, pointer to a pointer to the array data. Arrays may be larger than 64K, so very large pointers should be used only in Windows version 3.1 or later.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
E_INVALIDARG
The argument psa was not a valid safe array descriptor.
E_UNEXPECTED
The array could not be locked.
Increments the lock count of an array, and retrieves a pointer to the array data.
The following example sorts a safe array of one dimension that contains
BSTRs
by accessing the array elements directly.
This approach is faster than using
SafeArrayGetElement()
and
SafeArrayPutElement()
.
long i, j, min; BSTR bstrTemp; BSTR HUGEP *pbstr; HRESULT hr; // Get a pointer to the the elements of the array. hr = SafeArrayAccessData(psa, (void HUGEP* FAR*)&pbstr); if (FAILED(hr)) goto error; // Bubble sort. cElements = lUBound-lLBound+1; for (i = 0; i < cElements-1; i++) { min = i; for (j = i+1; j < cElements; j++) { if (wcscmp(pbstr[j], pbstr[min]) < 0) min = j; } // Swap array[min] and array[i]. bstrTemp = pbstr[min]; pbstr[min] = pbstr[i]; pbstr[i] = bstrTemp; } SafeArrayUnaccessData(psa);
- Allocates memory for a safe array, based on a descriptor created with
SafeArrayAllocData()
SafeArrayAllocDescriptor()
.
HRESULT SafeArrayAllocData((
#include <oleauto.h>
SAFEARRAY FAR* psa
);
Pointer to an array descriptor created by
SafeArrayAllocDescriptor()
.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
E_INVALIDARG
The argument psa was not a valid safe array descriptor.
E_UNEXPECTED
The array could not be locked.
Allocates memory for a safe array, based on a descriptor created with
SafeArrayAllocDescriptor()
.
The following example creates a safe array using the
SafeArrayAllocDescriptor()
and
SafeArrayAllocData()
functions.
SAFEARRAY FAR* FAR*ppsa; unsigned int ndim = 2; HRESULT hresult = SafeArrayAllocDescriptor(ndim, ppsa); if( FAILED(hresult)) return ERR_OutOfMemory; (*ppsa)->rgsabound[ 0 ].lLbound = 0; (*ppsa)->rgsabound[ 0 ].cElements = 5; (*ppsa)->rgsabound[ 1 ].lLbound = 1; (*ppsa)->rgsabound[ 1 ].cElements = 4; hresult = SafeArrayAllocData(*ppsa); if( FAILED(hresult)) { SafeArrayDestroyDescriptor(*ppsa) return ERR_OutOfMemory; }
SafeArrayAllocData()
,
SafeArrayDestroyData()
,
SafeArrayDestroyDescriptor()
- Allocates memory for a safe array descriptor.
SafeArrayAllocDescriptor()
HRESULT SafeArrayAllocDescriptor((
#include <oleauto.h>
unsigned int cDims,
SAFEARRAY FAR* FAR* ppsaOut
);
Allocates memory for a safe array descriptor.
This function allows the creation of safe arrays that contain elements
with
data types other than those provided by
SafeArrayCreate()
.
After
creating an array descriptor using
SafeArrayAllocDescriptor()
,
set the
element size in the array descriptor, an call
SafeArrayAllocData()
to allocate memory for the array elements.
The number of dimensions of the array.
Pointer to a location in which to store the created array descriptor.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
E_INVALIDARG
The argument psa was not a valid safe array descriptor.
E_UNEXPECTED
The array could not be locked.
The following example creates a safe array using the
SafeArrayAllocDescriptor()
and
SafeArrayAllocData()
functions.
SAFEARRAY FAR* FAR*ppsa; unsigned int ndim = 2; HRESULT hresult = SafeArrayAllocDescriptor( ndim, ppsa ); if( FAILED( hresult ) ) return ERR_OutOfMemory; (*ppsa)->rgsabound[ 0 ].lLbound = 0; (*ppsa)->rgsabound[ 0 ].cElements = 5; (*ppsa)->rgsabound[ 1 ].lLbound = 1; (*ppsa)->rgsabound[ 1 ].cElements = 4; hresult = SafeArrayAllocData( *ppsa ); if( FAILED( hresult ) ) { SafeArrayDestroyDescriptor( *ppsa ) return ERR_OutOfMemory; }
SafeArrayAllocData()
,
SafeArrayDestroyData()
,
SafeArrayDestroyDescriptor()
- Creates a copy of an existing safe array.
SafeArrayCopy()
HRESULT SafeArrayCopy((
#include <oleauto.h>
SAFEARRAY FAR* psa,
SAFEARRAY FAR* FAR* ppsaOut
);
Creates a copy of an existing safe array.
SafeArrayCopy()
calls the string or variant manipulation
functions if the
array to copy contains either of these data types.
If the array being copied
contains object references, the reference counts for the objects are
incremented.
Pointer to an array descriptor created by
SafeArrayCreate()
.
Pointer to a location in which to return the new array descriptor.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
E_INVALIDARG
The argument psa was not a valid safe array descriptor.
E_OUTOFMEMORY
Insufficient memory to create the copy.
SysAllocStringLen()
,
VariantCopy()
,
VariantCopyInd()
- Copies the source array to the target array after releasing any resources
in the target array.
SafeArrayCopyData()
HRESULT SafeArrayCopyData((
#include <oleauto.h>
SAFEARRAY FAR* psaSource,
SAFEARRAY FAR* FAR* ppsaTarget
);
Copies the source array to the target array after releasing any resources
in
the target array.
This is similar to
SafeArrayCopy,
except
that
the target array has to be set up by the caller.
The target is not allocated
or
reallocated.
In general, VBA3 supports array assignment.
Dim lhs(1 To 10) As Integer Dim rhs(1 To 10) As Integer lhs = rhs
When the number of dimensions, the size of those dimensions, and the element types match, data types are differentiated based on the following factors:
Fixed-size, left side.
The left side is
fixed if the type
of the expression on the left side is a fixed-size array.
For example, the
following statement is a declaration of a fixed-size array.
Dim x (1 To 10) As Integer
Matching number of dimensions.
The number
of dimensions of
the left side may or may not match the number of dimensions of the array on
the
right side.
Dimensions match.
The dimensions match
if, for each
dimension, the number of elements match.
The dimensions can match even if
the
declarations are slightly different, such as when one array is zero-based
and
another is one-based, but they have the same number of elements.
The following table shows what happens when the number of dimensions, size of the dimension, and element types do not match:
Fixed-Size, Left
Side
|
Matching
Number of Dimensions
|
Dimensions Match
|
What Happens
|
No | Yes or No | Yes or No | Success. If necessary, the left side is resized to the size of the right side. |
Yes | No | Failure. | |
Yes | Yes | No | Treated in same manner as fixed-length strings.
If the right side has more elements than the left side, the assignment succeeds
and the extra elements have no effect.
If the left side has more elements
than
the right side, the assignment succeeds and the unaffected elements of the
left
side are zero-,
NULL -, or empty-filled, depending on the
types of the elements. |
Yes | Yes | Yes | Success |
Visual Basic for Applications and Automation use the same set of rules with cases in which the size or types of source and destination arrays do not match. The rules of Visual Basic are described above.
The safe array from which to be copied.
On exit, the array referred to by ppsaTarget contains a copy of the data in psaSource.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
E_INVALIDARG
The argument psa was not a valid safe array descriptor.
E_OUTOFMEMORY
Insufficient memory to create the copy.
SysAllocStringLen()
,
VariantCopy()
,
VariantCopyInd()
- Creates a new array descriptor, allocates and initializes the data for the
array, and returns a pointer to the new array descriptor.
SafeArrayCreate()
HRESULT SafeArrayCreate((
#include <oleauto.h>
VARTYPE vt,
unsigned int cDims,
SAFEARRRAYBOUND FAR* rgsabound
);
Creates a new array descriptor, allocates and initializes the data for the array, and returns a pointer to the new array descriptor.
The base type of the array (the
VARTYPE
of each element
of the array).
The
VARTYPE
is restricted to a subset of
the variant types.
Neither the
VT_ARRAY
nor the
VT_BYREF
flag can be set.
VT_EMPTY
and
VT_NULL
are not valid base types for the array.
All other types
are legal.
Number of dimensions in the array. The number cannot be changed after the array is created.
Pointer to a vector of bounds (one for each dimension) to allocate for the array.
Points to the array descriptor, or
NULL
if the array
could not be created.
HRESULT PASCAL __export CPoly::EnumPoints(IEnumVARIANT FAR* FAR* ppenum) { unsigned int i; HRESULT hresult; VARIANT var; SAFEARRAY FAR* psa; CEnumPoint FAR* penum; POINTLINK FAR* ppointlink; SAFEARRAYBOUND rgsabound[1]; rgsabound[0].lLbound = 0; rgsabound[0].cElements = m_cPoints; psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound); if(psa == NULL){hresult = ReportResult(0, E_OUTOFMEMORY, 0, 0); goto LError0} // Code omitted here for brevity. LError0:; return hresult; }
- Creates a one-dimensional array whose lower bound is always zero.
SafeArrayCreateVector()
HRESULT SafeArrayCreateVector((
#include <oleauto.h>
VARTYPE vt,
long lbound,
unsigned int cElements
);
Creates a one-dimensional array whose lower bound is always zero.
A
safe array
created with
SafeArrayCreateVector()
is a fixed size, so
the constant
FADF_FIXEDSIZE
is always set.
SafeArrayCreateVector()
allocates a single block
of memory containing a
SAFEARRAY
structure for a single-dimension array (24 bytes),
immediately
followed by the array data.
All of the existing safe array functions work
correctly for safe arrays that are allocated with
SafeArrayCreateVector()
.
A
SafeArrayCreateVector()
is allocated as a single
block of memory.
Both
the
SafeArray
descriptor and the array data block are allocated
contiguously in one allocation, which speeds up array allocation.
However,
a
user can allocate the descriptor and data area separately using the
SafeArrayAllocDescriptor()
and
SafeArrayAllocData()
calls.
The base type of the array (the
VARTYPE
of each element of the array).
The
VARTYPE
is restricted
to a subset of the variant types.
Neither the
VT_ARRAY
nor the
VT_BYREF
flag can be set.
VT_EMPTY
and
VT_NULL
are not valid base types for the array.
All
other types are legal.
The lower bound for the array. Can be negative.
The number of elements in the array.
Points to the array descriptor, or
NULL
if the array
could not be created.
- Destroys an existing array descriptor and all of the data in the array.
SafeArrayDestroy()
HRESULT SafeArrayDestroy((
#include <oleauto.h>
SAFEARRAY FAR* psa
);
Pointer to an array descriptor created by
SafeArrayCreate()
.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
DISP_E_ARRAYISLOCKED
The array is currently locked.
E_INVALIDARG
The item pointed to by psa is not a safe array descriptor.
Destroys an existing array descriptor and all of the data in the array.
If objects are stored in the array,
Release()
is called
on each object
in the array.
STDMETHODIMP_(ULONG) CEnumPoint::Release() { if(--m_refs == 0){ if(m_psa != NULL) SafeArrayDestroy(m_psa); delete this; return 0; } return m_refs; }
- Destroys all the data in a safe array.
SafeArrayDestroyData()
HRESULT SafeArrayDestroyData((
#include <oleauto.h>
SAFEARRAY FAR* psa
);
Destroys all the data in a safe array.
This function is typically used when freeing safe arrays that contain
elements
with data types other than variants.
If objects are stored in the array,
Release()
is called on each object in the array.
Pointer to an array descriptor.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
DISP_E_ARRAYISLOCKED
The array is currently locked.
E_INVALIDARG
The item pointed to by psa is not a safe array descriptor.
SafeArrayAllocData()
,
SafeArrayAllocDescriptor()
,
SafeArrayDestroyDescriptor()
- Destroys a descriptor of a safe array.
SafeArrayDestroyDescriptor()
HRESULT SafeArrayDestroyDescriptor((
#include <oleauto.h>
SAFEARRAY FAR* psa
);
Destroys a descriptor of a safe array.
This function is typically used to destroy the descriptor of a safe
array that
contains elements with data types other than variants.
Destroying the array
descriptor does not destroy the elements in the array.
Before destroying the
array descriptor, call
SafeArrayDestroyData()
to free the
elements.
Pointer to a safe array descriptor.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
DISP_E_ARRAYISLOCKED
The array is currently locked.
E_INVALIDARG
The item pointed to by psa is not a safe array descriptor.
SafeArrayAllocData()
,
SafeArrayAllocDescriptor()
,
SafeArrayDestroyData()
- Returns the number of dimensions in the array.
SafeArrayGetDim()
HRESULT SafeArrayGetDim((
#include <oleauto.h>
unsigned int SafeArrayGetDim(psa),
SAFEARRAY FAR* psa
);
Returns the number of dimensions in the array.
Pointer to an array descriptor created by
SafeArrayCreate()
.
Returns the number of dimensions in the array.
HRESULT CEnumPoint::Create(SAFEARRAY FAR* psa, CEnumPoint FAR* FAR* ppenum) { long lBound; HRESULT hresult; CEnumPoint FAR* penum; // Verify that the SafeArray is the proper shape. if(SafeArrayGetDim(psa) != 1) return ReportResult(0, E_INVALIDARG, 0, 0); // Code omitted here for brevity. }
- Retrieves a single element of the array.
SafeArrayGetElement()
HRESULT SafeArrayGetElement((
#include <oleauto.h>
SAFEARRAY FAR* psa,
long FAR* rgIndices,
void FAR* pvData
);
Retrieves a single element of the array.
This function calls
SafeArrayLock()
and
SafeArrayUnlock()
automatically, before and after retrieving
the
element.
The caller must provide a storage area of the correct size to
receive the data.
If the data element is a string, object, or variant,
the function copies the element in the correct way.
Pointer to an array descriptor created by
SafeArrayCreate()
.
Pointer to a vector of indexes for each dimension of the array. The right-most (least significant) dimension is rgIndices[0]. The left-most dimension is stored at rgIndices[psa->cDims - 1].
Pointer to the location to place the element of the array.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
DISP_E_BADINDEX
The specified index is invalid.
E_INVALIDARG
One of the arguments is invalid.
E_OUTOFMEMORY
Memory could not be allocated for the element.
STDMETHODIMP CEnumPoint::Next(ULONG celt, VARIANT FAR rgvar[], ULONG FAR* pceltFetched) { unsigned int i; long ix; HRESULT hresult; for(i = 0; i < celt; ++i) VariantInit(&rgvar[i]); for(i = 0; i < celt; ++i){ if(m_iCurrent == m_celts){ hresult = ReportResult(0, S_FALSE, 0, 0); goto LDone; } ix = m_iCurrent++; hresult = SafeArrayGetElement(m_psa, &ix, &rgvar[i]); if(FAILED(hresult)) goto LError0; } hresult = NOERROR; LDone:; *pceltFetched = i; return hresult; LError0:; for(i = 0; i < celt; ++i) VariantClear(&rgvar[i]); return hresult; }
- Returns the size (in bytes) of the elements of a safe array.
SafeArrayGetElemsize()
HRESULT SafeArrayGetElemsize((
#include <oleauto.h>
unsigned int SafeArrayGetElemsize(psa),
SAFEARRAY FAR* psa
);
Pointer to an array descriptor created by
SafeArrayCreate()
.
Returns the size (in bytes) of the elements of a safe array.
- Returns the lower bound for any dimension of a safe array.
SafeArrayGetLBound()
HRESULT SafeArrayGetLBound((
#include <oleauto.h>
SAFEARRAY FAR* psa,
unsigned int nDim,
long FAR* plLbound
);
Pointer to an array descriptor created by
SafeArrayCreate()
.
The array dimension for which to get the lower bound.
Pointer to the location to return the lower bound.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
DISP_E_BADINDEX
The specified index is out of bounds.
E_INVALIDARG
One of the arguments is invalid.
Returns the lower bound for any dimension of a safe array.
HRESULT CEnumPoint::Create(SAFEARRAY FAR* psa, CEnumPoint FAR* FAR* ppenum) { long lBound; HRESULT hresult; CEnumPoint FAR* penum; // Verify that the SafeArray is the proper shape. hresult = SafeArrayGetLBound(psa, 1, &lBound); if(FAILED(hresult)) return hresult; // Code omitted here for brevity. }
- Returns the upper bound for any dimension of a safe array.
SafeArrayGetUBound()
HRESULT SafeArrayGetUBound((
#include <oleauto.h>
SAFEARRAY FAR* psa,
unsigned int nDim,
long FAR* plUbound,
);
Pointer to an array descriptor created by
SafeArrayCreate()
.
The array dimension for which to get the upper bound.
Pointer to the location to return the upper bound.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
DISP_E_BADINDEX
The specified index is out of bounds.
E_INVALIDARG
One of the arguments is invalid.
Returns the upper bound for any dimension of a safe array.
HRESULT CEnumPoint::Create(SAFEARRAY FAR* psa, CEnumPoint FAR* FAR* ppenum) { long lBound; HRESULT hresult; CEnumPoint FAR* penum; // Verify that the SafeArray is the proper shape. hresult = SafeArrayGetUBound(psa, 1, &lBound); if(FAILED(hresult)) goto LError0; // Code omitted here for brevity. LError0:; penum->Release(); return hresult; }
- Increments the lock count of an array, and places a pointer to the array data
in pvData of the array descriptor.
SafeArrayLock()
HRESULT SafeArrayLock((
#include <oleauto.h>
SAFEARRAY FAR* psa
);
Increments the lock count of an array, and places a pointer to the array data in pvData of the array descriptor.
The pointer in the array descriptor is valid until
SafeArrayUnlock()
is called.
Calls to
SafeArrayLock()
can be nested.
An equal number of calls to
SafeArrayUnlock()
are
required.
An array cannnot be deleted while it is locked.
Pointer to an array descriptor created by
SafeArrayCreate()
.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
E_INVALIDARG
The argument psa was not a valid safe array descriptor.
E_UNEXPECTED
The array could not be locked.
- Returns a pointer to an array element.
SafeArrayPtrOfIndex()
HRESULT SafeArrayPtrOfIndex((
#include <oleauto.h>
SAFEARRAY FAR* psa,
long FAR* rgIndices,
void HUGEP* FAR* ppvData
);
Returns a pointer to an array element.
The array should be locked before
SafeArrayPtrOfIndex()
is called.
Failing
to lock the array can cause unpredictable results.
Pointer to an array descriptor created by
SafeArrayCreate()
.
An array of index values that identify an element of the array. All indexes for the element must be specified.
On return, pointer to the element identified by the values in rgIndices.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
E_INVALIDARG
The argument psa was not a valid safe array descriptor.
DISP_E_BADINDEX
The specified index was invalid.
- Assigns a single element to the array.
SafeArrayPutElement()
HRESULT SafeArrayPutElement((
#include <oleauto.h>
SAFEARRAY FAR* psa,
long FAR* rgIndices,
void FAR* pvData
);
Assigns a single element to the array.
This function automatically calls
SafeArrayLock()
and
SafeArrayUnlock()
before and after assigning the element.
If
the data element is a string, object, or variant, the function copies it
correctly.
If the existing element is a string, object, or variant, it is
cleared correctly.
Multiple locks can be on an array. Elements can be put into an array while the array is locked by other operations.
Pointer to an array descriptor created by
SafeArrayCreate()
.
Pointer to a vector of indexes for each dimension of the array. The right-most (least significant) dimension is rgIndices[0]. The left-most dimension is stored at rgIndices[psa->cDims - 1].
Pointer to the data to assign to the array.
The variant types
VT_DISPATCH
,
VT_UNKNOWN
, and
VT_BSTR
are pointers, and do not require another level of indirection.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
DISP_E_BADINDEX
The specified index was invalid.
E_INVALIDARG
One of the arguments is invalid.
E_OUTOFMEMORY
Memory could not be allocated for the element.
HRESULT PASCAL __export CPoly::EnumPoints(IEnumVARIANT FAR* FAR* ppenum) { unsigned int i; HRESULT hresult; VARIANT var; SAFEARRAY FAR* psa; CEnumPoint FAR* penum; POINTLINK FAR* ppointlink; SAFEARRAYBOUND rgsabound[1]; rgsabound[0].lLbound = 0; rgsabound[0].cElements = m_cPoints; psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound); if(psa == NULL){ hresult = ResultFromScode(E_OUTOFMEMORY); goto LError0; } // Code omitted here for brevity. V_VT(&var) = VT_DISPATCH; hresult = ppointlink->ppoint->QueryInterface(IID_IDispatch, (void FAR* FAR*)&V_DISPATCH(&var)); if(hresult != NOERROR) goto LError1; ix[0] = i; SafeArrayPutElement(psa, ix, &var); ppointlink = ppointlink->next; } hresult = CEnumPoint::Create(psa, &penum); if(hresult != NOERROR) goto LError1; *ppenum = penum; return NOERROR; LError1:; SafeArrayDestroy(psa); LError0:; return hresult; }
- Changes the right-most (least significant) bound of a safe array.
SafeArrayRedim()
HRESULT SafeArrayRedim((
#include <oleauto.h>
SAFEARRAY FAR* psa,
SAFEARRAYBOUND FAR* psaboundNew
);
Changes the right-most (least significant) bound of a safe array.
If you reduce the bound of an array,
SafeArrayRedim()
deallocates the
array elements outside the new array boundary.
If the bound of an array is
increased,
SafeArrayRedim()
allocates and initializes the
new array
elements.
The data is preserved for elements that exist in both the old and
new
array.
Pointer to an array descriptor.
Pointer to a new safe array bound structure that contains the new array boundary. You can change only the least significant dimension of an array.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
DISP_E_ARRAYISLOCKED
The array is currently locked.
E_INVALIDARG
The item pointed to by psa is not a safe array descriptor.
- Decrements the lock count of an array, and invalidates the pointer
retrieved by
SafeArrayUnaccessData()
SafeArrayAccessData()
.
HRESULT SafeArrayUnaccessData((
#include <oleauto.h>
SAFEARRAY FAR* psa
);
Pointer to an array descriptor created by
SafeArrayCreate()
.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
E_INVALIDARG
The argument psa was not a valid safe array descriptor.
E_UNEXPECTED
The array could not be unlocked.
Decrements the lock count of an array, and invalidates the pointer retrieved
by
SafeArrayAccessData()
.
- Decrements the lock count of an array so it can be freed or resized.
SafeArrayUnlock()
HRESULT SafeArrayUnlock((
#include <oleauto.h>
SAFEARRAY FAR* psa
);
Decrements the lock count of an array so it can be freed or resized.
This function is called after access to the data in an array is finished.
Pointer to an array descriptor created by
SafeArrayCreate()
.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
E_INVALIDARG
The argument psa was not a valid safe array descriptor.
E_UNEXPECTED
The array could not be unlocked.
- Allocates a new string and copies the passed string into it.
Returns
SysAllocString()
NULL
if there is insufficient memory, and if
NULL
,
NULL
is passed in.
BSTR SysAllocString((
#include <oleauto.h>
OLECHAR FAR* sz
);
Allocates a new string and copies the passed string into it.
Returns
NULL
if there is insufficient memory, and if
NULL
,
NULL
is passed in.
You can free strings created with
SysAllocString()
using
SysFreeString()
.
A zero-terminated string to copy. The sz parameter must be a Unicode string in 32-bit applications, and an ANSI string in 16-bit applications.
If successful, points to a
BSTR
containing the string.
If insufficient memory exists or
sz
was
NULL
, returns
NULL
.
inline void CStatBar::SetText(OLECHAR FAR* sz) { SysFreeString(m_bstrMsg); m_bstrMsg = SysAllocString(sz); }
- Takes an ANSI string as input, and returns a BSTR that contains
an ANSI string.
Does not perform any ANSI-to-Unicode translation.
SysAllocStringByteLen()
BSTR SysAllocStringByteLen((
#include <oleauto.h>
char FAR* psz,
unsigned int len
);
Takes an ANSI string as input, and returns a
BSTR
that contains an ANSI string.
Does not perform any ANSI-to-Unicode translation.
This function is provided to create
BSTR
s that contain
binary data.
You can use
this type of
BSTR
only in situations where it will not
be translated from ANSI
to Unicode, or vice versa.
For example, do not use these
BSTR
s between a 16-bit
and a 32-bit application
running on a 32-bit Windows system.
The COM 16-bit to 32-bit (and 32-bit to
16-bit) interoperability layer will translate the
BSTR
and corrupt the binary
data.
The preferred method of passing binary data is to use a
SAFEARRAY
of
VT_UI1
, which will not be translated by COM.
If
psz
is
NULL
, a string of
the requested length is allocated, but not
initialized.
The string
psz
can contain embedded
NULL
characters, and
does not need to end with a
NULL
.
Free the returned string
later with
SysFreeString()
.
A zero-terminated string to copy, or
NULL
to keep the string uninitialized.
Number of bytes to copy from
psz.
A
NULL
character is placed afterwards, allocating a total of
len+1 bytes.
Allocates a new string of
len
bytes, copies
len
bytes from the passed string into it, and then appends a
NULL
character.
Valid only for 32-bit systems.
Points to a copy of the string, or
NULL
if insufficient
memory exists.
- Allocates a new string, copies cch characters from the passed string into
it, and then appends a
SysAllocStringLen()
NULL
character.
BSTR SysAllocStringLen((
#include <oleauto.h>
OLECHAR FAR* pch,
unsigned int cch
);
Allocates a new string, copies
cch
characters from
the passed string
into it, and then appends a
NULL
character.
If
pch
is
NULL
, a string of
the requested length is allocated, but not
initialized.
The
pch
string can contain embedded
NULL
characters and
does not need to end with a
NULL
.
Free the returned string
later with
SysFreeString()
.
A pointer to
cch
characters to copy,
or
NULL
to keep the string uninitialized.
Number of characters to copy from
pch.
A
NULL
character is placed afterwards, allocating a total
of
cch+1 characters.
Points to a copy of the string, or
NULL
if insufficient
memory exists.
- Frees a string allocated previously by
SysFreeString()
SysAllocString()
,
SysAllocStringByteLen()
,
SysReAllocString()
,
SysAllocStringLen()
, or
SysReAllocStringLen()
.
void SysFreeString((
#include <oleauto.h>
BSTR bstr
);
Frees a string allocated previously by
SysAllocString()
,
SysAllocStringByteLen()
,
SysReAllocString()
,
SysAllocStringLen()
, or
SysReAllocStringLen()
.
A
BSTR
allocated previously, or
NULL
.
If
NULL
, the function simply returns.
CStatBar::~CStatBar() { SysFreeString(m_bstrMsg); }
- Allocates a new
SysReAllocString()
BSTR
and copies the passed string into
it, then frees the
BSTR
referenced by pbstr, and finally
resets pbstr to point to the new
BSTR
.
BOOL SysReAllocString((
#include <oleauto.h>
BSTR FAR* pbstr,
OLECHAR FAR* sz
);
Allocates a new
BSTR
and copies the passed string
into it, then frees the
BSTR
referenced by
pbstr,
and finally resets
pbstr
to point to the
new
BSTR
.
Points to a variable containing a
BSTR
.
A zero-terminated string to copy.
Returns
FALSE
if insufficient memory exists.
- Creates a new
SysReAllocStringLen()
BSTR
containing a specified number of characters
from an old
BSTR
, and frees the old
BSTR
.
BOOL SysReAllocStringLen((
#include <oleauto.h>
BSTR FAR* pbstr,
OLECHAR FAR* pch,
unsigned int cch
);
Creates a new
BSTR
containing a specified number
of characters from an old
BSTR
, and frees the old
BSTR
.
Allocates a new string, copies
cch
characters from
the passed string
into it, and then appends a
NULL
character.
Frees the
BSTR
referenced currently
by
pbstr, and resets
pbstr
to point
to the new
BSTR
.
If
pch
is
NULL
, a string of length
cch
is allocated but not
initialized.
The
pch
string can contain embedded
NULL
characters and does not need to
end with a
NULL
.
Pointer to a variable containing a
BSTR
.
Pointer to
cch
characters to copy, or
NULL
to keep the string uninitialized.
Number of characters to copy from
pch.
A
NULL
character is placed afterward, allocating a total
of
cch+1 characters.
Returns
TRUE
if the string is reallocated successfully,
or
FALSE
if insufficient memory exists.
- Returns the length (in bytes) of a
SysStringByteLen()
BSTR
.
Valid for 32-bit
systems only.
unsigned int SysStringByteLen((
#include <oleauto.h>
BSTR bstr
);
Returns the length (in bytes) of a
BSTR
.
Valid for
32-bit systems only.
The returned value may be different from
fstrlen(
bstr)
if the
BSTR
was allocated
with
Sys[Re]AllocStringLen
or
SysAllocStringByteLen()
, and the passed-in characters included a
NULL
character in the first
len
characters.
For a
BSTR
allocated with
Sys[Re]AllocStringLen
or
SysAllocStringByteLen()
, this function always returns the number
of bytes specified in the
len
parameter at allocation
time.
A
BSTR
allocated previously.
It cannot
be
NULL
.
The number of bytes in
bstr, not including a terminating
NULL
character.
// Display the status message. TextOut(hdc, rcMsg.left + (m_dxFont / 2), rcMsg.top + ((rcMsg.bottom - rcMsg.top - m_dyFont) / 2), m_bstrMsg, SysStringByteLen(m_bstrMsg));
- Returns the length of a
SysStringLen()
BSTR
.
unsigned int SysStringLen((
#include <oleauto.h>
BSTR bstr
);
Returns the length of a
BSTR
.
The returned value may be different from
_fstrlen(
bstr)
if
the
BSTR
was allocated with
Sys[Re]AllocStringLen
or
SysAllocStringByteLen
, and the passed-in
characters included a
NULL
character in the first
cch
characters.
For a
BSTR
allocated with
Sys[Re]AllocStringLen
or
SysAllocStringByteLen
, this function
always returns the number of characters specified in the
cch
parameter
at allocation time.
A
BSTR
allocated previously.
Cannot be
NULL
.
The number of characters in
bstr, not including
a terminating
NULL
character.
// Display the status message. // TextOut(hdc, rcMsg.left + (m_dxFont / 2), rcMsg.top + ((rcMsg.bottom - rcMsg.top - m_dyFont) / 2), m_bstrMsg, SysStringLen(m_bstrMsg));
- Converts the variant representation of time-to-system time values.
SystemTimeToVariantTime()
int SystemTimeToVariantTime((
#include <oleauto.h>
SYSTEMTIME * psystime,
double * vtime
);
Converts the variant representation of time-to-system time values.
A variant time is stored as an 8-byte real value (double
),
representing
a date between January 1, 1753 and December 31, 2078, inclusive.
The value
2.0
represents January 1, 1900; 3.0 represents January 2, 1900, and so on.
Adding
1
to the value increments the date by a day.
The fractional part of the value
represents the time of day.
Therfore, 2.5 represents noon on January 1, 1900;
3.25 represents 6:00 a.m.
on January 2, 1900, and so on.
Negative numbers
represent the dates prior to December 30, 1899.
The
SYSTEMTIME
structure is useful for the following
reasons:
It spans all time/date periods. MS-DOS date/time is limited to representing only those dates between 1/1/1980 and 12/31/2107.
The date/time elements are all easily accessible without needing to do any bit decoding.
The National Data Support data and time formating functions
GetDateFormat()
and
GetTimeFormat()
take a
SYSTEMTIME
value as input.
The system time.
Returned variant time.
The return value obtained from the returned
HRESULT
is one of the following.
TRUE
Success.
FALSE
Failure.
- Converts a variant from one type to another.
VariantChangeType()
HRESULT VariantChangeType((
#include <oleauto.h>
VARIANTARG FAR* pvargDest,
VARIANTARG FAR* pvargSrc,
unsigned short wFlags,
VARTYPE vtNew
);
Converts a variant from one type to another.
The
VariantChangeType()
function handles coercions
between the fundamental
types (including numeric-to-string and string-to-numeric coercions).
A variant
that has
VT_BYREF
set is coerced to a value by obtaining
the referenced value.
An object is coerced to a value by invoking the object's
Value
property
(DISPID_VALUE
).
Typically, the implementor of
IDispatch::Invoke()
determines which
member is being accessed, and then calls
VariantChangeType()
to get the
value of one or more arguments.
For example, if the
IDispatch()
call specifies a
SetTitle
member that takes one string
argument, the
implementor would call
VariantChangeType()
to attempt to
coerce the
argument to
VT_BSTR
.
If
VariantChangeType()
does not return an
error, the argument could then be obtained directly from the
bstrVal
field of the
VARIANTARG
.
If
VariantChangeType()
returns
DISP_E_TYPEMISMATCH
, the implementor would set *puArgErr
to 0
(indicating the argument in error) and return
DISP_E_TYPEMISMATCH
from
IDispatch::Invoke()
.
Arrays of one type cannnot be converted to arrays of another type with this function.
The type of a
VARIANTARG
should not be changed in the rgvarg array in place.
Pointer to the
VARIANTARG
to receive the
coerced
type.
If this is the same as
pvargSrc, the variant will
be converted in place.
Pointer to the source
VARIANTARG
to be
coerced.
Flags that control the coercion.
The only defined flag is
VARIANT_NOVALUEPROP
, which prevents the function from attempting
to coerce an object to a fundamental type by getting the
Value
property.
Applications should set this flag only if necessary, because it
makes their behavior inconsistent with other applications.
The type to coerce to.
If the return code is
S_OK
,
the
vt
field of the *pvargDest
is
always the same as this value.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
DISP_E_BADVARTYPE
The variant type vtNew is not a valid type of variant.
DISP_E_OVERFLOW
The data pointed to by pvargSrc does not fit in the destination type.
DISP_E_TYPEMISMATCH
The argument could not be coerced to the specified type.
E_INVALIDARG
One of the arguments is invalid.
E_OUTOFMEMORY
Memory could not be allocated for the conversion.
- Converts a variant from one type to another, using a locale ID.
VariantChangeTypeEx()
HRESULT VariantChangeTypeEx((
#include <oleauto.h>
VARIANTARG FAR* pvargDest,
VARIANTARG FAR* pvargSrc,
LCID lcid,
unsigned short wFlags,
VARTYPE vtNew
);
Converts a variant from one type to another, using a locale ID.
The
VariantChangeTypeEx()
function handles coercions
between the
fundamental types (including numeric-to-string and string-to-numeric
coercions).
To change a type with the
VT_BYREF
flag set
to one without
VT_BYREF
, change the referenced value to
VariantChangeTypeEx()
.
To
coerce objects to fundamental types, obtain the value of the
Value
property.
Typically, the implementor of
IDispatch::Invoke()
determines which
member is being accessed, and then calls
VariantChangeType()
to get
the value of one or more arguments.
For example, if the
IDispatch()
call specifies a
SetTitle
member that takes one string
argument, the
implementor would call
VariantChangeTypeEx()
to attempt
to coerce the
argument to
VT_BSTR
.
If
VariantChangeTypeEx()
does not return an error,
the argument could then
be obtained directly from the
bstrVal
field of the
VARIANTARG
.
If
VariantChangeTypeEx()
returns
DISP_E_TYPEMISMATCH
, the implementor would
set *puArgErr
to 0 (indicating the argument in error)
and return
DISP_E_TYPEMISMATCH
from
IDispatch::Invoke()
.
Arrays of one type cannot be converted to arrays of another type with this function.
The type of a
VARIANTARG
should not be changed in the rgvarg array in place.
Pointer to the
VARIANTARG
to receive the
coerced
type.
If this is the same as
pvargSrc, the variant will
be converted in place.
Pointer to the source
VARIANTARG
to be
coerced.
The locale ID for the variant to coerce.
The locale ID is
useful when
the type of the source or destination
VARIANTARG
is
VT_BSTR
,
VT_DISPATCH
, or
VT_DATE
.
Flags that control the coercion.
The only defined flag is
VARIANT_NOVALUEPROP
, which prevents the function from attempting
to coerce an object to a fundamental type by getting its
Value
property.
Applications should set this flag only if necessary, because it
makes their behavior inconsistent with other applications.
The type to coerce to.
If the return code is
S_OK
,
the
vt
field of the *pvargDest
is
guaranteed to be equal to this value.
The return value obtained from the returned
HRESULT
is one of the following.
S_OK
Success.
DISP_E_BADVARTYPE
The variant type vtNew is not a valid type of variant.
DISP_E_OVERFLOW
The data pointed to by pvargSrc does not fit in the destination type.
DISP_E_TYPEMISMATCH
The argument could not be coerced to the specified type.
E_INVALIDARG
One of the arguments is invalid.
E_OUTOFMEMORY
Memory could not be allocated for the conversion.
- Clears a variant.
VariantClear()
HRESULT VariantClear((
#include <oleauto.h>
VARIANTARG FAR* pvarg
);
Clears a variant.
Use this function to clear variables of type
VARIANTARG
(or
VARIANT
) before the
memory containing the
VARIANTARG
is freed (as when a local
variable goes out of
scope).
The function clears a
VARIANTARG
by setting the
vt
field to
VT_EMPTY
and
the
wReserved
field to 0.
The current contents of the
VARIANTARG
are released first.
If the
vt
field is
VT_BSTR
, the string is freed.
If
the
vt
field is
VT_DISPATCH
, the object
is released.
If the
vt
field has the
VT_ARRAY
bit set,
the array is freed.
In certain cases, it may be preferable to clear a variant in code without
calling
Pointer to the
The return value obtained from the returned
Success.
The variant contains an array that is locked.
The variant type
pvarg
is not a valid
type of variant.
One of the arguments is invalid.
HRESULT VariantCopy((
Frees the destination variant and makes a copy of the source variant.
First, free any memory that is owned by
pvargDest,
such as
If
pvargSrc
is a
Pointer to the
Pointer to the
The return value obtained from the returned
Success.
The variant contains an array that is locked.
The source and destination have an invalid variant type (usually
uninitialized).
Memory could not be allocated for the copy.
The argument
pvargSrc
was
HRESULT VariantCopyInd((
Frees the destination variant and makes a copy of the source
This function is useful when a copy of a variant is needed, and to guarantee
that it is not
For example, if the source is a
If
pvargSrc
is ( This function frees any existing contents of
pvarDest.
Pointer to the
Pointer to the
The return value obtained from the returned
Success.
The variant contains an array that is locked.
The source and destination have an invalid variant type (usually
uninitialized).
Memory could not be allocated for the copy.
The argument
pvargSrc
was
void VariantInit((
Initializes a variant.
The
Pointer to the
int VariantTimeToDosDateTime((
Converts the variant representation of a date and time to MS-DOS date
and time
values.
A variant time is stored as an 8-byte real value ( For a description of the MS-DOS date and time formats, see
The variant time to convert.
Pointer to the location to store the converted MS-DOS date.
Pointer to the location to store the converted MS-DOS time.
The return value obtained from the returned
Success.
Failure.
int VariantTimeToSystemTime((
Converts the variant representation of time-to-system time values.
A variant time is stored as an 8-byte real value ( Using the
It spans all time/date periods.
MS-DOS date/time is limited
to
representing only those dates between 1/1/1980 and 12/31/2107.
The date/time elements are all easily accessible without needing
to do any bit decoding.
The National Language Support data and time formating functions
The variant time that will be converted.
Pointer to the location where the converted time will be stored.
The return value obtained from the returned
Success.
Failure.
HRESULT VarNumFromParseNum((
Parsed results.
Array.
Contains one bit set for each type that is acceptable as a
return value
(in many cases, just one bit).
Result variant.
The return value obtained from the returned
Success.
Out of memory.
The number is too large to be represented in an allowed type.
There
is no error if precision is lost in the conversion.
Once the number is parsed, the caller can call
The
rgbDig
array is filled in with the values for
the digits in the
range 0-7, 0-9, or 0-15, depending on whether the number is octal, decimal,
or
hexadecimal.
All leading zeros have been stripped off.
For decimal numbers,
trailing zeros are also stripped off, unless the number is zero, in which
case
a single zero digit will be present.
For rounding decimal numbers, the digit array must be at least one digit
longer
than the maximum required for data types.
The maximum number of digits required
for the
HRESULT VarParseNumFromStr((
[in]
strIn
lcid
dwFlags
Allows the caller to control parsing, therefore defining the acceptable
syntax of a number.
If this field is set to zero, the input string must contain
nothing but decimal digits.
Setting each defined flag bit enables parsing
of that syntactic feature.
Standard Automation parsing (for example, as used
by
The return value obtained from the returned
Success.
Internal memory allocation failed.
(Used for
There is no valid number in the string, or there is no closing
parenthesis
to match an opening one.
In the former case,
cDig
and
cchUsed
in the
For hexadecimal and octal digists, there are more digits than
will fit
into the array.
For decimal, the exponent exceeds the maximum possible.
In
both cases, the
Parses a string, and creates a type-independent description of the number
it
represents.
The first three parameters are identical to the first three
parameters of
The
HRESULT VectorFromBstr((
The
On exit,
ppsa
points to a one-dimensional
safe
array containing the characters in the
The return value obtained from the returned
Success.
Out of memory.
Returns a vector, assigning each character in the
The caller of
The
cDig
element is set to the size of the
rgbDig array, and
dwInFlags
is set to parsing options.
All other elements
may be
uninitialized and are set by the function, except on error, as described in
the
following paragraphs.
The
cDig
element is also modified
by the function
to reflect the actual number of digits written to the
rgbDig
array.
The
cchUsed
element of the
The
nBaseShift
element gives the number of bits
per digit (3 or 4 for
octal and hexadecimal numbers, and zero for decimal).
The following applies only to decimal numbers:
nPwr10
sets the decimal point position
by giving the power
of 10 of the least significant digit.
If the number is negative,
If there are more non-zero decimal digits than will fit into
the
digit array, the
The definition for a safe array varies, depending on the target operating
system platform.
On 32-bit Windows systems, both the
cbElements
and
cLocks
parameters are unsigned long integers, and
the
handle
parameter is omitted.
On 16-bit Windows systems,
cbElements
and
cLocks
are unsigned
short integers.
The
handle
parameter is retained for compatibility with
earlier software.
For example:
The array
Represents the bounds of one dimension of the array.
The lower bound
of the dimension is
represented by
lLbound, and
cElements
represents the
number of elements in the dimension.
The structure is defined as follows:
VariantClear()
.
For example, you can change the
type of a
VT_I4
variant to another type without calling this function.
However, you must call
VariantClear()
if a
VariantClear()
in these cases ensures that code will continue
to work if
Automation adds new variant types in the future.
Parameters
VARIANTARG
to clear.
Return Values
HRESULT
is one of the following.
S_OK
DISP_E_ARRAYISLOCKED
DISP_E_BADVARTYPE
E_INVALIDARG
Examples
for(i = 0; i < celt; ++i)
VariantClear(&rgvar[i]);
VariantCopy()
NAME
- Frees the destination variant and makes a copy of the source variant.
VariantCopy()
Synopsis
#include <oleauto.h>
VARIANTARG FAR* pvargDest,
VARIANTARG FAR* pvargSrc
);
Description
VariantClear()
(pvargDest
must point
to a valid initialized
variant, and not simply to an uninitialized memory location).
Then
pvargDest
receives an exact copy of the contents of
pvargSrc.
VT_BSTR
, a
copy of the string is made.
If
pvargSrcis a
VT_ARRAY
, the entire array is copied.
If
pvargSrc
is a
VT_DISPATCH
or
VT_UNKNOWN
,
AddRef()
is called to increment the object's
reference count.
Parameters
VARIANTARG
to receive the
copy.
VARIANTARG
to be copied.
Return Values
HRESULT
is one of the following.
S_OK
DISP_E_ARRAYISLOCKED
DISP_E_BADVARTYPE
E_OUTOFMEMORY
E_INVALIDARG
VT_BYREF
.
VariantCopyInd()
NAME
- Frees the destination variant and makes a copy of the source
VariantCopyInd()
VARIANTARG
,
performing the necessary indirection if the source is specified to be
VT_BYREF
.
Synopsis
#include <oleauto.h>
VARIANT FAR* pvarDest,
VARIANTARG FAR* pvargSrc
);
Description
VARIANTARG
,
performing the necessary indirection if the source is specified to be
VT_BYREF
.
VT_BYREF
, such as when handling arguments
in an implementation
of
IDispatch::Invoke()
.
(VT_BYREF | VT_I2)
,
the destination will be a
BYVAL | VT_I2
.
The same is true for all legal
VT_BYREF
combinations, including
VT_VARIANT
.
VT_BYREF
|
VT_VARIANT
), and the contained variant is
VT_BYREF
, the contained variant is also dereferenced.
Parameters
VARIANTARG
that will receive
the copy.
VARIANTARG
that will be
copied.
Return Values
HRESULT
is one of the following.
S_OK
DISP_E_ARRAYISLOCKED
DISP_E_BADVARTYPE
E_OUTOFMEMORY
E_INVALIDARG
VT_ARRAY
.
VariantInit()
NAME
- Initializes a variant.
VariantInit()
Synopsis
#include <oleauto.h>
VARIANTARG FAR* pvarg
);
Description
VariantInit()
function initializes the
VARIANTARG
by setting the
vt
field to
VT_EMPTY
.
Unlike
VariantClear()
, this
function does not interpret the current contents of the
VARIANTARG
.
Use
VariantInit()
to initialize new local variables of type
VARIANTARG
(or
VARIANT
).
Parameters
VARIANTARG
that will be
initialized.
Examples
for(i = 0; i < celt; ++i)
VariantInit(&rgvar[i]);
VariantTimeToDosDateTime()
NAME
- Converts the variant representation of a date and time to MS-DOS
date and time values.
VariantTimeToDosDateTime()
Synopsis
#include <oleauto.h>
double vtime,
unsigned short FAR* pwDOSDate,
unsigned short FAR* pwDOSTime
);
Description
double
),
representing
a date between January 1, 1753 and December 31, 2078, inclusive.
The value
2.0
represents January 1, 1900; 3.0 represents January 2, 1900, and so on.
Adding
1
to the value increments the date by a day.
The fractional part of the value
represents the time of day.
Therefore, 2.5 represents noon on January 1, 1900;
3.25 represents 6:00 a.m.
on January 2, 1900, and so on.
Negative numbers
represent the dates prior to December 30, 1899.
DosDateTimeToVariantTime()
.
Parameters
Return Values
HRESULT
is one of the following.
TRUE
FALSE
VariantTimeToSystemTime()
NAME
- Converts the variant representation of time-to-system time values.
VariantTimeToSystemTime()
Synopsis
#include <oleauto.h>
double vtime,
SYSTEMTIME * psystime
);
Description
double
),
representing
a date between January 1, 1753 and December 31, 2078, inclusive.
The value
2.0
represents January 1, 1900; 3.0 represents January 2, 1900, and so on.
Adding
1
to the value increments the date by a day.
The fractional part of the value
represents the time of day.
Therefore, 2.5 represents noon on January 1, 1900;
3.25 represents 6:00 A.M
.
on January 2, 1900, and so on.
Negative numbers
represent the dates prior to December 30, 1899.
SYSTEMTIME
structure is useful because:
GetDateFormat()
and
GetTimeFormat()
take a
SYSTEMTIME
value as input.
Parameters
Return Values
HRESULT
is one of the following.
TRUE
FALSE
VarNumFromParseNum()
NAME
- Converts parse results to a number.
VarNumFromParseNum()
Synopsis
#include <oleauto.h>
[in] NUMPARSE * pnumprs,
[in] unsigned char * rgbDig,
[in] unsigned long dwVtBits,
[out] VARIANT * pvar
);
Parameters
Return Values
HRESULT
is one of the following.
S_OK
E_OUTOFMEMORY
DISP_E_OVERFLOW
VarNumFromParseNum()
to
convert the parse results to a number.
The
NUMPARSE
structure
and digit array
must be passed in unchanged from the
VarParseNumFromStr()
call.
This function will choose the smallest type allowed that can hold the result
value with as little precision loss as possible.
The result variant is an
[out]
parameter, so its contents are not freed before storing the result.
DECIMAL
data type is 29, so the digit array must
have room for 30
digits.
There must also be enough digits to accept the number in octal, if
that
parsing options is selected.
(Hexadecimal and octal numbers are limited by
VarNumFromParseNum()
to the magnitude of an
unsigned
long
[32
bits], so they need 11 octal digits.)
VarParseNumFromStr()
NAME
- Parses a string, and creates a type-independent description of the number
it represents.
VarParseNumFromStr()
Synopsis
#include <oleauto.h>
[in] OLECHAR* strIn,
[in] LCID lcid,
[in] unsigned long dwFlags,
[in] NUMPARSE * pnumprs,
[out] unsigned char * rgbDig
);
Parameters
VarI2FromStr
) has all flags set (NUMPRS_STD
).
Return Values
HRESULT
is one of the following.
S_OK
E_OUTOFMEMORY
DBCS
only to create a copy with all wide characters mapped narrow.)
DISP_E_TYPEMISMATCH
NUMPARSE
structure will be zero.
In the latter, the
NUMPARSE
structure and digit array are
fully updated, as if the closing parenthesis was present.
DISP_E_OVERFLOW
NUMPARSE
structure and digit array are
fully updated (for decimal, the
cchUsed
field excludes
the entire exponent).
VarI2FromStr, VarI4FromStr, VarR8FromStr,
and so on.
The
fourth parameter is a pointer to a
NUMPARSE
structure,
which contains both
input information to the function as well as the results, as described above.
The last parameter is a pointer to an array of digits, filled in by the
function.
VarParseNumFromStr()
function fills in the
dwOutFlags
element
with each corresponding feature that was actually found in the string.
This
allows the caller to make decisions about what numeric type to use for the
number, based on the format in which it was entered.
For example, one
application might want to use the
CURRENCY
data type if
the currency symbol is
used, and others may want to force a floating point type if an exponent was
used.
VectorFromBstr()
NAME
- Returns a vector, assigning each character in the
VectorFromBstr()
BSTR
to an element of the vector.
Synopsis
#include <oleauto.h>
BSTR bstr,
SAFEARRAY FAR* FAR* ppsa
);
Parameters
BSTR
to be converted to a vector.
BSTR
.
Return Values
HRESULT
is one of the following.
S_OK
E_OUTOFMEMORY
E_INVALIDARG
BSTR
is
NULL
.
BSTR
to an element of the
vector.
19.6 Automation Related Structure Definitions
19.6.1 NUMPARSE
VarParseNumFromStr()
must initialize
two elements
of the passed-in
NUMPARSE
structure:
typedef struct {
int cDig;
unsigned long dwInFlags;
unsigned long dwOutFlags;
int cchUsed;
int nBaseShift;
int nPwr10;
} NUMPARSE;
NUMPARSE
sturcture is filled in with the
number of characters (from the beginning of the string) that were successfully
parsed.
This allows the caller to determine if the entire string was part
of
the number (as required by functions such as
VarI2FromStr
),
or where to
continue parsing the string.
NUMPRS_NEG
will
be set in
dwOutFlags.
NUMPRS_INEXACT
flag will be set.
19.6.2 SAFEARRAY
typedef struct FARSTRUCT tagSAFEARRAY {
unsigned short cDims; // Count of dimensions in this array.
unsigned short fFeatures; // Flags used by the SafeArray
// routines documented below.
#if defined(WIN32)
unsigned long cbElements; // Size of an element of the array.
// Does not include size of
// pointed-to data.
unsigned long cLocks; // Number of times the array has been
// locked without corresponding unlock.
#else
unsigned short cbElements;
unsigned short cLocks;
unsigned long handle; // Unused but kept for compatibility.
#endif
void HUGEP* pvData; // Pointer to the data.
SAFEARRAYBOUND rgsabound[1]; // One bound for each dimension.
} SAFEARRAY;
rgsabound
is stored with the left-most
dimension in
rgsabound[0]
and the right-most dimension in
rgsabound[cDims - 1]
.
If an array was specified in a
C-like syntax as a
[2][5]
, it would have two elements in
the
rgsabound
vector.
Element 0 has an
lLbound
of 0
and a
cElements
of 2.
Element 1 has an
lLbound
of 0 and a
cElements
of 5.
The
fFeatures
flags describe attributes of an array that
can affect
how the array is released.
This allows freeing the array without referencing
its containing variant.
The bits are accessed using the following constants:
#define FADF_AUTO 0x0001 // Array is allocated on the stack.
#define FADF_STATIC 0x0002 // Array is statically allocated.
#define FADF_EMBEDDED 0x0004 // Array is embedded in a structure.
#define FADF_FIXEDSIZE 0x0010 // Array may not be resized or
// reallocated.
#define FADF_BSTR 0x0100 // An array of BSTRs.
#define FADF_UNKNOWN 0x0200 // An array of IUnknown*.
#define FADF_DISPATCH 0x0400 // An array of IDispatch*.
#define FADF_VARIANT 0x0800 // An array of VARIANTs.
#define FADF_RESERVED 0xF0E8 // Bits reserved for future use.
19.6.3 SAFEARRAYBOUND
typedef struct tagSAFEARRAYBOUND {
unsigned long cElements;
long lLbound;
} SAFEARRAYBOUND;