HrGetOneProp), not a string.
What is the complete source code for the MAPIProp function?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Hi Dmitry,
it's like example on
http://www.mapilab.com/articles/vb_outlook_security_4.html and it
works
fine
(only for strings) with CDO
Gabi
Newsbeitrag
PropValue declaration is completely wrong - it is a union struct
with
a
bunch of fields for different prop types (Value.lpszA for
PT_STRING8,
Values.lpszW for PT_UNICODE, Value.l for PT_LONG, etc).
You are essentially casting a pointer to LPSPropValue to PChar using
a
variable declared as Long when you are trying to retrieve a pointer
to
a
string.
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Yes I am.
Here's some code
Option Explicit
Private Declare Function MAPIInitialize Lib "mapi32.dll" (ByVal
lpMapiInit
As Long) As Long
Private Declare Function MAPIFreeBuffer Lib "mapi32" (ByVal
lppProp
As
Long)
As Long
Private Declare Function HrGetOneProp Lib "mapi32" Alias
"HrGetOneProp@12"
(ByVal lpMapiProp As IUnknown, ByVal ulPropTag As Long, ByRef
lppProp
As
Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias
"RtlMoveMemory"
(Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function lstrlenA Lib "kernel32.dll" (ByVal
lpString
As
Long) As Long
Private Type PropValue
ulPropTag As Long
dwAlignPad As Long
val1 As Long
val2 As Long
val3 As Long
End Type
Private Const Prop_Sender As Long = &HC1A001E
Public Sub CheckForMAPIProp(ByVal objItem As Object)
Dim vValue As Variant, lResult As Long
Call MAPIInitialize(0)
vValue = MAPIProp(objItem.MAPIOBJECT, Prop_Sender, lResult)
MsgBox vValue, , CStr(lResult)
' RETURNS: vValue = ""; lResult = 6
Dim objSession As MAPI.Session, objMessage As MAPI.Message
Set objSession = New MAPI.Session
objSession.Logon "", "", False, False
Set objMessage = objSession.GetMessage(objItem.EntryID)
vValue = MAPIProp(objMessage.MAPIOBJECT, Prop_Sender, lResult)
MsgBox vValue, , CStr(lResult)
' RETURNS: vValue = "SenderName"; lResult = 0
...
...
End Sub
Private Function MAPIProp(ByVal objMAPIObject As IUnknown, PropID
As
Long,
lResult As Long) As Variant
Dim Prop As PropValue, ptrProp As Long, lLen As Long, lPos As
Long,
sRes
As
String
lResult = HrGetOneProp(objMAPIObject, PropID, ptrProp)
If lResult = 0 Then
CopyMemory Prop, ByVal ptrProp, 20
....
....
End If
End Function
Works fine with CDO but not with OOM (ErrCode really 6)
Gabi
Newsbeitrag
Are you sure? HrGetOneProp *only* resurns S_OK (0) or an error
( <
0).
It
does not return non-critical errors (>0).
Did you mean LPSPropValue out parameter in HrGetOneProp?
Does the property that you are trying to retrieve exist on that
particular
message? Did you check with MdbView or OutlookSpy?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Hi Dmitry,
lResult = 6
and I want to use HrGetOneProp in a Standalone Prog (not