Windows mobile 6.5 - best way to read and write from and to a config file - visual-c++

I have a handheld device running WM6.5 and trying to put together an application that should prompt the user for some information (login, password) and save it to a file for later use.
Have tried app.config files but unfortunately it requires System::Configuration, I can add the DLL but can't get the code to run, it requires CRL or something like that which I can't configure this being a mobile app - the required option is missing from the project/solution configuration section.
I am using Visual Studio 2008 C++
What's the best way to make this happen? Precisely, 1) write a string somewhere and 2) read it back later on.
TIA
Later edit:
I have tried using a binary file, like this
// write to config file
std::string s="helloworldhelloworldhelloworld";
ofstream ofile("test.txt",ios::binary);
ofile.write((char*)s.c_str(),strlen(s.c_str()));
ofile.close();
And then I have tried reading it back like this
// read config file
char read_str[60];
ifstream inf("test.txt",ios::binary);
inf.read(read_str,60);
inf.close();
LPCTSTR application_settings = CA2W(read_str);
What happens is it adds some garbage at the end of the string, if the string is longer less garbage, otherwise more.
Is there a way to sort out this conversion issue?

Turns out, project was using Unicode and had to use wifstream and wofstream to be able to properly read the strings, rather than attempt to convert them from ANSI to unicode.
This should be a reminder for me to stay away from strong typed languages in the future. Too bad there's no other significant choice for Windows Mobile. Spent a bunch of hours on this, I could have used that time for something else.

Related

Heroku cannot store files temporarily

I am writing a nodejs app which works with fonts. One action it performs is that it downloads a .ttf font from the web, converts it to a base64 string, deletes the .ttf and uses that string in other stuff. I need the .ttf file stored somewhere, so I convert it. This process takes like 1-2 seconds. I know heroku has an ephemeral file system but I need to store stuff for such a short time. Is there any way I can store my files? Using fs.writeFile currently returns this error:
Error: EROFS: read-only file system, open '/app\test.txt']
I had idea how about you make an action, That would get font, convert it and store it on a global variable before used by another task.
When you want to use it again, make sure you check that global variable already filled or not with that font buffer.
Reference
Singleton
I didn't know that you could store stuff in /tmp directory. It is working for the moment but according to the dyno/ephemeral system, it gets cleaned frequently so I don't know if it may cause other problems in the long run.

Calling WriteRegMultiStr in NSIS properly

With version 3.02 of NSIS came the addition of the WriteRegMultiStr function. When the function is called in my script the script throws an error:
Usage: WriteRegMultiStr /REGEDIT5 rootkey subkey entry_name hex_string_like_660000000000
root_key=(HKCR[32|64]|HKLM[32|64]|HKCU[32|64]|HKU|HKCC|HKDD|HKPD|SHCTX)
The call itself looks like this:
WriteRegMultiStr /REGEDIT5 HKLM "System\CurrentControlSet\Services\SomeService" "DependsOnService" "service1 service2"
Since there is no documentation on this specific function which was added later on, long after WriteRegStr and WriteRegDWORD were available, I have to wonder - how does one use it?
So far with respect to entering REG_MULTI_SZ values I only found the directive to use a registry-NSIS -plugin. Yet the function exists, so how can it be used?
Addendum:
Encoding the string to hex and passing it with ot without quotation marks yields no desirable result either.
I was actually able to find an answer after digging through the depths of the internet. Since I don't think this has been answered on StackOverflow I will leave a response here, in case anyone wants to use this function.
The structure of the command as described in the opening post is basically correct, but the value must be encoded precisely. My command looks like this:
WriteRegMultiStr /REGEDIT5 HKLM "System\CurrentControlSet\Services\SomeService" "DependsOnService" 54,00,63,00,70,00,69,00,70,00,00,00,41,00,66,00,64
For anyone intending to test this string, this is
Tcpip
Afd
encoded in hexadecimal regedit format. Precisely this is Regedit Version 5.0 format, as opposed to REGEDIT4 format. A conversion editor can be used to achieve this, I used OTConvertIt.
The script should then compile, assuming you run NSIS version 3.02 or higher.
As you found out, the value data must be in the exact same format as .reg files from Windows 2000+.
The reason this instruction works this way is because it is actually the same as WriteRegBin under the hood and very little code was added to support this new functionality.
In the future you might be able to drop the /REGEDIT5 switch and give it plain strings but support for that has not been added yet.
The Registry plug-in does allow you to write these strings in a sane manner.

