Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to Marshal a string property so that I can pass it to my dll.

This is what I've got so far but it doesn't work, error is can't read or write protected memory when I attempt to pass it.

Doesn't allow me to pass with UnmanagedType.ByValTstr.

Note: I've managed to pass my string successfully as a field but not property.
C#
public string firstName { 
           
     [return : MarshalAsAttribute(UnmanagedType.BSTR, SizeConst=51)]get {
            return _firstName;
      }
     [param : MarshalAsAttribute(UnmanagedType.BSTR, SizeConst=51)]set {
            _firstName = value;
      }
}
Posted
Updated 20-May-14 9:31am
v2
Comments
V. 21-May-14 3:39am    
try passing a StringBuilder instead of a String.
Jack Jarvis 21-May-14 4:27am    
I need to use data binding on this variable so it wouldn't be possible with string builder?
Jack Jarvis 22-May-14 13:32pm    
Could you possibly give an example?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900