Randy:
I too am having the problem that this other guy/girl had. I put in
the proper API declarations and arguments for GetPrivateProfi leString
yet it doesn't return the correct stuff. It always returns the
default value (padded with huge amount of spaces on the right) and the
return value (number of characters read) is some crazy huge number
like 51298398749084
Your demo doesn't work in .Net - it's for prior versions of VB, and so
the problem still remains. Have you had any luck with
GetPrivateProfi leString in VB.Net?
Mark Hayworth
From: Randy Birch (rg*@mvps.org)
Subject: Re: Why won't GetPrivateProfi leString work?
View this article only
Newsgroups: comp.lang.visua l.basic
Date: 2003-02-03 19:24:40 PST
Examine the basic private profile demo at http://www.mvps.org/vbnet/code/file/pprofilebasic.htm
--
Randy Birch
MVP Visual Basic http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
"nospam" <no@spam.com> wrote in message
news:pa******** *************** *****@spam.com. ..
# I can't for the life of me to get the GetPrivateProfi leString API
function
# to work correctly in VB.NET, although I've gotten
# WritePrivatePro fileString to work. Listed below after this message
# are the function declarations I'm using.
#
# These two functions write to the test.ini as they should:
# WritePrivatePro fileString("Sec tion1", "FirstKey", "First Value",
"test.ini")
# WritePrivatePro fileString("Sec tion2", "SecondKey" , "Second Value",
"test.ini")
#
#
# But when I try and read the values back, all that is copied to the
buffer
# is the "Default" value:
#
# GetPrivateProfi leString("Secti on1", "FirstKey", "Default", Buffer,
255,
# "test.ini")
#
# MsgBox(Buffer, MsgBoxStyle.OKO nly, "Ini Test")
#
#
# I also tried hard coding the path to the test.ini file, but that
didn't
# work either. Any ideas why GetPrivateProfi leString isn't working?
#
# -Thanks
#
#
# Function Declarations:
#
# Private Declare Function GetPrivateProfi leString Lib "kernel32"
Alias _
# "GetPrivateProf ileStringA" (ByVal lpApplicationNa me As String,
ByVal _
# lpKeyName As String, ByVal lpDefault As String, ByVal
lpReturnedStrin g _
# As String, ByVal nSize As Long, ByVal lpFileName As String) As
Long
#
#
# Private Declare Function WritePrivatePro fileString Lib "kernel32"
Alias _
# "WritePrivatePr ofileStringA" (ByVal lpSectionName As String, ByVal
_
# lpKeyName As String, ByVal lpString As String, ByVal lpFileName As
String) As Long
# 4 19244
Nope ... my .net disks are used as coasters, so I can feel there is at least
some redeeming value to the product.
: Date: 2003-02-03 19:24:40 PST
golly ... that's why I hate google! <g>
--
Randy Birch
MVP Visual Basic http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Mark Hayworth" <ha******@hotma il.com> wrote in message
news:26******** *************** **@posting.goog le.com...
: Randy:
: I too am having the problem that this other guy/girl had. I put in
: the proper API declarations and arguments for GetPrivateProfi leString
: yet it doesn't return the correct stuff. It always returns the
: default value (padded with huge amount of spaces on the right) and the
: return value (number of characters read) is some crazy huge number
: like 51298398749084
: Your demo doesn't work in .Net - it's for prior versions of VB, and so
: the problem still remains. Have you had any luck with
: GetPrivateProfi leString in VB.Net?
: Mark Hayworth
:
:
:
:
: From: Randy Birch (rg*@mvps.org)
: Subject: Re: Why won't GetPrivateProfi leString work?
:
:
: View this article only
: Newsgroups: comp.lang.visua l.basic
: Date: 2003-02-03 19:24:40 PST
:
:
: Examine the basic private profile demo at
: http://www.mvps.org/vbnet/code/file/pprofilebasic.htm
:
: --
:
: Randy Birch
: MVP Visual Basic
: http://www.mvps.org/vbnet/
: Please respond only to the newsgroups so all can benefit.
:
:
: "nospam" <no@spam.com> wrote in message
: news:pa******** *************** *****@spam.com. ..
: # I can't for the life of me to get the GetPrivateProfi leString API
: function
: # to work correctly in VB.NET, although I've gotten
: # WritePrivatePro fileString to work. Listed below after this message
: # are the function declarations I'm using.
: #
: # These two functions write to the test.ini as they should:
: # WritePrivatePro fileString("Sec tion1", "FirstKey", "First Value",
: "test.ini")
: # WritePrivatePro fileString("Sec tion2", "SecondKey" , "Second Value",
: "test.ini")
: #
: #
: # But when I try and read the values back, all that is copied to the
: buffer
: # is the "Default" value:
: #
: # GetPrivateProfi leString("Secti on1", "FirstKey", "Default", Buffer,
: 255,
: # "test.ini")
: #
: # MsgBox(Buffer, MsgBoxStyle.OKO nly, "Ini Test")
: #
: #
: # I also tried hard coding the path to the test.ini file, but that
: didn't
: # work either. Any ideas why GetPrivateProfi leString isn't working?
: #
: # -Thanks
: #
: #
: # Function Declarations:
: #
: # Private Declare Function GetPrivateProfi leString Lib "kernel32"
: Alias _
: # "GetPrivateProf ileStringA" (ByVal lpApplicationNa me As String,
: ByVal _
: # lpKeyName As String, ByVal lpDefault As String, ByVal
: lpReturnedStrin g _
: # As String, ByVal nSize As Long, ByVal lpFileName As String) As
: Long
: #
: #
: # Private Declare Function WritePrivatePro fileString Lib "kernel32"
: Alias _
: # "WritePrivatePr ofileStringA" (ByVal lpSectionName As String, ByVal
: _
: # lpKeyName As String, ByVal lpString As String, ByVal lpFileName As
: String) As Long
: #
Sorry ... I meant to include links to net groups where you might find a
compassionate ear .. news://msnews.microsoft.com/microsof...dotnet.general news://msnews.microsoft.com/microsof...t.languages.vb news://msnews.microsoft.com/microsof....vsnet.general
--
Randy Birch
MVP Visual Basic http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Randy Birch" <rg************ @mvps.org> wrote in message
news:Sn******** ***********@twi ster01.bloor.is .net.cable.roge rs.com...
: Nope ... my .net disks are used as coasters, so I can feel there is at
least
: some redeeming value to the product.
:
:: Date: 2003-02-03 19:24:40 PST
:
: golly ... that's why I hate google! <g>
:
: --
:
: Randy Birch
: MVP Visual Basic
: http://vbnet.mvps.org/
: Please respond only to the newsgroups so all can benefit.
:
:
: "Mark Hayworth" <ha******@hotma il.com> wrote in message
: news:26******** *************** **@posting.goog le.com...
:: Randy:
:: I too am having the problem that this other guy/girl had. I put in
:: the proper API declarations and arguments for GetPrivateProfi leString
:: yet it doesn't return the correct stuff. It always returns the
:: default value (padded with huge amount of spaces on the right) and the
:: return value (number of characters read) is some crazy huge number
:: like 51298398749084
:: Your demo doesn't work in .Net - it's for prior versions of VB, and so
:: the problem still remains. Have you had any luck with
:: GetPrivateProfi leString in VB.Net?
:: Mark Hayworth
::
::
::
::
:: From: Randy Birch (rg*@mvps.org)
:: Subject: Re: Why won't GetPrivateProfi leString work?
::
::
:: View this article only
:: Newsgroups: comp.lang.visua l.basic
:: Date: 2003-02-03 19:24:40 PST
::
::
:: Examine the basic private profile demo at
:: http://www.mvps.org/vbnet/code/file/pprofilebasic.htm
::
:: --
::
:: Randy Birch
:: MVP Visual Basic
:: http://www.mvps.org/vbnet/
:: Please respond only to the newsgroups so all can benefit.
::
::
:: "nospam" <no@spam.com> wrote in message
:: news:pa******** *************** *****@spam.com. ..
:: # I can't for the life of me to get the GetPrivateProfi leString API
:: function
:: # to work correctly in VB.NET, although I've gotten
:: # WritePrivatePro fileString to work. Listed below after this message
:: # are the function declarations I'm using.
:: #
:: # These two functions write to the test.ini as they should:
:: # WritePrivatePro fileString("Sec tion1", "FirstKey", "First Value",
:: "test.ini")
:: # WritePrivatePro fileString("Sec tion2", "SecondKey" , "Second Value",
:: "test.ini")
:: #
:: #
:: # But when I try and read the values back, all that is copied to the
:: buffer
:: # is the "Default" value:
:: #
:: # GetPrivateProfi leString("Secti on1", "FirstKey", "Default", Buffer,
:: 255,
:: # "test.ini")
:: #
:: # MsgBox(Buffer, MsgBoxStyle.OKO nly, "Ini Test")
:: #
:: #
:: # I also tried hard coding the path to the test.ini file, but that
:: didn't
:: # work either. Any ideas why GetPrivateProfi leString isn't working?
:: #
:: # -Thanks
:: #
:: #
:: # Function Declarations:
:: #
:: # Private Declare Function GetPrivateProfi leString Lib "kernel32"
:: Alias _
:: # "GetPrivateProf ileStringA" (ByVal lpApplicationNa me As String,
:: ByVal _
:: # lpKeyName As String, ByVal lpDefault As String, ByVal
:: lpReturnedStrin g _
:: # As String, ByVal nSize As Long, ByVal lpFileName As String) As
:: Long
:: #
:: #
:: # Private Declare Function WritePrivatePro fileString Lib "kernel32"
:: Alias _
:: # "WritePrivatePr ofileStringA" (ByVal lpSectionName As String, ByVal
:: _
:: # lpKeyName As String, ByVal lpString As String, ByVal lpFileName As
:: String) As Long
:: #
:
Randy:
Thanks for pointing me to the other newsgroups - I found the answer
there pretty quickly. Apparently it has to do with vb6 longs are now
..Net integers because a long in .net is 64 bits not 32 bits as before
in vb6. Corrected code from Tom Shelton follows.
---------------------------------------------------------------------
Private Declare Auto Function WritePrivatePro fileString Lib "kernel32"
_
(ByVal lpApplication As String, _
ByVal lpKeyName As String, _
ByVal lpString As String, _
ByVal lpFileName As String) As Integer
Private Declare Auto Function GetPrivateProfi leString Lib "kernel32" _
(ByVal lpApplicationNa me As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedStrin g As System.Text.Str ingBuilder, _
ByVal nSize As Integer, _
ByVal lpFileName As String) As Integer
Private Sub DoIt()
Dim strData As New System.Text.Str ingBuilder(255)
WritePrivatePro fileString(Appl ication.Product Name, "Datum1", _
"NewInfo", "MyInfo.ini ")
GetPrivateProfi leString (Application.Pr oductName, "Datum1", _
"DefaultInf o", strData, strData.Capacit y, "MyInfo.ini ")
MsgBox (strData.ToStri ng())
End Sub
---------------------------------------------------------------------
Note that Application.Pro ductName is really the section name in your
ini file and "Datum1" is the key name. The value comes out in strData
automatically - you don't need to assign anything to the return value
of GetPrivateProfi leString
Thanks,
Mark Hayworth
"Randy Birch" <rg************ @mvps.org> wrote in message news:<9p******* ************@tw ister01.bloor.i s.net.cable.rog ers.com>... Sorry ... I meant to include links to net groups where you might find a compassionate ear ..
news://msnews.microsoft.com/microsof...dotnet.general news://msnews.microsoft.com/microsof...t.languages.vb news://msnews.microsoft.com/microsof....vsnet.general
--
Randy Birch MVP Visual Basic http://vbnet.mvps.org/ Please respond only to the newsgroups so all can benefit.
"Randy Birch" <rg************ @mvps.org> wrote in message news:Sn******** ***********@twi ster01.bloor.is .net.cable.roge rs.com... : Nope ... my .net disks are used as coasters, so I can feel there is at least : some redeeming value to the product. : :: Date: 2003-02-03 19:24:40 PST : : golly ... that's why I hate google! <g> : : -- : : Randy Birch : MVP Visual Basic : http://vbnet.mvps.org/ : Please respond only to the newsgroups so all can benefit. : : : "Mark Hayworth" <ha******@hotma il.com> wrote in message : news:26******** *************** **@posting.goog le.com... :: Randy: :: I too am having the problem that this other guy/girl had. I put in :: the proper API declarations and arguments for GetPrivateProfi leString :: yet it doesn't return the correct stuff. It always returns the :: default value (padded with huge amount of spaces on the right) and the :: return value (number of characters read) is some crazy huge number :: like 51298398749084 :: Your demo doesn't work in .Net - it's for prior versions of VB, and so :: the problem still remains. Have you had any luck with :: GetPrivateProfi leString in VB.Net? :: Mark Hayworth :: ::
II found this using google:
I put the following at the top of the module, above the forms stuff:
=============== =============== ============
Public Class IniFile
' API functions
Private Declare Ansi Function GetPrivateProfi leString _
Lib "kernel32.d ll" Alias "GetPrivateProf ileStringA" _
(ByVal lpApplicationNa me As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedStrin g As System.Text.Str ingBuilder, _
ByVal nSize As Integer, ByVal lpFileName As String) _
As Integer
Private Declare Ansi Function WritePrivatePro fileString _
Lib "kernel32.d ll" Alias "WritePrivatePr ofileStringA" _
(ByVal lpApplicationNa me As String, _
ByVal lpKeyName As String, ByVal lpString As String, _
ByVal lpFileName As String) As Integer
Private Declare Ansi Function GetPrivateProfi leInt _
Lib "kernel32.d ll" Alias "GetPrivateProf ileIntA" _
(ByVal lpApplicationNa me As String, _
ByVal lpKeyName As String, ByVal nDefault As Integer, _
ByVal lpFileName As String) As Integer
Private Declare Ansi Function FlushPrivatePro fileString _
Lib "kernel32.d ll" Alias "WritePrivatePr ofileStringA" _
(ByVal lpApplicationNa me As Integer, _
ByVal lpKeyName As Integer, ByVal lpString As Integer, _
ByVal lpFileName As String) As Integer
Dim strFilename As String
' Constructor, accepting a filename
Public Sub New(ByVal Filename As String)
strFilename = Filename
End Sub
' Read-only filename property
ReadOnly Property FileName() As String
Get
Return strFilename
End Get
End Property
Public Function GetString(ByVal Section As String, _
ByVal Key As String, ByVal [Default] As String) As String
' Returns a string from your INI file
Dim intCharCount As Integer
Dim objResult As New System.Text.Str ingBuilder(256)
intCharCount = GetPrivateProfi leString(Sectio n, Key, _
[Default], objResult, objResult.Capac ity, strFilename)
If intCharCount > 0 Then GetString = Strings.Left(ob jResult.ToStrin g,
intCharCount)
End Function
Public Function GetInteger(ByVa l Section As String, _
ByVal Key As String, ByVal [Default] As Integer) As Integer
' Returns an integer from your INI file
Return GetPrivateProfi leInt(Section, Key, _
[Default], strFilename)
End Function
Public Function GetBoolean(ByVa l Section As String, _
ByVal Key As String, ByVal [Default] As Boolean) As Boolean
' Returns a boolean from your INI file
Return (GetPrivateProf ileInt(Section, Key, _
CInt([Default]), strFilename) = 1)
End Function
Public Sub WriteString(ByV al Section As String, _
ByVal Key As String, ByVal Value As String)
' Writes a string to your INI file
WritePrivatePro fileString(Sect ion, Key, Value, strFilename)
Flush()
End Sub
Public Sub WriteInteger(By Val Section As String, _
ByVal Key As String, ByVal Value As Integer)
' Writes an integer to your INI file
WriteString(Sec tion, Key, CStr(Value))
Flush()
End Sub
Public Sub WriteBoolean(By Val Section As String, _
ByVal Key As String, ByVal Value As Boolean)
' Writes a boolean to your INI file
WriteString(Sec tion, Key, CStr(CInt(Value )))
Flush()
End Sub
Private Sub Flush()
' Stores all the cached changes to your INI file
FlushPrivatePro fileString(0, 0, 0, strFilename)
End Sub
End Class
=============== ==============
within my code I use the following to write a to a [setion] key=value
Dim objIniFile As New IniFile("your file path\yourfile.i ni")
objIniFile.Writ eString("Sectio n name", "Keyname", "your value as string")
'============== ======
to read from a [section] key=value
Dim objIniFile As New IniFile("your file path\yourfile.i ni")
Dim boolData As Boolean = objIniFile.GetB oolean("your Section name", "your
key", True)
good luck.......jois ey This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Germic |
last post by:
Does C# has an equivalent of the 'C' GetPrivateProfileString? or is the only
way to get similar features to read from an INI file is to do a DllImport on
Kernel32.dll?
Thanks
|
by: L |
last post by:
static extern uint GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
uint nSize,
string lpFileName);
Interoping GetPrivateProfileString is giving me this Exception in
|
by: musosdev |
last post by:
Hi guys
Okay, I've setup my projects to open and compile fine in VS2005 using FPSE
and remote web, but it's *really* slow. So I thought I'd have a go at doing
it the normal way, by loading from the network share.
It loads in VS2005 fine, and I can edit and save code changes etc, but when
I try and Build the solution, I get the following error...
An error occured loading a configuration file: Failed to start monitoring
|
by: Domac |
last post by:
I need to read some configuration data from .ini file located at
Application.StartupPath location .
Here is code snippet :
Public Declare Unicode Function GetPrivateProfileString Lib "kernel32" Alias
"GetPrivateProfileStringW" (ByVal lpApplicationName As String, ByVal
lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As
String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
|
by: 海风 |
last post by:
A question about GetPrivateProfileString
a section in a .ini file , for example
ip = 192.168.1.112
....
i want to get the ip value by using GetPrivateProfileString() function.
the code is :
| |
by: Nhan |
last post by:
Hi,
I am trying to use the function GetPrivateProfileString as following:
public static extern Int32 GetPrivateProfileString(string lpAppName, string
lpKeyName, string lpDefault, string lpReturnedString, short nSize, string
lpFileName);
.......
String sDatabase = "";
|
by: thiago777 |
last post by:
Is there a better way of accomplishing this ?: http://msdn2.microsoft.com/en-us/library/ms724353.aspx
I have some program settings which should be easily editable by the user (really like in a text file), but dont want to use such an old function like GetPrivateProfileString..
maybe an XML file would be the best solution ?
thanks
|
by: tpgames |
last post by:
Two days ago, MS office Word would type JP fonts, I thought. I didn't think I was using Works. Now, it won't type in JP. Jasc Paint shop pro 8, should type JP fonts because I am using XP, according to Corel's website, and Jasc uses whatever is in the XP font folder. But, it won't. All the JP fonts types as English, even with JP selected in the Language Bar. I can't afford to upgrade to any better paint program. I do have a free JP word...
|
by: alag20 |
last post by:
Hi Guys,
I need some urgent help with this as I am becoming clueless now.
I have 2 DllImport as below from Kernel32
private static extern int GetPrivateProfileString(string section, int key, string defaultValue, byte result, int size, string fileName);
private static extern int GetPrivateProfileString(string section, string key, string defaultValue, StringBuilder result, int size, string fileName);
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |