Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

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!

  • 4
1 Solution
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.
Could you give us the function prototype (parameters, calling convention etc) for both the VB side and the C++ side?

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
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.

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));

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!!

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.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now