different charset for multiple params with dllimport

后端 未结 2 1836
不思量自难忘°
不思量自难忘° 2021-01-21 19:28

Is it possible to declare different charset options for seperate params?

heres what i mean:

[dllimport(\"my.dll\", charset = charset.Ansi)]
void myfunc(s         


        
2条回答
  •  情歌与酒
    2021-01-21 19:33

    You should specify [MarshalAs] for each parameter.

    Try the following:

    [DllImport("my.dll")]
    void myfunc(
         [MarshalAs(UnmanagedType.LPStr)] string CharPtrInCPP, 
         [MarshalAs(UnmanagedType.LPWStr)] StringBuilder WCharPtrInCPP,
         int len
       );
    

提交回复
热议问题