Author |
Topic: struct type ptr (Read 3387 times) |
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: struct type ptr
« Reply #25 on: Nov 21st, 2015, 09:39am » |
|
I found out that CHAR[32766] is the largest that works with the API (or is it a limit of CHAR[]?) That's plenty of room for INI stuff. I suppose there's a problem with running out of something while the program is running if the STRUCT gets too large.
Its a little clunky, because the name of the STRUCT is coded into the FUNCTION, but I envision several specific FUNCTIONs with several specific STRUCTs writing to the same INI file.
Maybe obfuscation isn't so clunky after all? :D
Code:
if right$(DefaultDir$,1)<>"\" then
DefaultDir$=DefaultDir$+"\"
end if
inifile$ = DefaultDir$ + "JunkINIstruct.ini"
print inifile$
struct structName, keychars$ as CHAR[32766] ' fails when CHAR[32766] is exceeded
ret = WriteINIStruct1("settings","config","0123456789:",inifile$)
print "ret from write: ";ret
print "Got this: ->"+GetINIStruct1$("settings","config",inifile$)+"<- (from GetINIStruct1$)"
end
function WriteINIStruct1(SectionName$,KeyName$,KeyChars$,inifile$)
' Returns true (1) if nothing wrong or false (0) if a problem
'code by Richard Russell
structName.keychars$.struct = KeyChars$
size = len(structName.struct)
calldll #kernel32, "WritePrivateProfileStructA", _
SectionName$ as ptr, _ ' Section name
KeyName$ as ptr, _ ' Key name
structName as struct, _ ' Structure
size as ulong, _ ' Size of structure
inifile$ as ptr, ret as long
WriteINIStruct1 = ret
end function
function GetINIStruct1$(SectionName$,KeyName$,inifile$)
' Returns string value if nothing wrong or NULL if a problem
'code by Richard Russell
size = len(structName.struct)
calldll #kernel32, "GetPrivateProfileStructA", _
SectionName$ as ptr, _ ' Section name
KeyName$ as ptr, _ ' Key name
structName as struct, _ ' Structure
size as ulong, _ ' Size of structure
inifile$ as ptr, ret as long
if ret = 0 then GetINIStruct1$ = "" : exit function
GetINIStruct1$ = structName.keychars$.struct
end function
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: struct type ptr
« Reply #26 on: Nov 21st, 2015, 10:00am » |
|
on Nov 21st, 2015, 09:39am, pnlawrence wrote:| I found out that CHAR[32766] is the largest that works with the API (or is it a limit of CHAR[]?) |
|
I'm really not sure what you are trying to achieve. If you are storing a single string, especially if it is quite a long string, using a STRUCT isn't a particularly appropriate method. For example it stores more than twice as much data in the INI file as it needs to (each character of the string gets expanded to two hex characters).
If your objective is to obfuscate the string, storing it as hex will defeat only the most simplistic attempts at reading it. Many people will immediately recognise hex text, and either be able to read it 'by inspection' or simply copy-and-paste it into their favourite hex editor.
A trivial encryption technique, like XOR-ing each character of the string with a pseudo-random key, would be much more effective and not waste space in the file. STRUCTs wouldn't be involved at all.
Richard.
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: struct type ptr
« Reply #27 on: Nov 21st, 2015, 10:46am » |
|
Not concerned with file size. "Many people" are not part of my target audience. Some folks just think its fun to poke around and see what they can do.
Also, I like it that the "fields" of the STRUCT are not delineated in the file.
Of course one wouldn't write a 32K section to an INI file, but that is a tested limit.
I used the word "obfuscation" instead of "encryption" for a reason. Not even trying to hide it in plain site.
If the STRUCT(s) look like the following, then I think the INI file data would be obscured well with little programming effort. And there's the checksum, although that's not much of a deterrent, to contend with if one just changes a character.
Code:
STRUCT startup, keychars$ as CHAR[12], numUsers as long, posX as ulong, posY as ulong, mainDataFilename$ as CHAR[32], thumbDrivePresent as boolean, screenSizeHeight as ulong, screenSizeWidth as ulong
STRUCT currentUser, userName$ as CHAR[12], userDescription$ as CHAR[257]
Write these in separate sections of an INI file, and Bob's your uncle. (Bob is your uncle, isn't he? :D )
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: struct type ptr
« Reply #28 on: Nov 22nd, 2015, 12:21am » |
|
Posted the following to the other forum, too.
My version using FUNCTIONS. (Thanks to R.R. and tsh73 for debugging.)
Code:
'===========================================
' WritePrivateProfileStructA Demo
'===========================================
' Acknowledgements to the original authors
' Submitted by pnlawrence 11/21/2015
' This is only one example on how to perform INI file Section writing with a STRUCT.
' Of course, the STRUCT(s) can be rewritten and the FUNCTION(s)
' can be slightly rewritten to return almost any INI file data.
if right$(DefaultDir$,1)<>"\" then
DefaultDir$=DefaultDir$+"\"
end if
inifile$ = DefaultDir$ + "JunkINIstruct.ini"
print inifile$
' STRUCT can be created however required with many different types included
' nothing in the resulting INI file section delineates the different parts of the STRUCT
' the resulting INI file section also includes a checksum to detect changes
' the resulting INI file section is more than double the original total length of the values written
' because each input character string/value is written as double-digit ASCII + nul termination + checksum
' the STRUCT is GLOBAL
struct structName, keychars$ as CHAR[12] ' fails when CHAR[32766] is exceeded
print "Return from write: "; WriteINIStruct("settings","config","0123456789:",inifile$)
print "Return from get: ->"+GetINIStruct$("settings","config",inifile$)+"<-"
end
'===========================================
' FUNCTIONS
'===========================================
function WriteINIStruct(SectionName$,KeyName$,KeyChars$,inifile$)
' Returns true (1) if nothing wrong or false (0) if a problem
'code by Richard Russell
structName.keychars$.struct = KeyChars$
size = len(structName.struct)
calldll #kernel32, "WritePrivateProfileStructA", _
SectionName$ as ptr, _ ' Section name
KeyName$ as ptr, _ ' Key name
structName as struct, _ ' Structure
size as ulong, _ ' Size of structure
inifile$ as ptr, ret as long
WriteINIStruct = ret
end function
function GetINIStruct$(SectionName$,KeyName$,inifile$)
' Returns string value if nothing wrong or NULL if a problem
'code by Richard Russell
size = len(structName.struct)
calldll #kernel32, "GetPrivateProfileStructA", _
SectionName$ as ptr, _ ' Section name
KeyName$ as ptr, _ ' Key name
structName as struct, _ ' Structure
size as ulong, _ ' Size of structure
inifile$ as ptr, ret as long
if ret = 0 then GetINIStruct$ = "" : exit function
GetINIStruct$ = structName.keychars$.struct
end function
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: struct type ptr
« Reply #29 on: Nov 22nd, 2015, 8:03pm » |
|
on Nov 22nd, 2015, 12:21am, pnlawrence wrote:| Posted the following to the other forum |
|
I trust you explained, in 'the other place', why you are using a STRUCT to store a string. I wouldn't want anybody to be misled into thinking it was preferable to using WritePrivateProfileString / GetPrivateProfileString (in normal circumstances).
Richard.
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: struct type ptr
« Reply #30 on: Nov 23rd, 2015, 12:16am » |
|
They wouldn't listen anyway. They think I'm being difficult. I'll probably get banned, too.
|
|
Logged
|
|
|
|
AAW
New Member
member is offline


