October 28th, 2010, 10:30 AM
Getting ByRef BSTR out of C++ into VB6
First up I'd like to thank Paul McKenzie & Igor Vartanov for helping me out on my first steps into C++, __stdcall was indeed the answer.
So on to the next hurdle, I have a VB6 app that calls a function in a VC++ (not .NET), this function returns an int 0 or 1 for success/fail and a string parameter is passed ByRef (example below). When this function is called from VB6 it returns success value of 1 but the ByRef only gives me the first character of the string I'm expecting.
__declspec(dllexport) int __stdcall PassChars(BSTR* str)
char* pCharval = "this string";
*str = ret.Copy();
Private Declare Function PassChars Lib "D:\Projects\VB6 Projects\Pointers\References\Pointers.dll" (ByRef value1 As String) As Long
Dim ret As Long
Dim val As String
ret = PassChars(val)
Message Box Displays: t
I have read as much as I can including Siddhartha's posts on converting strings but no-one has provided an example of ByRef that I have managed to see working.
Much respect to all C++ coders willing to help us noobs,
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.