Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   C++ Performant Strings über ActiveX austauschen (https://www.delphipraxis.net/105165-performant-strings-ueber-activex-austauschen.html)

matmok 17. Dez 2007 13:38


Performant Strings über ActiveX austauschen
 
(Ich nutze Borland CBuilder6 unter XP.)
Ich habe einen ActiveX Server und einen ActiveX Client programmiert und möchte (natürlich möglichst performant) Strings mit dem Client vom Server abrufen.

Die Implementation im ActiveXServer:
STDMETHODIMP ActiveXServ::GetNext(BSTR* TextA, BSTR* TextB, BSTR* TextC ...)
{
*TextA = (WideString)MeinAnsiString;
...
}

Der Aufruf im Client:
MeinActiveXClient::GetTexts()
{
WideString a, b, c;
ActiveXServer->GetNext(&a, &b, &c);
}

Mein Problem: Dadurch dass ich nur Referenzen auf die lokalen Variablen im Client übergebe werden die Strings überschrieben, die Längen stimmen nicht. Eigentlich müsste ich den benötigten Speicher doch im ActiveXServer allocieren...
Wie macht man das richtig?
VARIANT und SAFEARRAYS möchte ich möglichst nicht nutzen weil ich vermute dass das langsamer ist.

Vielen Dank im Voraus,
Matmok

<EDIT>
===> offensichtlich habe ich diese Frage zu voreilig gestellt. Nach ausgibiger Google-Labs codesuche (Suchbegirff <lang:"c++" BSTR* "/*[out]*/">)habe ich folgendes gefunden:
// The wrong way to do it
BSTR * MyBadFunction()
{
// Define a pointer to a BSTR
BSTR * bstrStringPtr;
// Create the CComBSTR object
CComBSTR bstrString("Hello World");
// Convert the string to uppercase
bstrString.ToUpper();
// Assign the pointer
* bstrStringPtr = bstrString;
// Return the pointer. ** Bad thing to do **
return bstrStringPtr;
}
// The correct way to do it
HRESULT MyGoodFunction(/*[out]*/ BSTR* bstrStringPtr)
{
// Create the CComBSTR object
CComBSTR bstrString("Hello World");
// Convert the string to uppercase
bstrString.ToUpper();
// Return a copy of the string.
return bstrString.CopyTo(bstrStringPtr);

bis zum nächsten Mal,
mfg,
Matmok


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:31 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz