Passing BSTR parameters from VB to a C++ dll

Posted on 2003-03-20
Medium Priority
Last Modified: 2010-04-01
I have a C++ dll that up to now has been working very well with my VB application.  The VB app passed in 2 strings and 2 ints.  I had to change the dll to accept 3 strings and 2 ints.  For some reason, the 3rd string is not coming through properly.  If I step through the code, what I am getting on the C++ end for the 3rd string is totally messed up.  From the VB side if I step into the code, it is passing through a nice string.  The other two strings still function properly.  What is wrong with this third string parameter??  I tried passing constant strings from VB and passing the same string to every parameter and still I have the first two coming through fine and the last one completely messed up!

Question by:emily_hall
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4

Author Comment

ID: 8175874
Sorry - forgot to add, the VB is sending parameters that are defined like Dim x as String and the C++ code is accepting BSTRs.
LVL 12

Expert Comment

ID: 8175910
Could you give us the function prototype (parameters, calling convention etc) for both the VB side and the C++ side?


Author Comment

ID: 8175956
Sure - the c++ side is as follows:

STDMETHODIMP CMyClass::Constructor(BSTR x, BSTR y,
int z, int a, BSTR b)

and the VB calls it with:

Call oMyLib.Constructor(string1, string2, int1, int2, string3)

where string1, string2, string3 are like:
Dim stringX as String
int is: Dim intX as Integer
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 8177028
Another part of the mystery:

I just wrote a test program in C++ that would call the same function and the parameter passed in just fine.  Called the function like:

MyLib->Constructor(A2OLE(string1), A2OLE(string2), int1, int2, A2OLE(string3));


Author Comment

ID: 8177213
Problem solved - I recompiled the C++ library, went to the VB code and dropped that library from the references, re compiled, readded the library, recompiled and tried it again and it worked!!


Accepted Solution

modulo earned 0 total points
ID: 8177722
PAQ'd and points refunded


Community Support Moderator
Experts Exchange

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question