|
Jay2 wrote:
I'm trying to use strcmp to compare 2 char* pointing to buffers the code is this...
Not sure that this will fix things, however you need to check your declaration of your two character pointers. It should look something like this( you have char* b,b2; ):
char *b, *2;
Jay2 wrote:
Also what is a volatile pointer
Here is a link to save space. Data Type Qualifiers[^]
Hope this helps.
Nick Parker
May your glass be ever full.
May the roof over your head be always strong.
And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing
|
|
|
|
|
Wow, you really have to work on formatting your code a little bit.
Your casts are odd as well and you'll have problems because strcmp expects strings to be NULL (0) terminated, you are better off using strncmp so you can set a max comparison size (in your case 100.) Also, what happens if fread reads less than 100 bytes or past the end of a either file? MSDN states "The file-pointer position is indeterminate if an error occurs. The value of a partially read item cannot be determined."
If you malloc you better free ! You allocate memory, but then you do a return without ever freeing the memory, you also return without ever _close ing the file handles (or is this done somewhere else?)
Do you really need to use a void pointer? Take a look at the following example on MSDN: fread()[^]
If you just use a buffer of char, you should be on your way.
You should also check for end of files (using feof ), and read errors (fread returning 0). Error handling is extremely important, and should never never never ever be omitted for production code (ever.) For illustrative purposes, many people do omit error handling, usually with a caveat that they've done so, or that the lack thereof is implied
Hopefully this will help you on your way.
|
|
|
|
|
Hi, I know the casts are odd! I couldnt think of any other way of thinking about it... not sure even if it is the correct cast but as a char* and void* are stored in memory (I think) the same way then I decided it would be possible.
I have to use a void* for fread to read from the file into the buffer which is void*, I think your strncmp looks like what i need to use but will this still assume there is a NULL character to terminate the string?
Incase that doesnt work maybe i can use sprintf to write from the buffer into a string, but i never like doing that kind of thing as i'm not really a fan of sprintf, and as the buffer is in binary i'm not even sure if it will work fully, is there no way of comparing 2 buffers or arreas of allocated memory, how about taking one from the other and seeing if the result is zero as this would save me a lot of messing around!
Ok thanks the code i showed you was only a small section of the program and i have closed the files, but not free'd the allocate memory yet.
Oh is that link the one used in msdn v6.0 i know as thats the version i have it's old but thats all i have, and when i click the link i dont get anything at all!
Thanks i'll have a play around with msdn.. - Jason
|
|
|
|
|
strncmp doesn't require a NULL terminator. fread will accept char pointers for the buffer as well.
|
|
|
|
|
sorry to spam your email like this... i think fscanf is the thing to use.;P
|
|
|
|
|
Why do you need to do things this way ? Are you using C rather than C++ ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Hi no i'm not using c, using c++ but for console applications, i'm comparing 2 different system files (actually i'm backing up windows installing some bits and pieces then comparing the new files with the backed up copies).
|
|
|
|
|
If you're using C++, you should use C++. Use new and delete instead of malloc and free, iostreams instead of fread. You'll find that the iostreams in particular greatly simplify what you're trying to do, and your code will be a lot nicer to read, also.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Each pop-up menu item has an arrow on the right, even when we override the menu item to be ownerdrawn. Windows seems to pull drawing for the right pointing triangle outside drawing context for pop-up menu items Does anybody know how to override this windows restriction and yet draw the triangle ourselves
Regards,
Vitaly
P.S. None of the articles about menus on this website has such feature as i could see.
|
|
|
|
|
Hi guys,
I'm developing an app and having a complete nightmare trying to support Windows 98! It runs solid like a rock on Windows 2000 and Xp, but with 98 it just crashes in the oddest of places. One of these is inside the AlphaBlend() function, which is a new function included in the November 2001 Platform Sdk. It is supposed to work under 98 no problem.
The AlphaBlend() code crashes inside msimg32.dll, and I read somewhere that you must not package this dll with your product... I am currently not doing this, but wonder if perhaps I should anyway ?
Does anyone have any ideas what could be going wrong? I'm debating just adding fine print saying something like "Run on Windows 98 at your own risk"
swinefeaster
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
Thanks! It's good to know the version numbers... Perhaps I'll combine that with Christian's code and together it might just be a fix .
Cheers,
swine
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
Alphablend is known to leak memory, I wrote a replacement, it's availble on the wdj site, sorry I forget when but if you search for my surname, it's the only article of mine that was the feature article ( so the text is online as well as the code ).
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Thanks very much Christian! I found it . I'm going to try it out and see what I can come up with. Hopefully that will solve most of my problems... Just a few more questions, please...
1. Does AlphaBlend() leak memory on Windows 2000 and Xp as well, or just Windows 98 or Me? (I don't get any crashes on 2000/Xp)
2. I found your article at:
http://www.windevnet.com/documents/s=7628/wdj0109b/
It says "If you download this month’s source code from the WDJ website, you will find an example project, which illustrates the use of these functions and also shows you the steps taken by TransparentBltU(), as shown also in the examples here."
...but unfortunately it which month nor where I can get this example code. Where is that stuff?
Again thanks a lot.
swine
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
I've used your code for the Windows 98 implementation, and it fixed the bug! Thanks .
swine
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
Hi,
I am a student who doing a project useing MFC. I had creade a single document project. But forget to fill the Document Template Strings, such as the filter name and file extension.
Now I can save and load fuiles but they have not an extension. And when clicks Open, all types of fill is shown.
Can any one tell me whether there is a method can add these functions to a project?
Thanks,
Tom
|
|
|
|
|
I believe these values are all in the string table.
Easiest way to deal with these sort of problems is to create another empty project, set the values to something that is unique and then search the files for it. simmilarly, if you want to change an option you set in the wizard, generate two empty projects of the same name, and make that option the only difference between the two, then run windiff over the directories.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
It is in the project's string table. The identifier of the string is IDR_MAINFRAME. Probably the easiest way to get a proper string is to generate a new project, and enter the strings properly. Then, open the string table of the new project and copy IDR_MAINFRAME from that string table to your new string table.
Chris Richardson
|
|
|
|
|
Thanks for the answer,
but it does not work. When 'open' or 'save as', all files are shown. Are there any other things beside the IDR_MAINFRAME need to be modified?
|
|
|
|
|
It is actuall stored in the string table, but in the document ID string. When you registered your DocTemplate in InitInstance, it had an ID of ID_MYDOCTYPE or some such. Look up the string for ths in the string table. It should have a format of somthing like:
"\nRefinementPro\nRefinementPro\n\n\nRefinementPro.Document\nRefinementPro Document"
I forget exactly which position int the \n delimited list you need to put *.ext for your extension.
Roger Allen
Sonork 100.10016
I have a terminal disease. Its called life!
|
|
|
|
|
Hi.
I am implementing an overlapped I/O based Winsock program. I would like to know how to format the data buffer after WSARecv returns. For example:
-----
// Allocate 100 bytes.
TCHAR *data = new data[100 + 1];
data[100] = NULL;
// Link data buffer and size to WSABUF.
WSABUF wBuf;
wBuf.len = 10000;
wBuf.buf = data;
...
WSARecv(..., &wBuf,...,);
...
-----
Given WSARecv returns after sometime with the data, how do you format, 20 bytes of valid data. In other words, data could contain 100 bytes of data, however, what if only 20 bytes are valid and the rest are random data Winsock produces from the socket?
I tried using CString and trim(), but it does not seem to help under an overlapped I/O. For example:
-----
WSARecv(...);
...
CString validData = CString(data);
validData.trim();
-----
The solution above does not work for overlapped I/O. Even with trim(), validData will hold some valid data and a whole lot of random bytes.
I would like to know how to format a raw byte data buffer into valid characters only.
Thanks,
Kuphryn
|
|
|
|
|
The data you send must contain some information indicating which bytes are valid data, e.g. a byte count in the beginning of the packet.
|
|
|
|
|
You should memset(data, 0, sizeof(data)) the buffer before you begin the read, that way it's formatted so that even if you read less than the buffer size, your string will still be NULL terminated, and when you do your magic CString(data), it'll work out better. It's always a good idea to zero out the memory of any character buffer for this reason (and many more.)
Your buffer size is 100 when you allocate it, but not when you link it to WSABUF, was that a typo?
|
|
|
|
|
Interesting. Thanks.
What does memset() do?
For example, given a data buffer of size 100, what will memset() do to the allocated memory? I do not want to deallocate 100 bytes; however, memset() would be of great use of all it does it clear the memory buffer of old data.
What is the difference between memset() and ZeroMemory()?
Kuphryn
|
|
|
|
|
memset fills a buffer of a certain size with a value, in your case, you'd use 0 (zero.):
char szBuf[101];
memset(szBuf, 0, sizeof(szBuf));
ZeroMemory is just the same thing, just a macro (shorthand definition):
#define ZeroMemory(p, s) memset((p), 0, (s))
Or something like that. When you compile, all the ZeroMemory()*s will get expanded to memsets.
|
|
|
|
|
|