c++ - How to get string from IFileDialogCustomize GetEditBoxText() in C# -


i trying use ifiledialogcustomize interface in c# using com calls. have call geteditboxtext(id, buffer) defined as:

    [methodimpl(methodimploptions.internalcall, methodcodetype = methodcodetype.runtime)]     hresult geteditboxtext([in] int dwidctl, [out] intptr ppsztext); 

which got https://msdn.microsoft.com/en-us/library/windows/desktop/bb775908(v=vs.85).aspx

the code have written is:

        intptr buffer = marshal.alloccotaskmem(sizeof(int));         string textboxstring;         var customizedialog = getfiledialog() ifiledialogcustomize;         if (customizedialog != null)         {          hresult result = customizedialog.geteditboxtext(id, buffer);             if (result != hresult.s_ok)             {                 throw new exception("couldn't parse string textbox");             }         }         textboxstring = marshal.ptrtostringuni(buffer);         marshal.freecotaskmem(buffer);         return textboxstring; 

the string returns odd characters such 벰∔.

i'm new using com interfaces , haven't ever done c++ programming, i'm bit lost here. why not getting actual string textbox here?

i figured out. combination of jacob said , changing signature of com call. instead of

    [methodimpl(methodimploptions.internalcall, methodcodetype = methodcodetype.runtime)]     void geteditboxtext([in] int dwidctl, [out] intptr ppsztext); 

i needed make signature:

    [methodimpl(methodimploptions.internalcall, methodcodetype = methodcodetype.runtime)]     hresult geteditboxtext([in] int dwidctl, out intptr ppsztext); 

which passed intptr out correctly , able string using

    marshal.ptrtostringuni(buffer); 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -