OLE and BYREF return parameters
Keywords: BYREF return parameters
Question:
I have written a COM component in VB to send emails. One parameter, an error description, should be returning a value when an error is encountered. In my VB program, that parameter is defined as "ByRef". I believe that my program is working correctly, but the value that I'm passing back in ErrDescr is not showing up in my Winbatch variable. Any ideas?MailObj = ObjectOpen("dllSendMail.dllSendMail") Sender = "crccdi@exchange.nordstrom.com" Recipient = "xjlr@exchange.nordstrom.com" Subject = "any old subject" Body = "any old body text" ErrDescr = " " Attachment1 = "d:\found.not" RC = MailObj.SendMail_Send(Sender,Recipient,Subject,Body,ErrDescr,Attachment1)Answer:
The basic problem is that Winbatch is not 100% happy with BYREF return parameters. Thus the route via a Binary Buffer is required.MailObj = ObjectOpen("dllSendMail.dllSendMail") Sender = "crccdi@exchange.nordstrom.com" Recipient = "xjlr@exchange.nordstrom.com" Subject = "any old subject" Body = "any old body text" bb=BinaryAlloc(2000) BinaryOleType(bb, 200+2,0,0,0) Attachment1 = "d:\found.not" RC = MailObj.SendMail_Send(Sender,Recipient,Subject,Body,bb,Attachment1) ErrDescr=BinaryPeekStr(bb,0,BinaryEodGet(bb)) BinaryFree(bb)