Passing BSTR parameters from VB to a C++ dll

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!

LVL 1
emily_hallAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

emily_hallAuthor Commented:
Sorry - forgot to add, the VB is sending parameters that are defined like Dim x as String and the C++ code is accepting BSTRs.
0
SalteCommented:
Could you give us the function prototype (parameters, calling convention etc) for both the VB side and the C++ side?

Alf
0
emily_hallAuthor Commented:
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
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

emily_hallAuthor Commented:
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));

0
emily_hallAuthor Commented:
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!!

0
moduloCommented:
PAQ'd and points refunded

modulo

Community Support Moderator
Experts Exchange
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.