Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem could also be one of Endianness. The byte order on windows and *nix computers are reversed. Maybe your os is writing the bytes out in reverse order during the copy process. To test that use your system's command-line copy function to make the copy, FTP to Windows and check it with MS-Word.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There's a time to smile, and a time to frown. I try to smile all the time while at work as a WalMart cashier and often wear a happy-face sticker on each shirt lapel. I haven't been punched in the face yet for smiling :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

if I ftp any work doc in binary format or asicc format and view the resulting file they are all fine. ftping the copied file that my binary creates does not work fine. So not too sure it's an ftp issue.

What o/s are you using to copy file?

I am using Microsoft Vista Home Premium and VC++ 2008 Express compiler. No FPT involved. Are you using the code I posted or something you wrote ?

Where did the input.doc file come from that you posted? Was it also FTPd to Windows machine before you posted it here? Or did you post it directly from a browser running on Solaris os ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh, I just saw the attachments. Downloaded input.doc and my program copied it correctly, as expected. The output.doc file you attached is unreadable for me too, so the problem is either in the ftp or the solaris operating system. My guess is the ftp program is corrupting the output file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There might be ftp problem. And I don't know what will happen if you try to copy MS-World doc file on your solaris operating system.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The microsoft word doc is copied successfully - byte per byte. Copied file is same size as original. However, when I try and use microsoft word to open the copied file, the copied file contents which have non-ascii text are not readable. The ascii text is readable. So the copied file is worthless to the end user if he/she cannot see the non-ascii parts. So I want to be able to copy the file AND open it and read it successfully using ms-word.

Zip up the file you are trying to copy and post it so that I can test it. The doc file I tested is readable by MS-Word as expected, and it contains quite a bit of graphics and charts, so there is no reason that program does not work with any document.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>If you need other pieces of the code I'll post them here...

Please don't. Post all your technical questions in one of the language boards. I would move this to the right place if I knew what computer language that code was written in.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

How would I use new and delete?

you are kidding aren't you? You mean you don't know diddley-squat about c++ yet you are attempting to write a windows program :icon_eek:

if(hFile != INVALID_HANDLE_VALUE)
    {
        DWORD dwTextLength;

        dwTextLength = GetWindowTextLength(hEdit);
        // No need to bother if there's no text.
        if(dwTextLength > 0)
        {
            char* pszText;
            DWORD dwBufferSize = dwTextLength + 1;

            try
            {
                pszText = new char[dwBufferSize];
                if(GetWindowText(hEdit,pszText, dwBufferSize))
                {
                    DWORD dwWritten;

                    if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL))
                        bSuccess = TRUE;
                }
                delete[] pszText;
            }
            catch(...)
            {
                // allocation failed
            }
    }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I compiled the *.cpp file with VC++ 2008 Express and got some errors

1>c:\dvlp\wintest\wintest\wintest.cpp(23) : error C2440: '=' : cannot convert from 'HGLOBAL' to 'LPSTR'
1> Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>c:\dvlp\wintest\wintest\wintest.cpp(61) : error C2664: 'SendMessageA' : cannot convert parameter 1 from 'int' to 'HWND'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\dvlp\wintest\wintest\wintest.cpp(64) : error C2664: 'SendMessageA' : cannot convert parameter 1 from 'int' to 'HWND'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://c:\dvlp\wintest\wintest\Debug\BuildLog.htm"
1>wintest - 3 error(s), 0 warning(s)

As for the first error: GlobalAlloc() returns a HGLOBAL object, not a char*. And GlobalAlloc() is just an unnecessary complication, just use standard c++ dynamic memory allocation, such as new and delete[].

The first argument to SendMessage() must be a window handle HWIND, not a macro from the resource.h file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>which really works out to about 2Gig because Dev Studio

What is Dev Studio? You mean Dev-C++? In any event it has nothing to do with the problem and does not affect the amount of memory a program can use, unless the computer has less than 2 Gig of RAM and is out of hard drive swap space.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know how to enable 64-bit. From what I see in the link I posted, and read in other places, its enabled during installation of the compiler. There is apparently an installation option that lets you install the 64-bit compiler. You may have to reinstall the compiler in order to get it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just tested a short program and it stopped at about 2Gig just as you had also reported. I believe the reason is a 32-bit program can only access 2 Gig RAM.

To get the 64-bit version of VC++ 2008 you have to select an option during installation. Here is how to do it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Visual Studio 2008, which I assume is a 64 bit compiler.
No -- its a 32-bit compiler. But the Pro version can compile 64-bit code if you provide the right options. Just because you compile something on a 64-bit os doesn't mean you will automatically get a 64-bit program.

Post a short example program that produces the problem you are talking about.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

On an unrelated note: is there some minimum amount of time that has to pass before thread subscription will "instantly notify" me? For example (and this happens a lot) I posted a question, you answered and I received an email about this answer. Then I replied. Then you replied, and I didn't receive an email - am I misinterpreting the expected behavior?

