<div dir="ltr"><div><div>Hi all,<br></div>I'm making a DLL wrapper around vboxmanage using Visual Studio 2010. For some reason VS gives me error C2664/C2440 when it is trying to convert from BSTR to PCRTUTF16. <br>1>C:\vboxbuild\virtualbox\latest\src\include\VBox/com/Guid.h(112): error C2664: 'RTUuidFromUtf16' : cannot convert parameter 2 from 'BSTR' to 'PCRTUTF16'
<br>1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
<br>1>C:\vboxbuild\virtualbox\latest\src\include\VBox/com/Guid.h(198): error C2440: '<function-style-cast>' : cannot convert from 'RTUTF16 [37]' to 'com::Bstr'
<br>1> No constructor could take the source type, or constructor overload resolution was ambiguous<br><br>I worked around that by using the casings below. But I was wondering why compiling vboxmanage doesn't produce the same errors. I tried to make my compile options match the vbox build options as much as possible but I'm sure I missed something. Below is are my options used to compile part of the project:<br>
<br>/Zi /nologo /W3 /WX-<br>/O2 /Oy-<br>/Gm- /EHsc /MD /GS<br>/fp:precise<br>/Zc:wchar_t<br>/Zc:forScope-<br>/GR<br></div><div>-wd4065 -wd4996 -wd4250<br></div><div>/Fp"Release\VboxCom.pch" /Fa"Release\" /Fo"Release\" /Fd"Release\vcWindows7.1SDK.pdb" /Gd /analyze- /errorReport:queue <br>
/D "__WIN__" /D "RT_OS_WINDOWS" /D "_WIN32_WINNT=0x0501" /D "WIN32" /D
"__WIN32__" /D "RT_ARCH_X86" /D "__X86__" /D "_X86_" /D "_LIB" /D "VBOX"
/D "VBOX_OSE" /D "VBOX_WITH_64_BITS_GUESTS" /D "IN_RING3" /D "UNICODE"
/D "NDEBUG=1" /D "_REENTRANT" /D "_UNICODE"<br><br></div>Any help would be greatly appreciated. Below are the castings that I had to make (V4.2.12):<br><div><div><div><br>--------------------------- include/VBox/com/Guid.h ---------------------------
<br>index c55d69d..01884d2 100644
<br>@@ -109,7 +109,7 @@ public:
<br> Guid(const Bstr &that)
<br> {
<br> int rc = !that.isEmpty()
<br>- ? ::RTUuidFromUtf16(&mUuid, that.raw())
<br>+ ? ::RTUuidFromUtf16(&mUuid, (PCRTUTF16)that.raw())
<br> : VERR_INVALID_UUID_FORMAT;
<br> if (RT_FAILURE(rc))
<br> ::RTUuidClear(&mUuid);
<br>@@ -195,7 +195,7 @@ public:
<br> <br> RTUTF16 buf[RTUUID_STR_LENGTH];
<br> ::RTUuidToUtf16(&mUuid, buf, RTUUID_STR_LENGTH);
<br>- return Bstr(buf);
<br>+ return Bstr((CBSTR)buf);
<br> }
<br> <br> bool isEmpty() const
<br> <br>------------- src/VBox/Frontends/VBoxManage/VBoxManageDebugVM.cpp -------------
<br>index 5901c53..72addfe 100644
<br>@@ -87,7 +87,7 @@ static RTEXITCODE handleDebugVM_GetRegisters(HandlerArg *pArgs, IMachineDebugger
<br> size_t cchMaxName = 8;
<br> for (size_t i = 0; i < aBstrNames.size(); i++)
<br> {
<br>- size_t cchName = RTUtf16Len(aBstrNames[i]);
<br>+ size_t cchName = RTUtf16Len((PCRTUTF16)aBstrNames[i]);
<br> if (cchName > cchMaxName)
<br> cchMaxName = cchName;
<br> }
<br> <br>------------------------ src/VBox/Main/glue/string.cpp ------------------------
<br>index 9865af5..51af313 100644
<br>@@ -179,7 +179,7 @@ void Utf8Str::copyFrom(CBSTR a_pbstr)
<br> && vrc != VERR_NO_MEMORY)
<br> {
<br> /* ASSUME: input is valid Utf-16. Fake out of memory error. */
<br>- AssertLogRelMsgFailed(("%Rrc %.*Rhxs\n", vrc, RTUtf16Len(a_pbstr) * sizeof(RTUTF16), a_pbstr));
<br>+ AssertLogRelMsgFailed(("%Rrc %.*Rhxs\n", vrc, RTUtf16Len((PCRTUTF16)a_pbstr) * sizeof(RTUTF16), a_pbstr));
<br> }
<br> <br> m_cch = 0;
<br>@@ -221,7 +221,7 @@ HRESULT Utf8Str::copyFromEx(CBSTR a_pbstr)
<br> && vrc != VERR_NO_MEMORY)
<br> {
<br> /* ASSUME: input is valid Utf-16. Fake out of memory error. */
<br>- AssertLogRelMsgFailed(("%Rrc %.*Rhxs\n", vrc, RTUtf16Len(a_pbstr) * sizeof(RTUTF16), a_pbstr));
<br>+ AssertLogRelMsgFailed(("%Rrc %.*Rhxs\n", vrc, RTUtf16Len((PCRTUTF16)a_pbstr) * sizeof(RTUTF16), a_pbstr));
<br> }
<br> <br> m_cch = 0;<br clear="all"><br>-- <br>-- Ribhi
</div></div></div></div>