Sign in to follow this  
Followers 0
xbennY0

Read struct from .bin file!!!??

28 posts in this topic

#1 ·  Posted (edited)

Is it possible to set data in a struct from a .bin file like in C? thx!

example in C++:

struct stAccount
{
    stSocket Socket;

    short Status;
    char PacketBuffer[2048];

    stDataBase DataBase;
};

stAccount Client[5000];

void Request::Login(stAccount *n_Client)
{
    p20D *Packet = (p20D*)&n_Client->PacketBuffer;

    FILE *hFile = NULL;
    char *TMP = new char[100];

    sprintf(TMP, "DataBase\\Accounts\\%c\\%s.bin", GetFirstKey(Packet->Username), Packet->Username);

    SecureZeroMemory(&n_Client->DataBase, sizeof(stDataBase));

    fopen_s(&hFile, TMP, "rb"); // read binary
    fread(&n_Client->DataBase, sizeof(stDataBase), 1, hFile); // "strcpy to struct"
    fclose(hFile);
}
Edited by xbennY0

Share this post


Link to post
Share on other sites



I don't know c well but you can populate an autoit dllstruct with the contents of a file. Give a little more info on your goal.

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

For example... 

I have 100 folders and each of these folders have another 50 folders within, within those 5000 folders (100 folders * 50 in each one) there are 20 .txt files containing some text.

Something like this:

 

...folder 1:

   - sub folder[1-1]:

          - data[1].txt

          - [...]

          - data[20].txt

   - [...]

          - [...]

   - sub folder[1-50]:

          - data[1].txt

          - [...]

          - data[20].txt

------------------------------------------------------------------------

...folder 2:

   - sub folder[2-1]:

          - data[1].txt

          - [...]

          - data[20].txt

   - [...]

          - [...]

   - sub folder[2-50]:

          - data[1].txt

          - [...]

          - data[20].txt

------------------------------------------------------------------------

...folder 3:

   - sub folder[3-1]:

          - data[1].txt

          - [...]

          - data[20].txt

   - [...]

          - [...]

   - sub folder[3-50]:

          - data[1].txt

          - [...]

          - data[20].txt

------------------------------------------------------------------------

...[...]:

------------------------------------------------------------------------

...folder 100:

   - sub folder[100-1]:

          - data[1].txt

          - [...]

          - data[20].txt

   - [...]

          - [...]

   - sub folder[100-50]:

          - data[1].txt

          - [...]

          - data[20].txt

 

I need to get all this information (including the name of the folders) and put into a struct! is it possible?

thanks!

Edited by xbennY0

Share this post


Link to post
Share on other sites
Of couse yes.
 
_FileListToArrayRec to search the txt. and fileread+dllstructure.
 
Saludos
1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

 

Of couse yes.
 
_FileListToArrayRec to search the txt. and fileread+dllstructure.
 
Saludos

 

Woww!! Thx bro!

then I want to save the struct in a binary file for easier reading(to not need to use the folders)

can you make a simple example??

best regards.

Edited by xbennY0

Share this post


Link to post
Share on other sites

I think no need to use structure for that.

You simple should use _FileListToArrayRec+fileread+filewrite or filecopy

Saludos

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I think no need to use structure for that.

You simple should use _FileListToArrayRec+fileread+filewrite or filecopy

Saludos

but I want something to remove these folders! I don't want to use them... like make a binary file with everything inside, you see?

Edited by xbennY0

Share this post


Link to post
Share on other sites

Do you mean like a zip file or something similar, with all the files in ?

Share this post


Link to post
Share on other sites

SQL database?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Do you mean like a zip file or something similar, with all the files in ?

Yes!

 

SQL database?

How? this is a good idea?

1 person likes this

Share this post


Link to post
Share on other sites

up

Share this post


Link to post
Share on other sites

There are examples of using archiving software to do what you want, do a search of the examples section for ZIP.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

There are examples of using archiving software to do what you want, do a search of the examples section for ZIP.

but I do not want to work with the folders!! I want them as structs

Share this post


Link to post
Share on other sites

Are you sure, do you even know what a struct is? What possible use would they be to you as a struct, and what would you do with the contents of this struct once yo've deleted the folders and put them inside it?

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Are you sure, do you even know what a struct is? What possible use would they be to you as a struct, and what would you do with the contents of this struct once yo've deleted the folders and put them inside it?

of course i know... I would save it in a .bin to read it later, exactly the example that I gave in c++

the idea is to merge everything into one file(as a binary for example) excluding the folders.

Do this in c++ is easy i don't know here in autoit...

thanks for your help bro!

Edited by xbennY0

Share this post


Link to post
Share on other sites

xbennY0,

Why not just use _FileListToArrayRec to get all of these files into an array and then loop through it reading their content, adding this content to a single text file, and then deleting them? That sounds the quickest way of doing you want. :)

Although I would delete the files on a second pass - just in case something goes wrong. ;)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

xbennY0,

Why not just use _FileListToArrayRec to get all of these files into an array and then loop through it reading their content, adding this content to a single text file, and then deleting them? That sounds the quickest way of doing you want. :)

Although I would delete the files on a second pass - just in case something goes wrong. ;)

M23

Hm....but how i will be able to read this single file? is it possible put this contents(in the single file) in a struct to organize them?

Can you make a simple example?

thx again!

Share this post


Link to post
Share on other sites

xbennY0,

 

is it possible put this contents(in the single file) in a struct to organize them?

You still have not really explained why you keep on about putting all this mass of data into a struct. What advantage does it give you over a single text file containing the content of all the files? Perhaps if you gave us a concrete example of what these files contain and what you mean by "organise" we might be a little wiser. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

xbennY0,

 

You still have not really explained why you keep on about putting all this mass of data into a struct. What advantage does it give you over a single text file containing the content of all the files? Perhaps if you gave us a concrete example of what these files contain and what you mean by "organise" we might be a little wiser. :)

M23

Because it is easier to find one single file than 3.000. Because it transfers the program to a computer faster(with these folders takes about 15 minutes to transfer 3MB).

Edited by xbennY0

Share this post


Link to post
Share on other sites

xbennY0,

If all you requires is all the data in one file, then what I suggested in post #16 above should be what you need. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0