PRB: MMC Samples/Tutorials Does Not Work on Windows 95
ID: Q182220
|
The information in this article applies to:
-
Microsoft Management Console, version 1.0
on the following platforms: Win95
SYMPTOMS
The Microsoft Management Console SnapIn samples do not execute on Windows
95 when they are compiled using the UNICODE switch. Snap-Ins compiled as
UNICODE-only do not register themselves properly on Windows 95. Windows 95
does not support UNICODE. Therefore, the samples must be modified to
support ANSI strings when calling Win32 APIs.
CAUSE
The Registry APIs on Windows 95 do not support UNICODE strings.
RESOLUTION
You can modify the samples to allow them to run on Windows 95 using ANSI
strings. To do this:
- In the DllRegisterServer and DllUnregisterServer functions, change the
way the string constants are declared. Use the _T("") macro to define
the string constants sent the Reg* APIs. For example:
nErr = RegOpenKey( HKEY_LOCAL_MACHINE,
L"Software\\Microsoft\\MMC\\SnapIns",
&hMmcParentKey);
Should be changed to:
nErr = RegOpenKey( HKEY_LOCAL_MACHINE,
_T("Software\\Microsoft\\MMC\\SnapIns"),
&hMmcParentKey);
The _T("") macro will be expanded to the appropriate string constant
based on the UNICODE switch.
- In the DisplayError function, change it to accept and use LPTSTR
string types.
- Change all references to ATLTRACE to use the _T("") macro to define text
constants. To find these references, use the Find In Files command from
the Edit menu and then click each entry in the Find In Files list.
Several of the .cpp files use this macro to display trace messages in
the results window of Visual C++.
- In the CDataObject constructor, calls are made to
RegisterClipboardFormat. The standard definitions in the MMC.h file
define all of the clipboard format strings in UNICODE. These strings
must be converted to ASCIIZ strings when the UNICODE switch is turned
off. You can use conditional compilation to insure that the strings
passed to RegisterClipboardFormat are the correct type. The
CDataObject::CDataObject function was changed to read as follows:
// These are the clipboard formats that you must supply at a minimum.
// MMC.h actually defined these. You can make up your own to use for
// other reasons. You don't need any others at this time.
//
// For ANSI, convert the format labels to ANSI if UNICODE
// is not defined.
// Leave them alone if they are OK.
//
#ifndef UNICODE
//
// If you are building an ANSI project, the
// RegisterClipboardFormat strings must be ANSI. From the MMC
// headers, the strings are UNICODE and they must be converted to
// ANSI in order to register them properly.
//
// Use conditional compilation to get the job done.
//
char buffer[256];
wcstombs( buffer, CF_SNAPIN_INTERNAL,
wcslen(CF_SNAPIN_INTERNAL)+1);
s_cfInternal = RegisterClipboardFormat((LPCSTR)buffer);
wcstombs( buffer, CCF_DISPLAY_NAME, wcslen(CCF_DISPLAY_NAME)+1);
s_cfDisplayName = RegisterClipboardFormat((LPCSTR)buffer);
wcstombs( buffer, CCF_NODETYPE, wcslen(CCF_NODETYPE)+1);
s_cfNodeType = RegisterClipboardFormat((LPCSTR)buffer);
wcstombs( buffer, CCF_SNAPIN_CLASSID,
wcslen(CCF_SNAPIN_CLASSID)+1);
s_cfSnapinClsid = RegisterClipboardFormat((LPCSTR)buffer);
#else
//
// UNICODE is defined, the clipboard formats will be OK.
//
s_cfInternal = RegisterClipboardFormat( CF_SNAPIN_INTERNAL);
s_cfDisplayName = RegisterClipboardFormat(CCF_DISPLAY_NAME);
s_cfNodeType = RegisterClipboardFormat(CCF_NODETYPE);
s_cfSnapinClsid = RegisterClipboardFormat(CCF_SNAPIN_CLASSID);
#endif
- As a general rule, use LPTSTR to define the strings pointers used in
Win32 API calls. Use the _T("") macro for all text constants.
- Use OLESTR inside the SnapIn. Microsoft Management Console expects
UNICODE strings and will perform conversions as necessary.
STATUS
Microsoft is researching this problem and will post new information here in
the Microsoft Knowledge Base and http://www.microsoft.com/management as it
becomes available.
MORE INFORMATION
Microsoft Management Console is a user interface framework. Microsoft
Management Console does not provide any additional APIs to assist in
administering users, machines, or network resources from Windows 95.
SnapIns are limited to the functionality available on the target operating
system. When developing a SnapIn that will target both Windows NT and
Windows 95, you need to insure that the SnapIn does not use OS specific
methods to accomplish a task.
REFERENCES
Samples distributed via the ISysMgmt.exe and IBLDEnv.exe self-extracting
zip files through the Platform SDK (http://www.microsoft.com/management)
and Microsoft Management Console
(http://www.microsoft.com/msdn/sdk/platform.htm )Web sites.
Additional query words:
MMC, samples, tutorial,
Keywords : kbMMC
Version : WINDOWS:1.0
Platform : WINDOWS
Issue type : kbprb