Posts: 22
|
 |
Re: struct type ptr
« Reply #31 on: Nov 23rd, 2015, 10:33am » |
|
on Nov 23rd, 2015, 12:16am, pnlawrence wrote:They wouldn't listen anyway. They think I'm being difficult. I'll probably get banned, too. |
|
When you wrote, "Apparently, you think I'm being difficult." I responded, "I reread my messages and I do not see anything that implies that I think you are being difficult. I am trying to be helpful."
In order to help you, I updated articles on LBPE. Anatoly created a new, in-depth demo for you, and Rod and I made suggestions of other ways you could accomplish your goal. I suggested a simple Rot13 encryption to obfuscate your text in WritePrivateProfileString.
I can find no place AT ALL where anybody indicates that you are being difficult, that we don't listen to you, and certainly not that you are about to be banned. I am completely confused. We've all tried to be polite and helpful.
I am sorry were were unable to help you do exactly as you wanted, but we tried.
|
|
Logged
|
|
|
|
SarmedNafi
Junior Member
member is offline


Posts: 93
|
 |
Re: struct type ptr
« Reply #32 on: Nov 23rd, 2015, 10:49am » |
|
Quote: Anatoly created a new, in-depth demo for you
|
|
A link please Dear Madam, I will appreciate that.
Regards Sarmed
|
| « Last Edit: Nov 23rd, 2015, 11:05am by SarmedNafi » |
Logged
|
|
|
|
SarmedNafi
Junior Member
member is offline


Posts: 93
|
 |
