September 14, 2011

kitten kitten
Lab Rat
159 posts

QString and BSTR

Page  
1

hi to everyone
i have a c# dll that i use it via dumpcpp and active qt
it works correctly except when i call a function that uses BSTR that dumpcpp converted to QString
how can i solve this problem?
how can i convert qString to bstr?

 Signature 

www.kitten.mihanblog.com

25 replies

September 14, 2011

cincirin cincirin
Ant Farmer
387 posts

something like this …

  1. BSTR test = SysAllocString(QString::utf16());
  2. // to do what you need with "test"
  3. SysFreeString(test)

September 14, 2011

kitten kitten
Lab Rat
159 posts

i want to set a Qstring variable to my Bstr and
i want to set a Bstr variable to my QString
can you give me example?

 Signature 

www.kitten.mihanblog.com

September 14, 2011

cincirin cincirin
Ant Farmer
387 posts

kitten wrote:
i want to set a Qstring variable to my Bstr

previous example not work ? … or some minimal compilable example would be …
  1. QString string("whatever string");
  2. BSTR bstr = SysAllocString(string.utf16());
  3. // to do what you need with "bstr"
  4. SysFreeString(bstr);

kitten wrote:
i want to set a Bstr variable to my QString

QString string = QString::fromUtf16(yourBSTR);

September 14, 2011

kitten kitten
Lab Rat
159 posts

thanks alot for your answer
but i use this code and it get me error

  1.     bool qax_result;
  2.  QString st("mil");
  3.  BSTR test = SysAllocString(st.utf16());
  4.     void *_a[] = {(void*)&qax_result, (void*)&Row, (void*)&Col, (void*)&test};
  5.     qt_metacall(QMetaObject::InvokeMetaMethod, 244, _a);
  6.  SysFreeString(test);
  7.     return qax_result;

it is compiled successfully but when i run it, it get me error

 Signature 

www.kitten.mihanblog.com

September 14, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

Hi kitten,

where do you get which error?
Did you try to debug it?

The conversion from QString to BSTR looks generally correct.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

September 14, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

By the way, do you need a BSTR*?
in the parameters, you write:

  1.     (void*)&test...

a BSTR is already a pointer….

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

September 14, 2011

kitten kitten
Lab Rat
159 posts

i use this but it get me error again

  1. void *_a[] = {(void*)&qax_result, (void*)&Row, (void*)&Col, (void*)test};

it get me error on this file
qatomic_windows.h
on function
  1. inline bool QBasicAtomicInt::ref()

 Signature 

www.kitten.mihanblog.com

September 14, 2011

cincirin cincirin
Ant Farmer
387 posts

I did a little test, and it works perfectly:

  1.     QString string("test");
  2.     BSTR bstr = SysAllocString(reinterpret_cast<const OLECHAR*>(string.utf16()));
  3.     char testing[] = {bstr[0], bstr[1], bstr[2], bstr[3], '\0'};
  4.     qDebug(testing);
  5.     SysFreeString(bstr);

debug window show “test”

September 14, 2011

cincirin cincirin
Ant Farmer
387 posts

Just out of curiosity, if you delete last parameter(test) from _a array, the problem still exists ?

September 14, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

kitten wrote:
i use this but it get me error again
  1. void *_a[] = {(void*)&qax_result, (void*)&Row, (void*)&Col, (void*)test};

it get me error on this file
qatomic_windows.h
on function

  1. inline bool QBasicAtomicInt::ref()

Which error message do you get???

this is just a parameter assignement, nothing else

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

September 14, 2011

kitten kitten
Lab Rat
159 posts

it work correctly
do you what i want to do?
i have a .net dll now i want to write a program for it
i use dumpcpp to use it , it works correctly and this functions work correctly too
but when i send a text of other languages like persian to this dll it show me ???? in replace of my text

 Signature 

www.kitten.mihanblog.com

September 14, 2011

kitten kitten
Lab Rat
159 posts

error

Gerolf wrote:
kitten wrote:
i use this but it get me error again
  1. void *_a[] = {(void*)&qax_result, (void*)&Row, (void*)&Col, (void*)test};

it get me error on this file
qatomic_windows.h
on function
@inline bool QBasicAtomicInt::ref()@

Which error message do you get???

this is just a parameter assignement, nothing else

 Signature 

www.kitten.mihanblog.com

September 14, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

which is the call stack?

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

September 14, 2011

kitten kitten
Lab Rat
159 posts

what do you mean by call stack?

 Signature 

www.kitten.mihanblog.com

September 14, 2011

cincirin cincirin
Ant Farmer
387 posts

In Visual Studio is: Debug -> Windows -> Call Stack

Page  
1

  ‹‹ Creating a keypress signal from application button      Setting window size including window frame ››

You must log in to post a reply. Not a member yet? Register here!