user1242878
user1242878

Reputation: 1

vc++- strings and BSTR

  STDMETHODIMP Cencrypt::encry(BSTR* s, BSTR* a)
   {
    int len,i;
    len=int(strlen((char *)(s)));
    for(i=0;i<len;i++)
   {
    a[i]=s[i]+3;
   }
    a[i]='\0';
    return S_OK;
   }

This is the backend code that im using for simple string encryption... my front end is VB and it has the following code..


   Dim obj As New encrypt
   Dim s As String
   Dim a As String

   Private Sub Command1_Click()
   a = Text1.Text
   Call obj.encrypt(s, a)

   MsgBox (s)

    End Sub

But when i run my vb after referencing the dll, it does not execute... Can i know why this happens?

Upvotes: 0

Views: 461

Answers (2)

Steve Townsend
Steve Townsend

Reputation: 54128

BSTRs are not regular C-strings, so you should stop thinking about them that way asap (for our own sanity).

They are specifically designed for COM usage, and as such have a bunch of special-purpose APIs for inspection and manipulation. For starters check out SysStringLen (to get the length properly) and the wrapper class _bstr_t.

Upvotes: 1

Joseph Willcoxson
Joseph Willcoxson

Reputation: 6040

I would recommend that you show the IDL code where you define the interfaces for your encrypt object.

Another problem you have is assuming that the BSTRs are char*. They are not. They are double byte char arrays.

Upvotes: 0

Related Questions