const nach BSTR konvertieren
-
Hallo zusammen,
In meine C++-DLL hab ich über den MIDL-Kompiler eine VisualBasic AxtiveX-DLL als COM-Schnittstelle eingebunden:
-----------------------------------------------------------------------
*EXTERN_C const IID IID__clsWordDonnector;#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("68269085-BE07-4625-B315-C505A6C75468")
_clsWordDonnector : public IDispatch
{
public:
virtual /* [id] */ HRESULT STDMETHODCALLTYPE DialogBrowseFor(
**/* [out][in] / BSTR __RPC_FAR Parameter,
/* [retval][out] */ BSTR __RPC_FAR __MIDL_0014) = 0;
} ...
-----------------------------------------------------------------------
Der Aufruf der Funktion:
FMX_PROC(fmx::errcode) DialogBrowseFor (short funcId, const fmx::ExprEnv& environment, const fmx::DataVect& dataVect, fmx::Data& result)
{
// Declare an HRESULT and a pointer to the clsVBClass interface
HRESULT hr;
_clsWordDonnector IVBClass = NULL;
// Now we will intilize COM
hr = CoInitialize(0);
// Use the SUCCEEDED macro and see if we can get a pointer to the interface
if(SUCCEEDED(hr))
{
hr = CoCreateInstance( CLSID_clsWordDonnector,
NULL,
CLSCTX_INPROC_SERVER,
IID__clsWordDonnector,
(void) &IVBClass);if(SUCCEEDED(hr))
{
long ReturnValue;
_bstr_t bstrValue("Hello World");hr = IVBClass->DialogBrowseFor(bstrValue, &ReturnValue);
hr = IVBClass->Release();
}
else
{ // Something went wrong
cout << "CoCreateInstance Failed." << endl;
}
}
// Uninitialize COM
CoUninitialize();
return 0;
}*Rufe ich nun die Funktion "DialogBrowseFor" auf, meldet der Compiler:
error C2664: '_clsWordDonnector::DialogBrowseFor': Konvertierung des Parameters 1 von '_bstr_t' in 'BSTR * ' nicht möglich!
**
Wie wandle ich den String richtig um, damit er benutzt werden kann??**Fons Gufler
-
probier mal: (BSTR*)&bstrValue
-
net schrieb:
probier mal: (BSTR*)&bstrValue
Danke erstmal, das hilft zumindest, dass der Kompiler das akzeptiert.
ABER die Funktion stürzt praktisch nach dem Aufruf der DLL-Funktion ab, bzw. gibt sie nichts mehr aus:
Die Zeile Log ("CoCreateInstance succeeded."); wird nicht mehr ausgegeben!Noch eine kleine Korrektur des Funktionsaufrufs, denn das hab ich im ersten Posten falsch dargestellt. An die DLL sollen die entsprechenden Funktions-Parameter übergeben werden: - fmx::DataVect& dataVect
Rückgabe der Funktion an: - fmx::Data& result*FMX_PROC(fmx::errcode) DialogBrowseFor (short funcId, const fmx::ExprEnv& environment, const fmx::DataVect& dataVect, fmx::Data& result)
{// Declare an HRESULT and a pointer to the clsVBClass interface
HRESULT hr;
_clsWordDonnector *IVBClass = NULL;// Now we will intilize COM
hr = CoInitialize(0);// Use the SUCCEEDED macro and see if we can get a pointer to the interface
if(SUCCEEDED(hr))
{
hr = CoCreateInstance( CLSID_clsWordDonnector,
NULL,
CLSCTX_INPROC_SERVER,
IID__clsWordDonnector,
(void**) &IVBClass);// If we succeeded then call the CountStringLength method,
// if it failed then display an appropriate message to the user.
if(SUCCEEDED(hr))
{
hr = IVBClass->DialogBrowseFor((BSTR*)&dataVect.AtAsText(0) , (BSTR*)&result);
Log ("CoCreateInstance succeeded.");
hr = IVBClass->Release();
}
else
{ // Something went wrong
cout << "CoCreateInstance Failed." << endl;
}
}
// Uninitialize COM
CoUninitialize();
return 0;*