PC Review


Reply
Thread Tools Rate Thread

GetPrivateProfileString en .net

 
 
Guest
Posts: n/a
 
      15th Oct 2003
"
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


 
Reply With Quote
 
 
 
 
Tom Shelton
Guest
Posts: n/a
 
      15th Oct 2003
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]
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      15th Oct 2003
* <(E-Mail Removed)> scripsit:
> 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


See:

<http://www.mentalis.org/soft/class.qpx?id=6>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GetPrivateProfileString =?Utf-8?B?a3ZyZGV2ZWxvcGVyMQ==?= Microsoft Dot NET 3 25th Mar 2005 05:53 PM
GetPrivateProfileString =?Utf-8?B?bW9sb25lZGU=?= Microsoft Access Form Coding 2 29th Nov 2004 03:25 PM
GetPrivateProfileString =?Utf-8?B?TmVpbCBH?= Microsoft Dot NET Framework 2 1st Jun 2004 10:27 PM
GetPrivateProfileString any managed method? Robains Microsoft Dot NET Framework 2 29th Dec 2003 02:11 PM
GetPrivateProfileString Susan Landgraf Microsoft Dot NET 1 27th Nov 2003 04:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:17 AM.