|
I'm sorry I thinked that you was talking about VB...
If you want to Know the HWND of the label, you must to use the label like a CWnd, and asign it with CWnd::GetDlgItem. You can get the handle with the data memeber CWnd::m_hWnd...;)
Best Regards...
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
I've been tinkering a little with STL after my brief run-in with the map template the other week. It took me a while to recover from that episode; but i've been having a go with the string thing.
My current program users c strings (char arrays, not that mfc bunk). I can already hear Christian muttering in the background. I used them becuase my program has the following traits:
-> lots of scanf and sprintf type stuff goes on, to jam integers to and from strings.
-> I'm using sockets and use char pointers to muck about with the input buffer that i receive through my socket.
-> one part of my program decodes a mime- formatted email body. as you may know, this is a hierarchical structure where a section consists of a header and a body. a body could also be a section in it's own right, consisting of a header and a body. Right now, i start with one big char pointer, and i call a function recursively on each body section to decode. This makes extensive use of tricking a c-type string into multiple separate strings by sticking \0 in the correct places.
I'm worried that reimplementing my program using stl is going to be a nightmare. Can someone please explain to me how it will in fact be a delightful process instead.
Jon
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
I have done a lot of the same stuff that you are doing, and I started to change my program from char pointers to std::string
Performance was, err.., one third, and it was a nightmare to change the program. std::string is way too slow for extensive string-stuff
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
I have to agree with Anders. For dynamic string intensive stuff, char arrays work best. For general string storage and lightweight processing, std::string is the way to go.
I use both extensively.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
One minor clarification.
If your string intensive stuff just results in always having to reallocate storage space to support changes in the string, then std::string should work just fine too.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I read an article in CUJ or DDJ (can't remember which) last fall which dealt with these performance problems.
One solution (using storage trade-offs) was to create a std::string compatible class called something like fixed_string. fixed_string would then implement the string using a fixed length char array. You got the best of both worlds: speed and the nice std::string interface.
The article also mentioned how you could pool these strings to optimize the performance even more (mostly for threaded environments).
I'm sorry I can't give you a correct reference to the article, my magazines are at home, and I'm not online at home anymore
Sonorked as well: 100.13197 jorgen
FreeBSD is sexy.
|
|
|
|
|
Exactly. Get the safe deallocation (if your strings are that big). Maybe even buffer overrun if you so decide it is needed.
As I have always said, know what tools are available and understand the costs involved with each.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Hi,
You should also consider the use of std::vector<char>
To the best of my knowledge, the std requires that elements should be allocated contiguosly (not sure)
Consider
std::vector<char> buffer;
buffer.resize(n);
legacy_function(&(buffer.at(0)),buffer.size());
Comments:
I am not comparing anything. Just another "tool/way" to do things that is worth be aware of
Regards,
R.
|
|
|
|
|
To the best of my knowledge, the std requires that elements should be allocated contiguosly (not sure)
The standard does not guarantee this, but later on this was perceived as a defect in the standard itself and a so called "tecnhical corrigendum" was issued in 2000 that fixes the error. Moreover, every compiler known so far stores vectors contiguously (and future ones are compelled to follow the corrigendum as well as the standard). So the moral is: contiguous vectors are a standard guarantee as of today, and every compiler implement them this way.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
corrigendum
Damn, had to look that one up.
Either...
1. I am stupid
2. Or in the US we use a different term. I guess I have always called them "errata"
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Standardese has its lingo, I guess. I find the word somewhat funny, too.
PS. If you allow me to go pedantic, for those of you with a leaning towards Latin, erratum (pl. errata) means "error", while corrigendum means something like "to be corrected" (pretty much the same, anyway.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Sort of like the words "feature" and "bug fix" in development.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Hi Joaquín,
Interesting. Maybe I'm too lazy, but how do you go about finding that kind of stuff out? What are your sources. We have ways of making you talk.
Nice,
Giles
Giles
|
|
|
|
|
You just follow discussions. Usenet newsgroups like comp.lang.c++.moderated and comp.std.c++ are two very good sources. C/C++ Users Journal also contains some info.
|
|
|
|
|
When run through the command line my program prints a usage message and then I type in the file name I want it to perform fopen call on. It then performs writes to this file.
When I click the icon I just get a quick flash on the screen. i tried checking the properties to see if I could change how the program is run but it will only let me view the general prperties.
|
|
|
|
|
Are you processing somehow the commandline parameters stored in argc and argv ?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Yes I am taking an infile.txt and compression it it outfile.txt. under Huffman compression.
It works fine when I run it from the ms-dos command line but not when I double click the icon. Any ideas would be much appreciated.
|
|
|
|
|
Klara wrote:
Yes I am taking an infile.txt
Aha! That's where the error is. You assume that infile.txt is in the current directory. You forget that when you run from windows the current directory need not always be the executable's directory.
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
Yes, when I run it from the command line I always have to type
cd C:\pathname\ and then type Myprog.exe
Then the path is chnged to where the exe file is and then I can run Myapp.exe. The program then should print a usage message and I type infile(it is in the same location as the exe file) and I type the name of outfile which is placed in the same folder.
Any ideas how to fix the icon problem?
Thanks for your input though.
|
|
|
|
|
Klara wrote:
Then the path is chnged to where the exe file is and then I can run Myapp.exe. The program then should print a usage message and I type infile
So, basically the first thing your program does is to display a message on the console. Then it reads the name of the infile followed by the name of the outfile. Is that what it does?
And what you say is that you don't even get the prompt to enter the file name, correct?
Could you please post the relevant code snippets upto this point in your code?
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
I don't get a prompt unless I runn it through the commandline, so at least I know the program works.
The main() routine supplied here has the job of checking for valid input and output files, opening them, and then calling the compression routine. It expects to find a compression routine in another module. If the files are not present, or no arguments are supplied, it prints out an error message, which includes the Usage string supplied by the compression module. All of the routines and strings needed by this routine are defined in the MAIN.H header file. I have included some explanations of the various modules further down.
I don't get a prompt unless I runn it through the commandline. This is part of my main program.
*/ This is the usage message
Usage:DOHUFF infile.txt outfile.txt
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bitio.h"
#include "errhand.h"
#include "main.h"
void usage_exit( char *prog_name );
void print_ratios( char *input, char *output );
long file_size( char *name );
int main( argc, argv )
int argc;
char *argv[];
{
BIT_FILE *output;
FILE *input;
setbuf( stdout, NULL );
if ( argc < 3 )
usage_exit( argv[ 0 ] );
input = fopen( argv[ 1 ], "rb" );
if ( input == NULL )
fatal_error( "Error opening %s for input\n", argv[ 1 ] );
output = OpenOutputBitFile( argv[ 2 ] );
if ( output == NULL )
fatal_error( "Error opening %s for output\n", argv[ 2 ] );
printf( "\nCompressing %s to %s\n", argv[ 1 ], argv[ 2 ] );
printf( "Using %s\n", CompressionName );
CompressFile( input, output, argc - 3, argv + 3 );
CloseOutputBitFile( output );
fclose( input );
print_ratios( argv[ 1 ], argv[ 2 ] );
return( 0 );
}
/*
* This routine just wants to print out the usage message that is
* called for when the program is run with no parameters. The first
* part of the Usage statement is supposed to be just the program
* name. argv[ 0 ] generally holds the fully qualified path name
* of the program being run.
*/
void usage_exit( prog_name )
char *prog_name;
{
char *short_name;
char *extension;
short_name = strrchr( prog_name, '\\' );
if ( short_name == NULL )
short_name = strrchr( prog_name, '/' );
if ( short_name == NULL )
short_name = strrchr( prog_name, ':' );
if ( short_name != NULL )
short_name++;
else
short_name = prog_name;
extension = strrchr( short_name, '.' );
if ( extension != NULL )
*extension = '\0';
printf( "\nUsage: %s %s\n", short_name, Usage );
exit( 0 );
}
|
|
|
|
|
What's happening is that since argc < 3, your program displays the usage message and exits.
Right click on the icon of the execuatble in explorer. You should get a properties tab window. Select the "Program" tab. There will be an edit box where you are supposed to enter the full command line. If you have any arguments you should append those arguments to the full path of the executable.
Eg:- C:\abc\myexe.exe file1.txt file2.txt /r:100
Regards,
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
Thanks for the help, I'm gonna try that out now.
|
|
|
|
|
Hey Nish,I'm still getting problems with this icon. When I right click on it I get the general properties only and nothing else. The check box is set to archive and there are no other tabs so I can't change the path name.
Any other ideas
|
|
|
|
|
Are you reading from a file, assuming it is in the same directory as the exe file? When you run it from windows the current directory might vary.
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|