Re: struct type ptr
« Reply #33 on: Nov 23rd, 2015, 10:54am » |
|
Dear pnlawrence,
I have a question if you please. What is the benefits of using API for creating an initial file (.ini)? Why not using a normal sequential file? as I always did?
Regards Sarmed
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: struct type ptr
« Reply #34 on: Nov 23rd, 2015, 11:10am » |
|
Hey, Alyce, it was a joke. We're free to joke around on this forum.
Hey, Alyce, how come you can freely post on this forum for Liberty Basic Booster AKA LBB, about things that happen on the LB forum but it is "against the rules" for ANYONE to do the reverse? I'm just curious.
Wouldn't it be nice if Richard could comment on topics of interest to LBB on the LB forum? It is kind of difficult with the current arrangement.
I'm sure that Richard could have had several helpful suggestions with recent posts, but I don't think he's on the list of members with posting privileges. (Actually, he did comment, but he had to do it on this forum only. Remember that? I admit to copying text from LB to LBB forum, so there's your opportunity with the broken rule.)
I've read all the tiring posts about "promoting" etc., but I fail to see the difference between "promoting" Liberty Basic Booster and "promoting" languages like "Visual Basic" or "C" or "C++" or "Pascal" or etc. I'm purty sure those are OK to write about on that forum.
Can you explain how "promoting" those other languages are OK on the LB forum, but no one can even obliquely mention Liberty Basic Booster? (You surreptitiously deleted a forum post of mine because I obliquely mentioned Liberty Basic Booster.)
I'm just curious.
PS. Feel free to comment here, because I'm hoping to clear the air and get these BASIC programs back into a cooperative state instead of stuck in 2006.
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: struct type ptr
« Reply #35 on: Nov 23rd, 2015, 11:12am » |
|
Another tool in the toolbox. You can do both within the same file, too.
on Nov 23rd, 2015, 10:54am, SarmedNafi wrote:| What is the benefits of using API for creating an initial file (.ini)? Why not using a normal sequential file? as I always did? |
|
|
| « Last Edit: Nov 23rd, 2015, 11:12am by joker » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: struct type ptr
« Reply #36 on: Nov 23rd, 2015, 11:17am » |
|
on Nov 23rd, 2015, 12:16am, pnlawrence wrote:They wouldn't listen anyway. They think I'm being difficult. I'll probably get banned, too. |
|
Hmm, sounds like things are getting worse over there, if anything. I wonder if it stems from disappointment with LB 4.5.0; many people must have been hoping for a more comprehensive update, with many more bugs being fixed.
Has Carl released LB Pro 4.5 yet? I think it was a very unwise decision to delay it because LB Pro users represent some of his most loyal and enthusiastic customers. In his position I wouldn't have released any update until both regular and Pro versions were ready.
Richard.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: struct type ptr
« Reply #37 on: Nov 23rd, 2015, 11:33am » |
|
on Nov 23rd, 2015, 10:54am, SarmedNafi wrote:| What is the benefits of using API for creating an initial file (.ini)? |
|
It's a standard format, which many people are familiar with, so editing such a file doesn't involve learning anything new.
The API allows you to read and write individual records, without having to update the entire file.
STRUCTs can be stored in the file, something which is difficult (or impossible) to do with regular LB sequential or random files.
Because structs can be stored, floating-point numeric values (DOUBLEs) can be saved in the file with no loss of precision. With a conventional file numbers must be converted to strings and back, which is often lossy.
The file is never 'open' in LB, so a crash or other bug can't leave a corrupted INI file behind, or delete it.
It's much easier than writing, testing and maintaining the code yourself. Richard.
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline


Gender: 
Posts: 210
|
 |
Re: struct type ptr
« Reply #38 on: Nov 23rd, 2015, 11:44am » |
|
SarmedNafi
>>A link please Dear Madam, I will appreciate that.
WritePrivateProfileStructA Demo
|
| « Last Edit: Nov 23rd, 2015, 11:45am by tsh73 » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: struct type ptr
« Reply #39 on: Nov 23rd, 2015, 11:59am » |
|
on Nov 23rd, 2015, 11:10am, pnlawrence wrote:| I'm sure that Richard could have had several helpful suggestions with recent posts, but I don't think he's on the list of members with posting privileges. |
|
I'm not even allowed to read the LB Forum, let alone post there; I can't even see what guests, who have never joined, are allowed to see. 
There was a time, in the distant past, when I was allowed to be a member of, and even post to, the LB Forum. I contributed a number of posts which I like to think were valuable, for example demonstrating how COM Objects could be called from LB, something which had previously been believed to be impossible without a helper DLL.
But I made the mistake of using the Private Messaging system for exactly what the rules (at the time) encouraged its use for - i.e. communicating with other members about 'sensitive' subjects not permitted in posted messages (in this case telling them about LBB when they had posted a query that LBB provided a solution for).
Apparently some recipients of those messages complained to the forum administrators about them (why they would complain about being given an answer to their queries I don't know). I wasn't told about those complaints (at the time), I was never asked not to send messages of that sort, there was never any direct communication with me at all. I was simply banned.
Richard.
|
|
Logged
|
|
|
|
|