GetPrivateProfileString

G

Guest

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)
 
J

Jeff Gaines

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;
}
 
T

Tom Dacon

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 said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

GetProfileItem. 7
use GetPrivateProfileString 2
How is it work? 4
ini file 2 2
GetPrivateProfileString 1
GetPrivateProfileString problem! 1
Create a DLL with VB.NET and use with VBScript 2
Reading an INI file 18

Top