PC Review


Reply
Thread Tools Rate Thread

GetPrivateProfileString

 
 
=?Utf-8?B?TmVpbCBH?=
Guest
Posts: n/a
 
      1st Jun 2004
Has any got GetPrivateProfileString to work in vb.net? I am upgrading from VB6.

Code snippet:

Public Declare Function GetPrivateProfileString Lib "kernel32" Alias _
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _
lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString _
As String, ByVal nSize As Long, ByVal lpFileName As String) As Long



Dim sBuf As String, lreturn As Long
Dim strTemp As String
Dim strTemp2 As String
Dim lSize As Long


strTemp = New String(CChar(" "), BufferLen)
lSize = Len(strTemp)

Try
lreturn = GetPrivateProfileString(SectionName, KeyName, strDef, strTemp, lSize, IniFile)
 
Reply With Quote
 
 
 
 
Jeff Gaines
Guest
Posts: n/a
 
      1st Jun 2004
On Tue, 1 Jun 2004 12:31:02 -0700, Neil G
<(E-Mail Removed)> wrote:

>Has any got GetPrivateProfileString to work in vb.net? I am upgrading from VB6.
>
>Code snippet:
>
>Public Declare Function GetPrivateProfileString Lib "kernel32" Alias _
>"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _
>lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString _
>As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
>
>
>
>Dim sBuf As String, lreturn As Long
> Dim strTemp As String
> Dim strTemp2 As String
> Dim lSize As Long
>
>
> strTemp = New String(CChar(" "), BufferLen)
> lSize = Len(strTemp)
>
> Try
> lreturn = GetPrivateProfileString(SectionName, KeyName, strDef, strTemp, lSize, IniFile)


Can you convert from C#?

Prototype:

// GetPrivateProfileString
[DllImport("kernel32.DLL",
EntryPoint="GetPrivateProfileString",
SetLastError=true,CharSet=CharSet.Auto)]
public static extern int GetPrivateProfileString(string
lpSectionName, string lpKeyName, string lpDefault, IntPtr
lpReturnedString, int nSize, string lpFileName);

Usage:
private string JINIGetKeyValue(string strSection, string
strKeyName, string strFileName)
{
int intReturn = 0;
int BufferSize = 2048;

IntPtr ipReturn = Marshal.AllocHGlobal(BufferSize);

intReturn = GetPrivateProfileString(strSection, strKeyName,
"", ipReturn, BufferSize, strFileName);
if(intReturn == 0)
return "";

string strReturn = Marshal.PtrToStringAuto(ipReturn,
intReturn);
Marshal.FreeHGlobal(ipReturn);

return strReturn;
}

--
Jeff Gaines - Damerham Hampshire UK

 
Reply With Quote
 
 
 
 
Tom Dacon
Guest
Posts: n/a
 
      1st Jun 2004
Go to www.mentalis.org, and look for a project named IniReader in the
'useful classes' section. He has a complete set of managed wrappers around
the ini file access API. It's downloadable and free, if I recall correctly.

HTH,
Tom Dacon
Dacon Software Consulting


"Neil G" <(E-Mail Removed)> wrote in message
news:C689C8D8-AB54-43A5-A047-(E-Mail Removed)...
> Has any got GetPrivateProfileString to work in vb.net? I am upgrading from

VB6.
>
> Code snippet:
>
> Public Declare Function GetPrivateProfileString Lib "kernel32" Alias _
> "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _
> lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString _
> As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
>
>
>
> Dim sBuf As String, lreturn As Long
> Dim strTemp As String
> Dim strTemp2 As String
> Dim lSize As Long
>
>
> strTemp = New String(CChar(" "), BufferLen)
> lSize = Len(strTemp)
>
> Try
> lreturn = GetPrivateProfileString(SectionName, KeyName,

strDef, strTemp, lSize, IniFile)


 
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
Equivalent of GetPrivateProfileString equivalent in C#? Germic Microsoft C# .NET 1 24th Jan 2005 10:22 AM
GetPrivateProfileString =?Utf-8?B?bW9sb25lZGU=?= Microsoft Access Form Coding 2 29th Nov 2004 03:25 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 04:48 PM.