different charset for multiple params with dllimport

后端 未结 2 1838
不思量自难忘°
不思量自难忘° 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:54

    As already pointed out, you should be able to specify MarshalAs for each parameter. Another way would be to specify a default character set type and then specify the marshalling for the odd one out. For example,

      [DllImport("my.dll", CharSet=CharSet.Unicode)]
      void myfunc( [MarshalAs( UnmanagedType.LPStr )] String filename, 
                   StringBuilder buffer, int len );
    

提交回复
热议问题