|
|
Actually, you should declare your struct with padding out to the width of the datatype that you declare as the bits. EX:
struct Bitflags
{
unsigned char Bit1 : 1;
unsigned char Bit1 : 1;
unsigned char Bit1 : 1;
unsigned char Padding : 5;
};
|
|
|
|
|
I need to 'tag' a binary file I generate with a key value. I can't change the file format since a third-party vendor is using the output. I remember a Win32 class I took long ago where there was a way to write info to an NTFS file separate from it's data, almost like a file namespace. Anyone know how to do this?
I found more info:
Using the optional "named" attributes.
From a console window do this: echo some_guid_key_string > test.txt:key
How to read/write the named key data attribute from a fstream or hFile?
|
|
|
|
|
You found the answer, they're called streams. You can use a ":streamname" construct with any API that takes a file name. So you could open the file called "yourdatafile:mystream" and then any reads/writes you do are directed to that stream.
--Mike--
Latest blog entry: *drool* (Alyson) [May 10]
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
Ok, I'm making a file converter for a legacy app and it formats it's numbers lamely.
i.e.:
Normal c++ format:
1.5625E-002
Lame legacy app:
0.15625E-01
So I have 2 options: 1. Find the right format options, or 2. Split the number (represented in a std::string) @ the E and divide the ffirst half by 10, and add 1 to the exponent.
Now my question is:
A. Is there an easy way to format the number? (Lame Legacy format)
B. How do I easily split a std::string without going through all kinds of tepm assignments and sorry hoops?
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
I think the following can do the trick:
#include <iostream>
#include <string>
#include <stdio.h>
std::string legacy_display(double x)
{
char buff[256];
sprintf(buff,"%.4lE",x);
int integer_part;
int fractional_part;
int exponent;
sscanf(buff,"%d.%dE%d",&integer_part,&fractional_part,&exponent);
if(integer_part>=0){
sprintf(buff,"0.%d%.4dE%+.2d",integer_part,fractional_part,exponent+1);
}else{
sprintf(buff,"-0.%d%.4dE%+.2d",-integer_part,fractional_part,exponent+1);
}
return buff;
}
int main()
{
std::cout<<legacy_display(1.5625E-002)<<std::endl;
std::cout<<legacy_display(1.5625E+005)<<std::endl;
std::cout<<legacy_display(0.0)<<std::endl;
std::cout<<legacy_display(1.0)<<std::endl;
std::cout<<legacy_display(-1.0)<<std::endl;
return 0;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks Joaquín !
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Both the following are valid C++ and have the same meaning:
const int i = 0;
int const j = 0;
The first style is widely used, and everyone will recognise and understand it. The second style is not so immediately understandable to most developers. However, always putting the const qualifier immediately to the right of what it qualifies can prevent some esoteric bugs. There's a brief discussion of why, with examples, here[^], in the section titled Avoiding confusion by using a good programming style. I only found a few other examples when I searched a few weeks ago, so it's safe to assume the second method is not widely known.
In your opinion, is the safer, but less well-known and understood style "better" than the widely-used one, or not?
For what it's worth, I think the safer style is "better", but obviously changing such a deeply engrained style across a development team or organisation is likely to prove difficult.
Gavin Greig
"Haw, you're no deid," girned Charon. "Get aff ma boat or ah'll report ye."
Matthew Fitt - The Hoose O Haivers: The Twelve Trauchles O Heracles.
|
|
|
|
|
"const int" and "int const" are absolutely identical in meaning. I've literally never seen "int const" outside of reference books and web pages.
The "avoiding confusion" section in the quoted page is actually about programming style, which is a highly personal issue.
--Mike--
Latest blog entry: *drool* (Alyson) [May 10]
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
Maybe my examples weren't best chosen. As the article I referred to points out, the position of the const qualifier can become significant when you introduce a pointer or reference. So although "const int" and "int const" are identical, "const int*" and "int* const" are not. The first is a pointer to a const int, while the second is a const pointer to a non-const int.
Of course, you might not make this error if you separate the pointer from the type, because "const int *" and "int const *" are also identical in meaning.
Thinking in terms of always putting const to the right of what you are making const would help to avoid this sort of confusion.
Now, if you are using typedefs, it can be more confusing still:
typedef int * PINT;
typedef const PINT CPINT;
typedef const int * PCINT;
It might be "reasonable" to expect, when attempting to understand line 2 that the type defined in line 3 would be identical, because all we've done is substitute "int *" for the typedef PINT - but the result is not the same. However, if you adopt the "const to the right" convention, then making that direct substitution does work:
typedef int * PINT;
typedef PINT const CPINT;
typedef int * const CPINT;
Of course, you could say that you'll never write such a typedef, but the typedef could be created by someone else within a template - Loki makes use of typedefs in its Typelists, for example - and if you're not using the "const to the right" convention then it will be harder to understand and debug any resulting issues.
So yes, it is a style issue, but there is at least one specific circumstance in which it will commonly lead to an incorrect understanding of the way C++ works, and poor understanding leads directly to bugs.
What I was really hoping for were some opinions as to whether an improvement in long term understandability of code justified the short term confusion that would be inevitable by overturning a long-standing convention?
Reference: "C++ Templates - The Complete Guide", David Vandevoorde and Niccolai Josuttis.
There is also a short article (c.1998), available somewhere online, which seems to have been the first to raise this issue, but unfortunately I haven't managed to find it again to provide a link.
Gavin Greig
"Haw, you're no deid," girned Charon. "Get aff ma boat or ah'll report ye."
Matthew Fitt - The Hoose O Haivers: The Twelve Trauchles O Heracles.
|
|
|
|
|
I am trying to convert a service skeleton to unicode and I have run into a problem with the event logging. The function void CService::LogEvent(LPCSTR pFormat, ...) and has problems with parsing arguments. This is the original code that compiles under MBCS:
void CService::LogEvent(LPCSTR pFormat, ...)
{
TCHAR chMsg[256];
...
va_list pArg;
va_start(pArg, pFormat);
vsprintf(chMsg, pFormat, pArg);
va_end(pArg);
...
printf(chMsg);
}
so the following code will output Text=1
DWORD dw=1;
LogEvent("Text=%d", dw);
My code:
void CService::LogEvent(LPCSTR pFormat, ...)
{
TCHAR chMsg[256];
...
va_list pArg;
va_start(pArg, pFormat);
vswprintf(chMsg, (LPCTSTR)pFormat, pArg);
va_end(pArg);
...
printf("%s", chMsg);
}
will output Text=%d
I can't just print straight out each time because the LogEvent uses the chMsg string differently when its running as a services vs. a console app. Does anyone have an suggestions?
Matt
BURN HIM! - David Wulff
|
|
|
|
|
Ummm, having trouble finding a well defined question.
However that aside, if you are using TCHAR then you should also use a #define'd version of vsprintf i.e. _vstprintf().
Also, you might actually want to use _vsntprintf() instead to help prevent buffer overrun.
I'm not sure what you were asking with regard to the printf() statement.
...cmk
|
|
|
|
|
cmk wrote:
Ummm, having trouble finding a well defined question.
Oh, sorry. My problem was that instead of formating the DWORD value into the string, it was just printing the %d and ignoring the value.
Matt
BURN HIM! - David Wulff
|
|
|
|
|
Matt Newman wrote:
cmk wrote:
Ummm, having trouble finding a well defined question.
Oh, sorry. My problem was that instead of formating the DWORD value into the string, it was just printing the %d and ignoring the value.
Matt
Oh yes, i see what you were asking now.
The problem is likely that you are passing in straight char* "Text=%d" and yet using the unicode version which will expect ALL string parameters to be unicode.
Using the TCHAR is an all or nothing proposition.
Wrap all literal strings with _T() e.g. _T("Text=%d").
Personally i gave up on using all that as there were cases when i needed both ansi and unicode strings.
...cmk
|
|
|
|
|
I made a simple Windows application written in MFC that uses CHtmlView to render HTML pages and everytime it navigates to a page containing an applet, the application uses Microsoft's VM, even if the Internet Options has been set to use "Java 2 for <applet>". Sun's VM is used as expected when the same page is navigated from Internet Explorer.
Does anyone know how to get an application that extends the CHtmlView class to behave similarly to Internet Explorer and use Sun's Java? Thanks.
|
|
|
|
|
Does anyone know of a good reference on using a Rich Edit control 2.0 in a dialog application written in C. Currently if I place a rich edit box in my applicatoin is does not start but if I remove the rich edit control from the dialog form the application starts. Not sure what I am doing wrong? Any help would be most appreciated. If someone has some sample code the use Rich Edit box in c, it will be a great help.
Regards,
SAK
|
|
|
|
|
What you need to do is call AfxInitRichEdit() in your app's
InitInstance() function.
jhaga
CodeProject House, Paul Watson wrote:
...and the roar of John Simmons own personal Nascar in the garage. Meg flitting about taking photos.Chris having an heated arguement with Colin Davies and .S.Rod. over egian values. Nish manically typing *censur*. Duncan racing around after his pet *c.* Michael Martin and Bryce loudly yelling *c.* C.G. having a fit as Roger Wright loads up *c.* . Anna waving her *c.* and Deb scoffing chocolates in the corner.
...Good heavens!
|
|
|
|
|
Jhaga,
Thank you for the reply, I think AfxInitRichEdit is only is used when programming MFC, at least that is what the MSDN documentation seemed to say. Do I need to include a particular library, header? Is there an equivalent in 'c'. I tried search through google...can find much on programming richedit in c.
Regards,
SAK
|
|
|
|
|
How do you know if a combination of a path and filename is valid ?
I don't want to know if it is an actual existing file but only if it's valid (does not contain any invalid caracters). Also, I do not want to create a file on the disk to know if I'll receive an invalid filename error.
So, how can I know if a path + filename combination has a valid syntax ?
(example: "C:\folder name\file name.ext" is valid, "C:\folder name\file&?n!.ext" is invalid)
I'm using C++ only (no MFC, etc).
Thanks a lot !
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
J.-C. Gauthier - http://www.grandmenhir.com/
|
|
|
|
|
One solution is to create a temporary file or path.
Kuphryn
|
|
|
|
|
Unfortunately, I do not want to do that (like mentionnend in the original post) Its a possible solution but I would like to use only if everything else should fail
|
|
|
|
|
Testing is the only programming solution.
Kuphryn
|
|
|
|
|
This article titled "Making Room for Long Filenames" in the location "Windows Base Services General Technical Articles " of the MSDN Library has a few general guidelines for long filenames, and they include:
- The application must not use the following characters in directory names or filenames, because they are reserved for Windows:
< > : " / \ |
- The application must not use reserved words, such as aux, con, and prn, as filenames or directory names.
The documentation forgot to mention that asterisk (*) and the question mark (?) are also invalid characters.
|
|
|
|
|
I might soon need to write an Extensible Authentication Protocol (EAP) and wondered if there is anyone out there that has done this...
I've got the VS6 sample that implements a simple password request response protocol and that looks pretty straightforward but MSDN also mentions a further sample in the section entitled Server-Side Configuration User Interface that would show an ATL implementation of IEAPProviderConfig - does anyone know where I can get hold of this sample.
If there's anyone out there that's implemented an EAP dll then any tips that would be really appreciated.
|
|
|
|
|
im trying to use ImageMagick with MS Vision SDK.
there are a few problems that i have
[1] i am trying to run the demo project from Imagemagick 5.5.6
i have linked the following folders to the project:
C:\Projects\ImageMagick\Magick++\lib
C:\Projects\ImageMagick\Magick++
C:\Projects\ImageMagick\magick
but i still get the following error:
c:\projects\imagemagick\magick++\lib\magick++\include.h(13) : fatal
error C1083: Cannot open include file: 'magick/magick_config.h': No
such file or directory
any ideas??
[2] i need some advice about using both MS vision SDk and ImageMagick together. is there certain versions of Image Magick that will only work with MS vision SDk? and how would i link the image resize class from ImageMagick with a MS Vision Project?
Elaine
elaine_clancy@hotmail.com
|
|
|
|