I have been able to programmatically retrieve the MCL in
Outlook 97/98 and 2000 using a Class I found on the Net
that wraps the Registry API functions:
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dnovba01/html/RegistryMadeEasy.asp
But when I try with Outlook 2002, I get an (unsupported
data format) message.
It seems the MCL is in Binary (D_WORD?) format. I have
tried various VB functions like AscB, CStr, Chr, etc., in
various combinations, to convert it to something usable in
VB, with no luck.
Any ideas would be very welcome.
The documentation for the class, available at the above
URL, states that it returns a Variant. However, I have had
success with Outlook 97/98 and 2000, just assigning the
return value to a String. This clearly won't work with
Outlook 2002.
Also, Does anyone know where & how the MCL will be stored
in Outlook 2003?
Thanks a lot,
-Andrew
To read the list is easy, take a look at the code sample using WSH for
reading a user's master
category list from the registry at
http://www.cdolive.com/cdo5.htm#ReadMasterCategories, it shows how to
do it for all versions of Outlook.
To write to the registry for the master category list you'd want to
use the Win32 API functions since the WSH RegWrite function can write
binary values to the registry, but
it can only write a DWORD's worth (4 bytes). Not very useful for
categories.
What you would have to do is use the Win32 API RegSetValueEx registry
function for that, with a type of REG_BINARY (3). You would get the
string you want to write to the master categories list and break it
apart character by character. After each character you would add a
CHR(0) value.
For a list of categories the easiest way would probably be to break
apart the list using the Split function to get each entry into an
array element. The Split character would be a comma. Then you would
construct a string to write to MasterList, including the commas after
each category from each element of the array.
Here's a very simple example that writes the string "Foo" as a new
master category list entry. Just remember that MasterList won't exist
unless you have previously added a new category to the master list, or
you create the key using the Win32 API functions to create it.
Const REG_BINARY = 3
Const HKEY_CURRENT_USER = &H80000001
Const ERROR_NONE = 0
Const KEY_ALL_ACCESS = &H3F
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" _
Alias "RegOpenKeyExA" _
(ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByVal ulOptions As Long, _
ByVal samDesired As Long, _
phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" _
Alias "RegSetValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, _
lpData As Any, _
ByVal cbData As Long) As Long
Sub WriteNewCategory()
Dim hKey As Long
Dim lRetVal As Long
Dim sCategory As String
Dim lLen As Long
Dim sKeyName As String
sKeyName = "Software\Microsoft\Office\10.0\Outlook\Categories"
sCategory = "F" & Chr(0) & "o" & Chr(0) & "o" & Chr(0)
lLen = Len(sCategory)
lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyName, 0&, _
KEY_ALL_ACCESS, hKey)
If lRetVal = ERROR_NONE Then
lRetVal = RegSetValueEx(hKey, "MasterList", 0&, REG_BINARY, _
ByVal sCategory, lLen)
End If
End Sub
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm
"Andrew Cushen" <and...@REMOVETOREPLYcushen.com> wrote in message
news:14cd01c321ac$3d13b8a0$a301...@phx.gbl...
I found a VB function that will read binary values from
the Registry at:
http://www.vb2themax.com/Item.asp?PageID=CodeBank&ID=238
There is a link at the bottom of the page to a function
that will write binary values.
I did in fact find the WSH code you mention at
cdolive.com, but had some trouble translating it to VB.
Dropping the function I mentioned into my VB project as a
Module did the trick.
So you are saying that, just like reading the MCL, there
is no way to create a new Category programmatically, other
than adding it to the end of the Registry value? This
seems rather short-sighted by the Outlook VBA team.. .
Thanks again.
-Andrew
>.
>
"Andrew Cushen" <and...@NOSPAMcushen.com> wrote in message news:059201c327c1$7a58d7c0$a001...@phx.gbl...