cr
Nybegynder
28. juni 2002 - 09:11
Der er
5 kommentarer og
1 løsning
istream, IPersistStream og persistens i Visual Basic (.net)??
Hej
Jeg har følgende problem. Jeg skal bruge en istream eller en ipersiststream til at kommunikere med et com objekt. Jeg har ikke den store erfaring i windows programmering og det værktøj som jeg har tilrådighed er Visual Basic .net.
Det jeg har kunne finde ud af indtil nu er at man ikke direkte kan bruge istream eller ipersistream i visual basic (er vist nok c++ funktioner), men at man kan bruge dem indirekte ved at gøre en objekt i vb persistent? Er det rigtigt. Hvordan gør man et objekt persistent i VB, er det en property eller hva?
Jeg ville bliver meget glad for kode eksempler eller links til kode eksempler hvor man kan se en istream bliver operette i VB helst i en .net version, men en vb6.0 version er bedre end igen ting (tror jeg).
Bare skriv hvis jeg skal uddybe problemet yderligere, jeg er ikke sikker på at ovenståene er helt forståeligt.
Her er noget med en IStream, ved ikke lige om det kan bruges :O)
Methods
Name Description
Delete Deletes the specified Message object and the associated file from which the object was derived.
DeleteAll Deletes all Message objects in the collection and all associated files on the file system.
Remarks
The IDropDirectory.GetMessages method returns a Messages collection object containing messages from a specified file system folder. You can get the total count of Message objects in the collection using the IMessages.Count property and retrieve one of the messages by using the IMessages.Item method, and you can get the name of the file that houses the message on the file system by using the IMessages.Filename property. To enumeration the collection, use the IMessage._NewEnum property. In Visual Basic, this happens automatically when a For Each Obj in Collection statement is used.
Example
This example demonstrates how you can use the DropDirectory object (exposing the IDropDirectory interface) to enumerate the messages in the Simple Mail Transfer Protocol (SMTP) default drop directory and then copy each message addressed to a particular local account into the appropriate account mailbox directory; for example, you can locate the local Administrator account's personal mail directory in c:\maiboxes\administrator directory.
[Visual Basic]
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Dim iDropDir as New CDO.DropDirectory
Dim iMsgs as CDO.IMessages
Dim iMsg as CDO.Message
Dim iStream as ADODB.Stream
Dim strTo as String
Dim ToRecipients as Variant
Dim strEmailName as String
Dim strAccountName as String
Dim strFileName as String
Dim strMailboxDir as String
Set iMsgs = iDropDir.GetMessages
For Each iMsg in iMsgs
strFileName = iMsgs.FileName(iMsg)
' trim to get the short file name
' from the full path
strFileName = Right(strFileName, Len(strFileName) - InStrRev(strFileName,"\") )
' Get the To recipients...and assume they are all local accounts
strTo = iMsg.To
ToRecipients = Split(strTo,",")
Dim j, lpos, rpos, posdiff
' loop through recipients and get account names for each.
' We get the account name by getting the string
' between "<" and "@" in the address.
For j = LBound(ToRecipients) to UBound(ToRecipients)
strEmailName = ToRecipients(j)
lpos = InStr(strEmailName,"<")
rpos = InStr(strEmailName,"@")
posdiff = rpos - lpos - 1
strAccountName = Mid(strEmailName,lpos + 1, posdiff)
' For the purposes of this example,
' each account's mailbox directory resides in the
' directory c:\mailboxes. For user Joe, their account
' directory would be c:\mailboxes\joe
strMailboxDir = "c:\mailboxes\" & strAccountName
' Get the message stream
Set iStream = iMsg.GetStream
' write the stream to the user's mailbox directory
' the file name is the same as the one in the drop directory
iStream.SaveToFile strMailboxDir & "\" & strFileName
iStream.Close
Set iStream = Nothing
Next j
Next iMsg
' once we're done, delete the picked up messages
' this deletes the files from the file system as well.
iMsgs.DeleteAll
Set iMsgs = Nothing
Set iDropDir = Nothing
cr
Nybegynder
28. juni 2002 - 22:39
#3
Tak for input!
Jeg læser lige lidt på sagerne og prøver også at teste lidt.
Jeg har selv fundet ud af at der er blevet ændret rimeligt meget i måden hvorpå ipersiststream skal implementeres i vb .net i forhold til vb6. Det betyder at en del af de ting som jeg har forsøgt åbentbart har været vb6 kode og derfor ikke har virket.
Jeg er nået så langt at det system som jeg forsøger at sende til (forresten en navision application server) modtager min message event, men at det data som jeg streamer ikke kommer frem.
Jeg kan godt sende data hvis jeg brus msxml2.load og save funktionerne. Men jeg er ikke interesseret i at sende xml så derfor vil jeg gerne have det andet til at virke også.
Er det nogen som ved hvilken type definition det data har som bliver sendt via af en msxml2.save har? Den virker nemlig :)