Quote Originally Posted by cristinuccia View Post
Code:
string mystr = "hello world!";
bstrArr[i] = SysAllocString(mystr.c_strt());
Unfortunately, the above code does not work and I do not understand why. casting to (const unsigned short *) it compiles but it does not assign the correct string. Could you help me to solve this last issue?
The above doesn't work, because you need to perform an ANSI-to-BSTR-conversion at the C++ end of things,
which you could avoid when you'd use:
std::wstring mystr = L"hello world!";
instead of your:
std::string mystr = "hello world!";
from above...

Meaning that you work unicode- (or at least WString) aware throughout (also at the C/C++ side).

If you want to keep up "doing ANSI" at the C++ Dlls end, then you need to introduce
ANSI2BSTR-conversion-routines ...
(in case of C++ you could use _bstr_t for shorter notation -
...maybe interesting to look at this article here: http://msdn.microsoft.com/en-us/libr...8VS.80%29.aspx
...or just google for [ANSI to BSTR C++]

The small helper-function below is C-compatible, not using any of the C++ stuff shown in the above link,
but should work when you use it this way: bstrArr[i] = Ansi2Bstr(mystr.c_strt());

Code:
BSTR Ansi2Bstr(LPCSTR lpSrc){
    if (!lpSrc) return 0;
	
    int  LenSrc = strlen(lpSrc);
    BSTR lpDst = SysAllocStringLen(NULL, LenSrc);
 
    if (!lpDst) return 0;
	
    MultiByteToWideChar(CP_ACP, 0, lpSrc, LenSrc, lpDst, LenSrc);
    return lpDst;
}
Just out of interest - is the C/C++ Dll only a small helper to speed some things up on the VB-side?
(in this case there'd be a lot of things one can do with regards to fast string-processing directly in VB6,
which will perhaps beat what you currently have in VC++)

Or is the VB-Dll-interface only a small window into a "long existing, very broad and very complex C++ lib, which is used also in other contexts by other languages"?

What does your C++ Dll do currently (if you are allowed to tell us that much).

Olaf