Board index » cppbuilder » URGENT!!! BCB4 and BSTR

URGENT!!! BCB4 and BSTR

Hello,

I am trying to automate Outlook 97. I have imported the library type in BCB4
(Msoutl8.olb). Then I made a little project, just with one button with the
following code :

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  AnsiString    Name;
  NameSpacePtr  NameSpace;
  MAPIFolderPtr MAPIFolder;
  ItemsPtr      Items;
 WideString    test("MAPI");

 Outlook = CoApplication_::Create();

 NameSpace = Outlook->GetNamespace(test.c_bstr());

  MAPIFolder = NameSpace->GetDefaultFolder(olFolderInbox);
  Items = MAPIFolder->get_Items();

  Name = MAPIFolder->get_Name();

  LNbElt->Caption = Name;

  Outlook->Quit();

Quote
}

What ever I made, I always get a NULL pointer in return of GetNamespace.
I tried StringToOleStr, declaring a BSTR var and using AnsiString::WideChar,
declaring an OLECHAR but nothing to do, I will always get the same result.
If I trace in the interface of GetNamespace, it seems that each time the
NameSpace parameter points anywhere but not on my BSTR var.

Any suggestions ?

Thanks

Jean-Marc BURGSTAHLER

 

Re:URGENT!!! BCB4 and BSTR


Hi, Jean-Marc!

Here's how I do it...

 wchar_t MAPIWideString[5]; MAPIWideString.WideChar((wchar_t *)
"MAPI",5);
 BSTR MAPIBSTR = ::SysAllocString((wchar_t *) &MAPIWideString);

// Do stuff

 ::SysFreeString(MAPIBSTR);

Hope this helps.

------
Mark Cashman (TeamB - C++ Builder), creator of The Temp{*word*203}Doorway at
http://www.temporaldoorway.com
- Original digital art, writing, music and more -
C++ Builder / JBuilder Tips and The C++ Builder Programmer's Webring
(Join us!)
http://www.temporaldoorway.com/programming/index.htm
------

Other Threads