On 2003-10-15, <(E-Mail Removed)> <(E-Mail Removed)> wrote:
> "
> You can fix this by declaring sBuf as a normal string and initializing it to
> a fixed length with the Space function:
> Dim sBuf As String = Space(128)The new VB.NET declaration syntax lets you
> declare and initialize the variable on the same line. You use the sBuf
> string's Length method to return its length. The function call to return an
> INI string now looks like this:
>
> lRet = GetPrivateProfileString (Section, KeyName, _
> DefaultValue, sBuf, sBuf.Length, msININame)"Segun Microsoft esta es la
> forma de implementar esta API en .net, pero no funciona,¿Alguien sabe por
> qué?Saludosjmpedrero
>
>
I'm assuming that this is an answer to a question that I don't see?
But, I would like to make a comment... You should never use the String
data type to return values from API calls. Strings in .NET are
immutable - this means that they can not be changed. Because of this
fact, it causes a great deal of overhead - in both memory and speed to
pass a string to an API routine that is expected to be modified by the
called function... And it in fact will not work in C#.
So, my advice

Pass it as a System.Text.StringBuilder. That would
mean that the declaration of GetPrivateProfileString would look
something like:
Declare Auto Function GetPrivateProfileString Lib "kernel32" ( _
ByVal lpAppName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As System.Text.StringBuilder, _
ByVal nSize As Integer, _
ByVal lpFileName As String) As Integer
Then you would use it like:
Dim buffer As New System.Text.StringBuilder(256)
Dim retVal As Integer =
GetPrivateProfileString(
"Section", "KeyName", "", buffer, buffer.Capacity, "my.ini")
Dim value As String = buffer.ToString()
HTH
--
Tom Shelton
MVP [Visual Basic]