|
ritz1234 wrote: The program to open the file depends on its extension that is registered
with OS. OS uses that extension to open an application for that file.
I'm well aware of this.
ritz1234 wrote: Right now I am not going anywhere, and waiting for your reply.
I tried your code snippet and it worked as expected. The only change I made was to the messages, like:
if (! res)
{
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
AfxMessageBox(szError);
}
else
AfxMessageBox("The file was opened successfully."); Are you opening SerialNumbers.txt with Notepad?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Hi Guys, I have a program that consumes a lot of memory. First of all it dynamically creates an array of char and reads a binary file, as shown below:
---------------
char * memblock; //Pointer to Char array used to read binary file
char unsigned * memcopyblock; //Pointer to char unsigned array used to create int array
ifstream file (fileName, ios::in|ios::binary|ios::ate);
count = file.tellg();
memblock = new char [count];
file.seekg (0, ios::beg); //Set the postion of the pointer to the start of the file
file.read (memblock, count); //Read the 2 minute log file
file.close(); //Close the log file
----------------
it then converts all the 'chars' into 'char unsigned'.
-------------------------------------
memcopyblock = new char unsigned [count];
for (int i=0;i<=count;i++)
memcopyblock[i] = memblock[i]; //copy
delete []memblock;
---------------------------------------------
However, this approach uses twice as much memory as the size of the binary file. Is it possible to read a binary file into a dynamic array of 'char unsigned' or to use a dynamic memory map (i.e. union stucture) to half the amount of memory used by this program?
Cheers,
Aubs
|
|
|
|
|
Member 3363498 wrote: Is it possible to read a binary file into a dynamic array of 'char unsigned'...
What makes you think it would not work?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
If I change modify memblock from:
char * memblock;
memblock = new char[count];
to
char unsigned * memblock;
memblock = new unsigned char[count];
I get the compilation error:
Error 315 error C2664: 'std::basic_istream<_Elem,_Traits>::read' : cannot convert parameter 1 from 'unsigned char *' to 'char *' e:\projects\global\readbinary.cpp 16
against the line:
file.read(memblock, count);
Is there a simpler efficient way of reading a binary file into a dynamic 'char unsigned' array?
|
|
|
|
|
Yes, it is:
file.read((char*) memblock, count);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I have an app written in CodeGear C++ Builder 2007 which uses a COM port. If I run this app on an XP-system (my laptop) and I set the programm to use COM6 (USB->Serial) the app works fine. If I copy the app to a XPe environment (without C++) I get system error 2 (FILE NOT FOUND) if I try to create the COM connection (with FileCreate).
Is there a difference in the naming of the ports in XP and XPe, and if so, what do I have to do to solve this?
When I run the programm from the Programming environment, it creates an exe file. I copy the exe and all the files/directories in this directory to the XPe environment, and until now it didn't cause any problem, but maybe I have to it in an other way?
|
|
|
|
|
XPe ? XP Embedded ?
Did you check that the COM port is the same on the other machine ? If you use a USB to serial, the port number might change from PC to PC.
What is the complete string that you are using to open the com port ?
|
|
|
|
|
XPe = XP embedded.
It is not the same COM port (On laptop with USB to Serial on COM 6; On XPe system on COM2) I've changed that before moving the app.
<br />
char portName[] = "COM6";<br />
hComm = CreateFile (portName,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);<br />
|
|
|
|
|
I didn't use XP embedded before but I used winCE (but there, the binaries are different so you need to compile your code specifically for winCE).
As far as I remember, you have to specify the port name this way on WinCE:
char portName[] = "\\\\.\\COM6";
If that doesn't work, check also with a colon at the end:
char portName[] = "COM6:";
|
|
|
|
|
Cedric Moonen wrote: char portName[] = "\\\\.\\COM6";
did it, but now I am doubting myself... I believe I've tested this solution but I'm not sure anymore.
Anyway... thanks
Frank Peeters
|
|
|
|
|
Cedric Moonen wrote: As far as I remember, you have to specify the port name this way on WinCE:
char portName[] = "\\\\.\\COM6";
I thought this format was required only for COM ports 10 and higher.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm writing a SDI windows win32 .exe program using Visual C++ 6.0. If in the future I want the program to run on PCs other than with the Windows Operating system, is there anything I should incorporate into the code now, or is it compatible with most other operating systems already, or does it need to be rewritten?
Thanks!
|
|
|
|
|
I've not used it myself, but if you're using fairly plain win32 code (ie, not wacky libraries), then you may be able to use WINE to run your program on linux (or maybe most unices).
You may also want to look at some llibraries like Qt (off the top of my head) which are on most systems, so you'd just need to recompile for a different OS.
If your program does clever algorithmic things, you could make that part OS independent, and write OS dependent front ends...
Lots of choices!
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
Visual C++, MFC, Win32, etc., are from Microsoft and they are specific to develop software for Microsoft Windows.
If you need tools to write a cross platform program, have a look at the following URLs:
Visual Component Framework[^]
Cross Platform Programming[^]
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
You won't be able to do that. MFC is for windows only. Anyway, even if your code was 100% system independant, you still would need to recompile it for a different platform (the binaries are totally different).
If you want to make something portable, you will need to make your code portable, you will need to get rid of every call to the win32 API (and get rid of MFC, completely). However, don't panic, there is a cross-platform alternative to MFC: wxWidgets[^]. If you have experience with MFC, it shouldn't be too difficult to switch because it is more or less similar (in usage I mean).
Good luck, it is probably more complicated than you think...
|
|
|
|
|
Java ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
better look for library like WxWidget and QT for this, MFC is specific for windows.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
|
|
Naively: because a (raw) pointer is not an object.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: Naively: because a (raw) pointer is not an object
what is original question??
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
He was asking while relational operators cannot be overloaded for pointers.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I dont know why you delete your question?
|
|
|
|
|
indian trade secrets?
|
|
|
|