|
In general 0xFF 0xFE means little-endian; 0xFE 0xFF means big-endian, and 0xEF 0xBB 0xBF means UTF-8.
When loading a file of unknown encoding, i normally look for these byte order marks first, then if they aren't found, i scan for null bytes in the string (an obvious giveaway of unicode), and if that fails then i check to see if the string conforms to UTF-8 (UTF-8 defines valid ranges for the first, second, and third bytes of a character). If all that fails, i load the string using the default character encoding of the system it is running on.
Of course, i'm normally dealing with EDI or XML messages, almost all of which start with english characters so if it is unicode i'll know after looking at the first two bytes of the message.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
This came up a couple of days ago so I can still remember - IsTextUnicode is a handy function that does all the checks for you!
|
|
|
|
|
Johnny ² wrote:
IsTextUnicode
Very handy!
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
This hasn't been mentioned yet, so I'll add it. It's called the BOM - byte order mark. The Unicode value 0xFEFF is the BOM, and the way it appears in the file indicates whether the remainder of the values are little- or big-endian. So when a reader sees FF FE at the beginning, it knows it's got a little-endian file. (0xFFFE is reserved, btw, so as not to conflict with 0xFEFF.)
--Mike--
"So where does that leave us? Well, it leaves us right back where we started, only more confused than before." -- Matt Gullett
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
Hey Friends
Can someone suggest how to use CRectTracker MFC Class so that we can keep track of multiple selections.
|
|
|
|
|
I often get this weird error when working in the MS VC++ 6.0 environment.
... error C2018: unknown character '0xa0'
Most of the time it happens when I cut and paste stuff, the incriminating line being the one I paste. But there is no error whatsoever in the line. I usually erase and retype all the stuff, but as you guess it is sometimes painful. How to get rid of this?
Cheers.
blackmesa
Humble student
|
|
|
|
|
You have an extraneous char like a ' . \ + or similar. or in this case
the one with hex value 0xa0 or 160.
Just remove it - it really is there.
Sometimes its hard to find as in
GetDialog(h);
printf("test");'
exit(-99);
In fact in this case the output of
void main()
{
printf("'%c'\n",0xa0);
}
explains why its hard to find.
|
|
|
|
|
The character with the value 0xa0 is à. And it is nowhere in my code. i post it here, with the incriminated lines in bold.
if ((i > 0) && (j < NBCELLS-1) && (board_copy[j+1][i-1] == 1))
{
++surr_cells;
}
if ((i < NBCELLS-1) && (j < NBCELLS-1) && (board_copy[j+1][i+1] == 1))
{
++surr_cells;
}
if ((i < NBCELLS-1) && (j > 0) && (board_copy[j-1][i+1] == 1))
{
++surr_cells;
}
Blackmesa
Computer engineering student
Étudiant en génie informatique
------------------------------
|
|
|
|
|
What is the definition of NBCELLS ?
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
#define NBCELLS 20
It is in top of the file, I just didn't paste this line.
Blackmesa
Computer engineering student
Étudiant en génie informatique
------------------------------
|
|
|
|
|
Try opening the file in another editor and resaving it. If one particular line became corrupted for some reason, and you're copying and pasting it, then you might be pasting more corrupted lines.
Or type the line by hand in again - just type below the current line and delete the old one. I'd do this. If it works for one line, then you can copy and paste that one.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
I will made a UI by MFC; The UI just like media player9 ,
I use the function SetWindowRgn, but when the panel zoomed what can I get the ner rgn
A man can do what he want but not wants what he want
|
|
|
|
|
Hi peoples,
Given a Dll generated with VS C++ 6.0, no .h file for that dll and no documentation.
How easy is it too,
[1] - Find the number of parameters for the function
[2] - Find the types of those arguments
I have heard about securing dlls with public/private key cryptography with .NET.
Is it worth the effort? If I have a DLL which is the core of my system is it
relatively easy to link it into a new application and use it effectively?
Thanks.
|
|
|
|
|
flip wrote:
How easy is it too,
[1] - Find the number of parameters for the function
[2] - Find the types of those arguments
Simple answer. You can't. Not unless you want to disassemble the DLL code and step through the assembly code by hand to see what it does.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Yes, and thats exactly the question.
How easy is it to do that? Is it practically impossible or relatively fairly simple.
If it has been done before (ever) then I probably do not want to expose a core component of the system as a dll (or even an encrypted dll).
Also can I still compile a dll in VC 6 and then encrypt it later or do I have to use
.NET to encrypt it at each build?
Can anyone provide a link to dll Securing for .NET?
|
|
|
|
|
flip wrote:
How easy is it to do that? Is it practically impossible or relatively fairly simple.
Fairly impossible would be an understatement . It is extremely difficult.
I haven't ever tried to encrypt a DLL, and I haven't used .NET, so I can't help with the rest
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
How easy is it to do that? Is it practically impossible or relatively fairly simple.
R - Fairly impossible would be an understatement . It is extremely difficult.
Ok good. Thats what I thought.
R - I haven't ever tried to encrypt a DLL, and I haven't used .NET, so I can't help with the rest
Same here.
I am trying to avoid .NET since nothing in the program needs it.
If I was using .NET technologies - then things would be different.
I just dont see the need to have to switch over to .NET just to ensure the dlls are
encrypted when I am happy with VC 6.
Ryan
|
|
|
|
|
There's an article here on CP somewhere about encrypting an EXE file. Perhaps you could modify that to work with a DLL...
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
As Ryan said you have to disassemble the DLL code to find the number of parameters. There are certain patterns to determine the number of parameters, for instance before a function is called, its parameters are pushed into the stack
push eax<br />
push ecx<br />
call DllFunc
which in C++ translates to DllFunc( ecx, eax).
At the end of the function you could have something like this:
ret 000X - where X is a number (4, 8, C etc.), which will tell you the number of parameters, and 4 means one parameter, 8 means two and so on.
After the function has returned, if you see code like this:
add esp, 0X - where X again is a number that tells you the number of parameters. This is an adjustment done to the stack after a function returns.
There are more hints out there but you have to study some assembly to figure out most of them.
Finding the types of those arguments is very difficult and sometimes impossible. You need to know something about the function.
// Afterall, I realized that even my comment lines have bugs
When one cannot invent, one must at least improve (in bed).-My latest fortune cookie
|
|
|
|
|
Toni78 wrote:
push eax
push ecx
call DllFunc
which in C++ translates to DllFunc( ecx, eax).
Sometimes, but not always. I've looked at the output from some compilers, and sometimes they push the registers simply to save their value across the function call. I don't think this happens with the MS compiler, but other compilers do it. Also, the compiler may perform processing in between the pushes, and it may use the stack for doing that processing, so it can be very complex. But I agree, looking at the instructions before the call is the easiest way.
The problem is that in his situation he want to know if you can work out the parameters from the DLL - no calling code. That is substantially more difficult because you have to look at what each parameter is used for and what is done with them. And then, as you said, finding the types of the parameters is almost impossible
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote:
Sometimes, but not always.
I couldn't agree more. However, I was just trying to give him some pointers and I thought this could help.
When it comes to the types of the parameters, simple data types such as int, char, char*, etc can be detected "easily" but structures and classes are such a pain (or undetectable).
// Afterall, I realized that even my comment lines have bugs
When one cannot invent, one must at least improve (in bed).-My latest fortune cookie
|
|
|
|
|
I was currently reading an article in my linux mag about the wonderful uses of the assert function. I personally use this function and variations of it a lot. My question arises when I caught a side bar of the article about some preprocessor macros.
The sidebar explains how assert is so great because of the __LINE__ and __FILE__ macros. However it also explains two useful macros that are available under the GNU C compiler. __FUNCTION__ and __PRETTY_FUNCTION__. The first being for C compilers it returns the functions name. Since C++ mangles function names do to overloading the second returns the full function name (i.e. "void CMyClass::myfunc(int, double)" ). However these do not seem to be available under Microsoft's or Borland's compiler, and a long search through MSDN doesn't reveal anything similar. Is there a way to produce similar output with the MS compiler?
|
|
|
|
|
A good place to start is current_function.hpp in the boost library. Boost tends to be a good place to start for information and patterns which work around differences in compilers.
#ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED
#define BOOST_CURRENT_FUNCTION_HPP_INCLUDED
#if _MSC_VER >= 1020
#pragma once
#endif
namespace boost
{
namespace detail
{
inline void current_function_helper()
{
#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000))
# define BOOST_CURRENT_FUNCTION __PRETTY_FUNCTION__
#elif defined(__FUNCSIG__)
# define BOOST_CURRENT_FUNCTION __FUNCSIG__
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
# define BOOST_CURRENT_FUNCTION __FUNC__
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
# define BOOST_CURRENT_FUNCTION __func__
#else
# define BOOST_CURRENT_FUNCTION "(unknown)"
#endif
}
}
}
#endif // #ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
__FUNCTION__ is available in VS.NET; it returns the undecorated name of the function.
|
|
|
|
|
Hey everyone, I just wanted to inform you of a great great website that really helped me out with reading and writing to the registry using C++. It took me many hours to find a website with simple explanations and examples like this.
http://www4.ncsu.edu:8030/~jgbishop/codetips/general/registry_access_advanced.html
Check it out...
|
|
|
|