Why do C# and VB.NET implicitly marshal char* differently?

前端 未结 3 1646
盖世英雄少女心
盖世英雄少女心 2021-02-20 16:19

So I have a function, written in C++, that looks like this...

extern \"C\" __declspec(dllexport) int __stdcall SomeFunction(char *theData)
{
    // stuff
}
         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-20 17:04

    Now I know that VB.NET and C# are quite different, but I suppose I always assumed that strings were strings

    Strings are immutable in .net. Ask yourself why it is that ByVal passing of an immutable data type can result in the value changing. That doesn't happen for normal functions, just for Declare.

    I'd guess it all has to do with maintaining some backwards compatibility with Declare statements from classic VB6 which were done this way. To my mind the black sheep here is the VB.net code rather than the C# code.

提交回复
热议问题