In C# PInvoke, come faccio a passare un buffer di stringa in modo che la DLL C lo riempia e restituisca? Quale sarà la dichiarazione di PInvoke?C# PInvoke out string declaration
La dichiarazione di funzione C è
int GetData(char* data, int buflength);
In C#, ho dichiarato come
[DllImport(DllName)]
static extern Int32 GetData([MarshalAs(UnmanagedType.LPStr)]StringBuilder receiveddata, Int32 buflen);
E 'corretto? Sto passando la variabile StringBuilder come questo
int bufferLength = 32;
StringBuilder data = new StringBuilder(bufferLength);
int result = GetData(data, bufferLength);
vorrei sapere è corretto o no?
Grazie
E 'corretto se funziona. Non c'è una ragione ovvia che non dovrebbe funzionare. –