A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

how to convert 'System::String ^' to 'BSTR'



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 20th 07, 12:43 PM posted to microsoft.public.outlook.program_addins
lencastro
external usenet poster
 
Posts: 8
Default how to convert 'System::String ^' to 'BSTR'

i am creating a addin for outlook express in vc++2005

I am trying to load xml to my code with the following code

STDMETHOD(GetCustomUI)(BSTR RibbonID, BSTR * RibbonXml)
{
Assembly^ assem=Assembly::GetExecutingAssembly();
Stream^ strm=
assem-GetManifestResourceStream("test.Xmlres.test.xml") ;
StreamReader^ reader= gcnew StreamReader(strm);
*RibbonXml= reader-ReadToEnd();
reader-Close();
strm-Close();
return S_OK;

}


but it showing an error in compile time:

error C2440: '=' : cannot convert from 'System::String ^' to 'BSTR'
No user-defined-conversion operator available, or
Cannot convert a managed type to an unmanaged type

Ads
  #2  
Old January 26th 07, 01:03 AM posted to microsoft.public.outlook.program_addins
IceKettle
external usenet poster
 
Posts: 21
Default how to convert 'System::String ^' to 'BSTR'

I'm not very familiar with managed C++. I think you can first convert the
System::String to an wide char,an then convert this wide char to BSTR.
From MSDN you can get the first step as follows:

// convert_string_to_wchar.cpp
// compile with: /clr
#include stdio.h
#include stdlib.h
#include vcclr.h

using namespace System;

int main() {
String ^str = "Hello";

// Pin memory so GC can't move it while native function is called
pin_ptrconst wchar_t wch = PtrToStringChars(str);
printf_s("%S\n", wch);

// Conversion to char* :
// Can just convert wchar_t* to char* using one of the
// conversion functions such as:
// WideCharToMultiByte()
// wcstombs_s()
// ... etc
size_t convertedChars = 0;
size_t sizeInBytes = ((str-Length + 1) * 2);
errno_t err = 0;
char *ch = (char *)malloc(sizeInBytes);

err = wcstombs_s(&convertedChars,
ch, sizeInBytes,
wch, sizeInBytes);
if (err != 0)
printf_s("wcstombs_s failed!\n");

printf_s("%s\n", ch);
}And in second step using ::SysAllocString to conver the wchar to BSTR or
using _bstr_t.



"lencastro"
roups.com...
i am creating a addin for outlook express in vc++2005

I am trying to load xml to my code with the following code

STDMETHOD(GetCustomUI)(BSTR RibbonID, BSTR * RibbonXml)
{
Assembly^ assem=Assembly::GetExecutingAssembly();
Stream^ strm=
assem-GetManifestResourceStream("test.Xmlres.test.xml") ;
StreamReader^ reader= gcnew StreamReader(strm);
*RibbonXml= reader-ReadToEnd();
reader-Close();
strm-Close();
return S_OK;

}


but it showing an error in compile time:

error C2440: '=' : cannot convert from 'System::String ^' to 'BSTR'
No user-defined-conversion operator available, or
Cannot convert a managed type to an unmanaged type



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I Replace a string with a variable? Carol G Outlook and VBA 4 December 2nd 06 04:24 PM
String in msg body gamename Outlook and VBA 5 August 10th 06 10:05 PM
last string in txt file Leech Outlook and VBA 1 February 10th 06 07:13 AM
Need String from Email Subject CondtllyFrmttd Outlook and VBA 1 January 25th 06 04:26 PM
string variable that contains formatting Martin Outlook and VBA 4 January 19th 06 09:49 AM


All times are GMT +1. The time now is 08:53 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.