|
UpdateWindow(); this function worked perfect, thanks.
|
|
|
|
|
Hi,
I am new to c++ and I will use it in my thesis on image processing.
I wrote a piece of code to read a ppm image file. in order to read the magic number (the number indicating the type of the image file whether it is ppm, bmp, jpeg or etc. this magic number is in the header section of the image) i create a char pointer magicNumber:
char *magicNumber;<br />
magicNumber = new char[2];
and pass it into the function PPMreadHeader. My intent is to fill the pointer inside the function and write the magicnumber in the console outside the function.
i have an array in the PPMreadHeader fuinction in order to read the file line by line. I have a local char pointer "word":
<br />
char line[255];<br />
char * word;
when i read the magicnumber (it is "P6" for ppm files) i assign it to the local pointer word:
word=line;
if i try to write the magic number in the function using the local pointer:
cout<<word<<endl;
there is no problem, it writes p6 to the console. however, if i first copy the word into the magicnumber pointer that i create in the main function:
*magicNumber=*word;<br />
*(magicNumber+1)=*(word+1);
and then try to print out the pointer to the consolelike below:
cout<<"magicNumber: "<<magicNumber<<endl;
then it writes:
magicNumber:P6ııııİİ
which not i want. it writes the p6 which is what i want to write to the console, but it writes more than p6. within the function when i write the local pointer "word" it just writes the P6, nothing more. Could you please help me on this.
You may advise other alternatives to write the magic number on to the console but even you do this, i still want to learn what is wrong with my coding. i spent a lot of time on this and i could not fix it.
Thank you in advance.
|
|
|
|
|
char* strings in C/C++ need to have a null character at the end. if you allocate 2 chars for a two-char string, there's no place for that null to go.
so, you should allocate 3 bytes for magicNumber, and set byte #3 to 0. then use a string copy function (like strcpy or even better, strncpy) to copy the strings from buffer to buffer; that will copy the null character along, too.
so, best of all, use a C++ string class, like std::string, to handle your strings. that will eliminate the need for buffer allocation, worrying about nulls, etc..
|
|
|
|
|
emrah.a wrote: char line[255];
char * word;
Modify it to ,
char line[255] = { 0 };
char * word = NULL ;
This should solve your problem.
|
|
|
|
|
Hi All,
I'm looking to team with someone who has written an HTML parser (or can write an HTML parser). My scanners\pasrsers are generally LALR (from my Compiler Theory days in college), which is a bit different from HTML.
The requirements are loose - I don't need a DOM. Something similar to below would work well (written in C\C++):
while( EOF != document )
{
Element = GetNextElement( document )
}
Element should look as follows:
struct _E
{
string element
vector<string> attributes
string value
} Element
I'm interested in the html 'primitives': < P > tag, < H# > tags, < TITLE >, < TABLE > (no need to break out the < TD >s and < TR >s. As I said, I am flexible. There is no need to return < HEAD > or < BODY > (hence the request for 'primitive' elements). To summarize, I want the 'leaves' of the tree (leaf nodes) - not the stuff encountered on the way down (branches). For proof of concept, attributes can be empty (they may be required later).
There is no need to convert between entity codes and characters. For example, does not need to be converted to it's corresponding white space (but it may in the future). Same with the C\C++ '\t' - character 0x09 can stay that way (for now).
Additionally, the co-author will be responsible for file rotation. Think of it as a log file for this purpose. Assume there will be at least 8 files to rotate (first in, first out). The data to be read and written will be a vector< string >:
vector< string >: ReadFile( Some sort of Time identifier )
void WriteFile( vector< string >: )
The algorithm does need to be deterministic (duh) - run on the same document, it must produce the same results each time.
So, the co-author should:
* create GetNextElement( )
* file I/O
* file rotation
* well document it - the byte scanner and tokenizer should take at least 3 pages. Aho, Sethi, and Ullman managed to produce 350 pages on this portion of a front end in Compilers - Principles, Techniques, and Tools[^].
I will:
* add the usage code of Element
* remaster screen shots in Photoshop
* coordinate the publication
I'm anal about article write ups. I toss out 5's for three sentence articles with a pretty Screen shot, but that is not what I expect of myself. Please see here[^] for my articles (so you can get a feel for what I expect).
I generally post to two sites: Code Project and Code Guru. It would be nice (but definetly not required) if the co-author had a Code Guru account.
Any takers? If more than one taker, I'll ask that you fight it out amongst yourselves, or take on an additional co-author. I' don't want to have to choose. I'm actually more concerned no one will step up to the plate, so don't be shy.
If successful, I want to move the Project to SourceForge. At that time the co-author can share in the Administrative responsibilities. The project will be called WebGrits. You'll understand later when the poetry is in motion.
BTW, my portion is complete It is another Crypto++ project based on hashing.
Jeff
|
|
|
|
|
Can any one show me how to double buff in a windows media player visualization using GDI. Just a very simple example of say drawing a circle will be fine. I just cant seem to get it to work following examples.
|
|
|
|
|
Hello,
I'm writing a MFC application and I need to run a complex C program. The C program gets data from a file and the write results in another file. The MFC program interacts with the user and display data and results graphically. I've the source code but also a dilemma. Can anybody tell me what is the best way to interact with the C code?
I think have three alternatives, 1) run the exe and work with pipe's, 2) put everything in extern C code or 3) create a simple c++ class that have all the C subroutines.
For the first alternative I think I will have problems if the program does not like my data, and that implies having to test all possible errors.
In the second, since the memory allocation is based in malloc, will I get memory leaks?.
The third alternative (I'm working on it right now) will get me all the benefits from c++ environment but is taking too long, since it implies that every subroutine is tested (and can only do that on the end), well linked (removing the parameters) and creating other class's.
I need to finish the program at the end of the month (year).
Any help appreciated.
Luis Bras
|
|
|
|
|
Luís Brás wrote: I think have three alternatives, 1) run the exe and work with pipe's, 2) put everything in extern C code or 3) create a simple c++ class that have all the C subroutines.
It sounds like the only difference between your MFC code and your C code is that the C code has
no user interface.
Any of your three methods will work.
If you need the C code to run in a separate process (exe) then you'll need to go with method 1.
Having to communicate with another process adds a level of complexity, obviously.
If it's ok to have the C code linked to your MFC app then method 2 or 3 will work. The code
could be in a DLL or compiled right into your MFC app.
If you are developing your C code from the start (it hasn't already been written) then method 3 is
probably the way to go. It shouldn't take any longer than any other method - you still have to
write the code and check for errors at runtime as needed, regardless of which method you use.
There's no problem mixing C code with C++. You do it all the time using MFC and/or the C runtime
(CRT). Calling malloc is fine. Remember to free memory when you're done with it
|
|
|
|
|
I need to send a enter key stroke how can I do that? That I need to do is send a enter key stroke to the dialog but I dont now how so please help me.
|
|
|
|
|
http://www.codeproject.com/cpp/sendkeys_cpp_Article.asp
modified 8-Mar-17 3:51am.
|
|
|
|
|
Hey all,
I'm facing a small dilemma...
I'm currently coding a dll which will be used in one of my projects.
As I go further and further with the development of my dll, it becomes clearer that a specific coded dll would serve
me better as opposed to a general coded dll, when it comes to both performence and coding issues.
By specific coded dll I mean that I write my dll to be used only with my current project.
If I'll ever want to use it in another project, I'll have to make changes.
What should I do?
Which is a better programming practice?
Not really sure where to post this question...
Maybe I'll post it in another forum as well.
Thanks in advance,
Shy.
|
|
|
|
|
shyagam wrote: By specific coded dll I mean that I write my dll to be used only with my current project.
Why a DLL then?
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers! We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP Linkify!|Fold With Us!
|
|
|
|
|
I have to inject it to every running process...
|
|
|
|
|
OK,
try to identify what is generic (reusable), and what is specific for your project.
If there is no generic (or a negligible) part, write a custom DLL.
Only if there is a suitably large generic part, write a generic DLL that handles it, and implement the specific part in a second DLL that is loaded by the first as plugin.
Maybe you want to explain some details of what the DLL is supposed to do, what you thought would be generic, and why it isn't.
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers! We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP Linkify!|Fold With Us!
|
|
|
|
|
Well... After a lot of trial and error in the journy to accomplish my goal I've decided that the dll would hook certain API functions.
I can't write something which would be generic because each API callback has a different signature...
|
|
|
|
|
There is a bmp resource in my project,IDB_BITMAP1.
I got a HBITMAP handle to the resource.
How could I save it into a *.png?? or other image format.
Thanks.
3.141592653... Never Stop
|
|
|
|
|
|
Hi everyone, i havent been on these message boards in a while and its good to be back. So the other day I ventured into the world of emulators and got a bit interested. I am not ready to program one yet, but was curios as to how one can go about a read a binary or rom file. What I need to do before taking on this project is to understand some things and I am hoping i get some advice and suggestions. First off, do I need to create a simple rom loader based on the rom file's structure, and if so does any one know any good references or books that deal with loaders using c++? All comments are welcome, thnkx!
|
|
|
|
|
Hi Asp .Net Programmer,
Write a Compiler for for a toyish Pascal like language. Grab only a few constructs - read memory location, write memory location, if/then constructs, and type declarations. The bad thing is the front end is tough unless you use lex, flex, bison, etc.
Define your instruction set: 0x01 = memory read, 0x02 = memory write, etc.
Generate your byte codes. At this point, you need an emuator to test your code generation.
It's not a smart ass answer. It's how a class on Compiler Therory would prpbably be taught (it is how the class I attended was taught).
Jeff
|
|
|
|
|
can someone tell me how they work? how does the scanning for invalid entries work?
|
|
|
|
|
Hello,
I have an MFC dialog application (VC++ 6 environment).
I've used the class wizard to create a handler for mouse movement
in my main frame window (to intercept ON_WM_MOUSEMOVE messages).
However, the handler is never invoked.
I can create a handler in the View (rather than main frame) and it is invoked. However, I want to capture all mouse movement, including mousing over the application's main menu area (outside of the view window).
Any help appreciated.
|
|
|
|
|
there is a cover (window) in front of main frame window, mouse movement is delivered to taht front window.
|
|
|
|
|
Can someone please show me, by code example, how to cause Windows Exployer to open on call in a program and to open a specific file.
Your code example would be deeply appreciated.
A C++ programming language novice, but striving to learn
|
|
|
|
|
FYI some C# code that opens an explorer window and highlights the
file specified by string fileSpec:
Process proc=new Process();
proc.StartInfo.FileName="Explorer.exe";
proc.StartInfo.Arguments="/n,/select,"+fileSpec;
proc.StartInfo.CreateNoWindow=true;
proc.StartInfo.UseShellExecute=false;
proc.Start();
and some C# code that opens a file as if you double-clicked it on the Windows desktop:
Process proc=new Process();
proc.StartInfo.FileName=fileSpec;
proc.StartInfo.Arguments=null;
proc.StartInfo.CreateNoWindow=true;
proc.StartInfo.UseShellExecute=false;
proc.Start();
I know it is C#, not C++, but under .NET it is basically the same.
Luc Pattyn
|
|
|
|
|
I know nothing about c#; and as you may have gathered, I know very little about c++. I am learning!
I need real, working c++ code to understand what to do.
Please try to understand, I am a novice to c++, but I desparately wan to learn how to do things CORRECTLY!
I have no idea if c++ has a "key word" or "token" named "Process".
Thanks anyway,
Larry A Mills Sr
A C++ programming language novice, but striving to learn
|
|
|
|
|