Thanks,

Dave

I don't know because I don't use that feature. Please post your question in DaniWeb Community Feedback.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It's part of the new "c++0x standard" called "delegated constructors".

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1986.pdf

I didn't see in that document where int x = 5; would be a legal construct. As far as I can tell that document is talking about class constructors, not variable initialization outside the constructor.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

c++ does not allow initialization of variables like that. No c++ compiler on earth will do it. What you might be referring to is const int x = 5; , which is allowed but not implemented by all compilers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

II have written code that can successfully read and write a microsoft word doc - that is if the word doc contains plain text only

That isn't a microsoft word doc, but a normal text file.

. If there are any headings and different fonts used, these are not copied successfully. Which brings me back to my original question - when copying word docs does one need to manipulate the non-ascii chars? And how is this done?

See the code I already posted and which you quoted. If all you want to do is copy the file then the answer to your question is NO.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>The great thing about this project is that there isn't anything that has to do with MS-Excel at all in the spreadsheets I'm working with.

You are not working with xls files as you initially stated, but comma separated csv file. The first line contains cell titles while the remaing lines contain the data.

use getline() to read each line, ignoring the first line read. After that use getline() in conjunction with stingstream to extract second colum, Something like this:

string line;
ifstream in("fiulename.csv");
getline(in, line); // ignore cell titles
while( getline(in, line) )
{
    float n;
    stringstream str(line);
    while( getline( str, line, ',') )
    {
        n = atof( line.c_str());

       // instead of atof() you could also convert string to float
       // using another stringstream object, like this:
       stringstream str1(line);
       str1 >> n;
       // now do thatever you want with this cell value
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Should work as long as you are logged into MS-Windows with administrative privileges. If not, then the os may prevent you from writing into c:\\ root directory. Try writing that file to another directory that you know is writable.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its almost impossible to read .xls files directly because they contain proprietary MS-Excel data. But if you really really really have to do it then read this document

The simpler solution is to convert the xls files to cvs files using MS-Excell program. The csv files do not contain all that binary data and reading is straight forward.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

put an else between the first two if statements, like you did between the last two statements.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why is contiguous memory even an issue here? Once the array is allocated it doesn't really matter.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

fstream auto closes the file when the function is finished, and that's why I didn't do it in main(). But you have to call close() if you wanted to delete the file in the same function that opened it.

Nick Evan commented: Did not know that :) +20
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its not necessary to test for file existance beforehand. Just open like this: ios::in | ios::out | ios::ate . This will append text to the end of the file every time the program is run.

int main(int argc, char* argv[])
{
    fstream out("HelloWorld.txt", ios::in | ios::out | ios::ate );
    if( out.is_open() )
    {
        out << "Hello World\n";
    }
    else
        cout << "Failed\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post #3 presents a 1d array as if it were a 2d array. Thats a good way to do it, unless of course the requirement is to create a 2d array.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I agree we need an MS-Windows programming forum because there are lots of win32 api questions. But in all the time I have been here I don't recall ever having a mobile device question, although I might have missed it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what compiler and version are you using?

Microsoft has a Scribble Tutorial that's an introduction to MFC.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 11 of that code snippet is wrong. It should be delete[], not delete.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

dont rlly know...told ya i am noob in this thing

You will have to get that library before you can attempt to compile the program you posted. google for it and see if that will find it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hey AD, in your post (#3) you forgot a bracket on this line: while( fin.read( iobuffer, sizeof(iobuffer) ) :P

Nobody is perfect :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When I actually tried it I had the same problem. I used a command prompt and found out that the two files were just a few bytes different.

well, the code I posted almost works. The problem is that the last few bytes does not get read/written

int main(int argc, char* argv[])
{
    char iobuf[255];
    size_t total = 0;
    size_t sz = 0;
    ifstream fin("file1.doc", ios::binary);
    if( !fin.is_open() )
    {
        cout << "Can't open the file\n";
        return 1;
    }
    ofstream fout( "copy.doc", ios::binary);
    while( fin.read(iobuf, sizeof(iobuf) ))
    {
        sz = fin.gcount();
        total += sz;
        fout.write(iobuf, sz);
        sz = 0;
    }
    sz = fin.gcount();
    if( sz > 0)
    {
        cout << "sz = " << sz << "\n";
        total += sz;
        fout.write(iobuf, sz);
    }
    fin.close();
    fout.close();
    cout << "Total = " << total << "\n";
	return 0;
}
tux4life commented: Good code :) +11
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I missed this reply - sorry. I am treating the microsoft word doc in the C++ code as a binary doc and using fstreams to read/write the data. Then when I use microsoft word to open the newly copied file, the contents are not readable.
Is it possible to just read the contents of the microsoft doc file in binary form, write and open without doing any formatting of special chars?

That is exactly what the code snipped I posted will do. Its just standard file i/o operation, nothing special about it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Does one need to use microsoft apis to ensure that non-ascii chars are converted?

Huh? I didn't post anything specific to microsoft, only standard C++ stuff. Binary files have to be opened in binary mode using ios::binary option. If you don't do that then the destination file will be corrupt.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>When I try to open the newly created file, the contents are not readable
Its because doc files are binary files, not text files. Those files contain a lot of formatting information, such as font, font color, font size, etc, that is only readable by MS-Word or similar compatible program.

Binary files have to be opened in binary mode ifstream fin(file, ios::binary); and use stream's read() method.

ifstream fin(file, ios::binary);
ofstream out("newfile.doc", ios::binary);
char iobuffer[255];
while( fin.read( iobuffer, sizeof(iobuffer) )
{
    // do something with this block of data
    size_t sz = fin.gcount();
    out.write( iobuffer, sz);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I downloaded that zip file and tried to compile it with VC++ 2008 Express but some errors on bncsutil library (its not on my computer). Where do I get it ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

he told me to post the whole program so he can try to compile it...welll the whole programe has 18MB

Go back and re-read my post. I said to delete all compiler-generated files.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

zip up the entire project and attach it to your post so that we can try to compile/link it ourselves. Please delete all compiler-generated files, such as *.obj and *.ncb to that the zip file is smaller.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

search www.codeproject.com because I've seen several articles about that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There is a message in that compile.txt file that states it must be compiled with VC++ 2008 (probably express edition will be ok).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

VC++ 2008 -- Express edition is free. Although C# is good too.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think you want to add your own Avatar. In the yellow bar at the top of any DaniWeb window, cluck "Contro Panel" link. In the left side of the screen you see "Edit Avatar". You can use either one of the canned DaniWeb avatars or load your own from your hard drive.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Debug -> Start Debugging

Or just press F5

either way works.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I m surprised and wanna know that how the compiler understand the sequence of how data was entered. as i didnt use any space any tab not a new line, how it can point to the original value from a
single line..?????????

The compiler has no clue how to interpret those digits. The only way it will work is if you write a space, tab, or some other character that acts as a separator.

It only appears to work -- that read loop didn't actually do anything because there was probably an integer overflow error on the first read. What you saw on the screen was the old data left in the array after keyboard input.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>vec_enc_data.push_back(enc_data);
I think the problem is that enc_data is the same for every row in the vec_enc_data vector. What you probably need to do is allocate a new array for each row

uint8_t* ts_checksum;

...
ts_checksum = new uint8_t[32];
getHash(sencdata,enc_data);
...
vec_enc_data.push_back(enc_data);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just created a new Windows Forms project, and Form1.h is 66 lines, including blank lines. There is no Form1.cpp file, but there is a <project name>.cpp that contains main() with a few lines of startup code.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Just a guess, but if you are trying to read the contents of a structure perhaps there are holes in the structure, such as the packing factor is something other than 1.

#pragma pack(1)
struct mystuff
{
   WORD a;
    DWORD b;
   // etc
};
#pragma pack()
Intrade commented: Expert analysis +1
Salem commented: *nods* +35
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

in my f..king third world home, we have a mandatory military attendance which i havent done yet.

Well, what's stopping you? Go get it overwith, military will make a man out of you. We had that too when I was your age, and I stayed for 23 years :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can find all the unicode version of standard functions by googling for the function then selecting the MS-Windows version in the google links.

For programs I'm going to use just for myself I always turn UNICODE off so that I don't have to bother with the macros. You should do the same for code you are writing for university classes unless your professor tells you otherwise he/she wants UNICODE ready code.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>what amount of time as a software developer are we supposed to spend being with computer?

24/7 :)

If you are in school and trying to work full-time too then your love like will suffer greatly. Take small vacations away from work frequently to help avoid burnout. And don't forget to go home at least once a year to visit family.

tux4life commented: Is that with Christmas then :P ? +9
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can not just typecase from char* to wchar_t*. You have to call one of the transformation functions.

This works ok for me when the program is not compiled for UNICODE

#include <iostream>
#include <cstring>
using namespace std;

int main()
{
char S1[] = "C:\\Program Files" ;
char S2[]= "Zebra";
strcpy(S1,S2);
cout << S1 << "\n";
}

And the UNICODE version

#include <iostream>
#include <tchar.h>
using namespace std;
#ifdef _UNICODE
#define COUT wcout
#else
#define COUT cout
#endif
int main()
{
    TCHAR S1[] = _TEXT("C:\\Program Files") ;
    TCHAR S2[]= _TEXT("Zebra");
    _tcscpy(S1,S2);
    COUT << S1 << _TEXT("\n");
}

With the above code you can compile the program with our without UNICODE and the compiler will make appropriate conversions for you.

If you are not really interested in UNICODE then just turn it off and code normally as in my first code snippet. To turn it off select menu item Project --> Properties --> Configuration Properties --> General. Then on the right side of the screen change the "Character Set" list box to "Not Set".

Creator07 commented: Thanks for the quick help +1