We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

Archicad C++ API
About Archicad add-on development using the C++ API.

DGGetItemText()

Anonymous
Not applicable
Hi all,

I use Api DevKit 16 but the fonction DGGetItemText() doesn't have the same number of parameter than API DevKit 15.

-> "DGGetItemText (short dialId, short item, char* text, Int32 size);"

Do you know by what function it is replaced in API DevKit 16 ?

I'm searching for...

Thanks, Have a nice day.
5 REPLIES 5
Ralph Wessel
Mentor
atila-diffusion wrote:
-> "DGGetItemText (short dialId, short item, char* text, Int32 size);"
Do you know by what function it is replaced in API DevKit 16 ?
It hasn't been replaced, just modified. The old method was a bit antiquated, relying on a caller-specified buffer. If the text content exceeded the buffer, the user's input would be truncated. The AC16 version is:
DG_DLL_EXPORT GS::UniString CCALL	DGGetItemText (short dialId, short item);
This function simply returns a dynamic, Unicode string containing the full user input.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Thanks Ralph for your response,

So, I don't understand very well, the parameter "char* text" can be use like this ? :

My old code (api 15) :

char strPath[255];
DGGetItemText(intIdFenetreActuelle,2,strPath,DGGetItemText(intIdFenetreActuelle,2,NULL,0));

My new code (api 16) :

char strPath[255];
(GS::UniString)strPath = DGGetItemText(intIdFenetreActuelle,2);

PS : I have simplified my code
Ralph Wessel
Mentor
atila-diffusion wrote:
My new code (api 16) :
char strPath[255];
(GS::UniString)strPath = DGGetItemText(intIdFenetreActuelle,2);
No, it's much simpler than that:
GS::UniString strPath = DGGetItemText(intIdFenetreActuelle, 2);
If you really need a const char* you can request a C-string representation of the string data by calling the following method:
const char* strPathCStr = strPath.ToCStr();
But ideally you should use a string class and not delve into the raw data if at all possible. You avoid all the risk of buffer overruns etc.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Thank you so much Ralph !
Akos Somorjai
Graphisoft
Graphisoft
Ralph wrote:
If you really need a const char* you can request a C-string representation of the string data by calling the following method:
const char* strPathCStr = strPath.ToCStr();
Be careful with that, though. Don't keep the pointer (strPathCStr above) around, just use it to copy the C string representation elsewhere.
Also, you can pass a code page (in the form of the CC_xxx constants, see CH.hpp) to extract the string in a different codepage (e.g. UTF8).

Best, Akos

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!