Returning strings from Windows C functions

穿精又带淫゛_ 提交于 2019-12-06 05:46:25

Do what the Windows API does. It typically does not return pointers, it fills in buffers that you pass in.

Managed code:

[DllImport("YourLibrary", CharSet = CharSet.Auto)] 
static extern Int32  SomeArbitraryFunction (
    String        input,          // string passed to API (LPCSTR) 
    StringBuilder output,         // output filled by API (LPSTR)    
    Int32         outputMaxLen    // StringBuilder.Capacity
); 

On the C/C++ side:

DWORD WINAPI SomeArbitraryFunction (
    LPCSTR input,
    LPSTR output,
    DWORD outputMaxLen
);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!