|
-
October 28th, 2010, 10:30 AM
#1
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.
C++
__declspec(dllexport) int __stdcall PassChars(BSTR* str)
{
char* pCharval = "this string";
CComBSTR ret(pCharval);
*str = ret.Copy();
::SysFreeString(ret);
return 1;
}
VB6
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)
MsgBox (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,
Thanks
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|