Having problems decompiling class files

I have been working on a game for a while now and i tried to make this game as easy to understand as possible and easy to change as well by using one variable in a few places and not write the variables value in each place so that if i decide to change the value i wont have to change it every where, i will just have to change the value of the variable.
Two days ago i formatted my computer and saved in my external Hard Drive a .Jar file of the
game and the Eclipse(Coding environment) folder in where i THOUGHT the game source should be located at but it wasn't thus losing my source code.
I was very upset but then I remembered that you can decompile a jar file.
I searched for a decompiler and found the jd gui decompiler opened my jar file and i was happy
to see that its actually works but then... I noticed that the code is alliiiiitle bit different.
The compiler added tons of this. all the classes which doesn't matter to me.
Then i noticed that every where there was a double type number it added a .0 and a D
at the end of the number and even is some places where i had for example 0.7 i saw that there is 0.699999996 which again doesn't really matter, not a big deal.
But then i noticed that in all the places where i had a final variable it changed it to its value (Example : supposed to be : numRowsToDraw = Panel.WIDTH / tileHeight + 2;
what it is now : numRowsToDraw = 768 / tileHeight + 2;)
which ruined all the easy to change aspect of the program and i didn't want to change
the numbers back to the variable in all the places there should be a variable because it will take a lot of work.
So my question is : Is there a decompiler which doesn't change your code?
If there is can you tell me the name of it?
THANKS!
Oh and i forgot to mention that i tried afterwards the JAD decompiler which did the same thing...
No, there is not. Decompilation can never get back source level constructs like comments or the particular formatting of literals. But I'm sure there are automated source formatting tools out there that let you do stuff like remove Ds on double literals.

Support for em-dash in Windows file paths using StgOpenStorage()

I had a customer reporting problems with a file in a specific path. Debugging some old Windows code, I have found that the code in question that fails is a call to StgOpenStorage(). The path in question that fails has an em-dash. If I take this em-dash out by renaming the file, then the call to StgOpenStorage() succeeds.
So my question is this: is this a known limitation with this function? Are there likely to be other Windows SDK functions that fail with special characters like em-dash? I noticed there is a call to mbstowcs() prior to calling this function, which makes me wonder if the problem is due to the code-page mapping the em-dash character incorrectly. The wchar path looks okay in the Visual Studio debugger prior to the call, so it seems weird that the function would fail on a path that the system allows.
You were right Roger Rowland, it was due to the active locale prior to the call to mbstowcs(). I fixed this problem by calling:
setlocale( LC_ALL, "" );
Prior to the call to mbstowcs(). It looks like for some reason the "C" locale doesn't support em-dash, as if I set this instead it fails:
setlocale( LC_ALL, "C" );
My regional settings are set to English (Australia).
Cheers.

Return value of c# exe with exec

i have a problem using inno setup. I'm installing an update with inno, and with the update.exe the user get a txtfile with a licencenumber. On his Unit this licencenumber readable by a dll function.
Before the installingprocess i have to compare these numbers. Only if this numbers are identical the user is trying to installing the update on the right machine with the right licence.
If i would put this check into an seperate exe, it would be easy to crack it by change the exe with one just doing nothing (no errorcode). So i want to split the checking into the seperated exe (where i check some other things like installed version number etc.) and the update.exe
In update exe, i want to read the txtfile inside the updatepackage - this is easy.
In check.exe i want to call the internal dll and get the licencenumber of the machine. I have to return this number as an int. C# allows me to do that.
But how can i get this number in innosetup?
I tried to take the errorcode for this (0=error - not right version etc, XXXXXXXXX = licencenumber of machine). But the errorcode is just 2 chars in inno. I get only 2 chars...
Saving the number in another file would'nt be a solution cause the user can crack it this way... Is it possible to get the number into inno without giving the user the chance to manilpulate??
If you move the code into a DLL (either COM or a plain stdcall DLL) then it can be used by Inno and pass extra data between them including full strings, etc.

Resources