Strings and Interop
-
Can someone please tell me how to create the appropriate buffer to hold characters in a LPCTSTR buffer in C#. I have tried using Strings but the results are chaotic to say the least. For instance, SendMessage, often will use a LPCTSTR in the LPARAM to return a collection of characters. How do I create the appropriate array in C#. Eric
-
Can someone please tell me how to create the appropriate buffer to hold characters in a LPCTSTR buffer in C#. I have tried using Strings but the results are chaotic to say the least. For instance, SendMessage, often will use a LPCTSTR in the LPARAM to return a collection of characters. How do I create the appropriate array in C#. Eric
-
Can someone please tell me how to create the appropriate buffer to hold characters in a LPCTSTR buffer in C#. I have tried using Strings but the results are chaotic to say the least. For instance, SendMessage, often will use a LPCTSTR in the LPARAM to return a collection of characters. How do I create the appropriate array in C#. Eric
Try casting it to a C# string from a lpcstr
-
I'm sorry to be more clear, How do I get a string safely into an IntPtr since I have defined my SendMessage with LPARAM as an IntPtr? Thanks, Eric
Try
System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(Auto/Uni)
. This will do the trick. Andy Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons -
Can someone please tell me how to create the appropriate buffer to hold characters in a LPCTSTR buffer in C#. I have tried using Strings but the results are chaotic to say the least. For instance, SendMessage, often will use a LPCTSTR in the LPARAM to return a collection of characters. How do I create the appropriate array in C#. Eric
Use StringBuilder from the System.Text namespace.
[DllImport("kernel32.dll")]
static extern bool GetVolumeNameForVolumeMountPoint(string lpszVolumeMountPoint, [Out] StringBuilder lpszVolumeName, uint cchBufferLength);public static string GetVolumeName(string MountPoint)
{
StringBuilder sb = new StringBuilder();
GetVolumeNameForVolumeMountPoint(MountPoint, sb, 100);
return sb.ToString();
} -
Use StringBuilder from the System.Text namespace.
[DllImport("kernel32.dll")]
static extern bool GetVolumeNameForVolumeMountPoint(string lpszVolumeMountPoint, [Out] StringBuilder lpszVolumeName, uint cchBufferLength);public static string GetVolumeName(string MountPoint)
{
StringBuilder sb = new StringBuilder();
GetVolumeNameForVolumeMountPoint(MountPoint, sb, 100);
return sb.ToString();
}I tried a StringBuilder but I got empty strings back. I think it has to do with the LPARAM parameter needing to be LPCSTR type pointer and StringBuilder is in appropriate. What I am trying to do is use the SendMessage API to get the textline in an edit control with EM_GETLINE. The LPARAM parameter in this case is an LPCSTR pointer to a buffer of characters and I just don't know how to allocate the memory for this to happen correctly. Thanks, Eric
-
Try
System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(Auto/Uni)
. This will do the trick. Andy Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons