|
I think I saw example of write on cd on codeproject did you search?
|
|
|
|
|
I am trying to open a file using fopen for append and switching its current position using fseek to modify its current contents.
oFile=fopen(strcat(f_SELF,"1.exe"), "a+b");
fseek(oFile,f_POS,SEEK_SET);
putw(0x00000000,oFile);
fclose(oFile);
When I use fwrite on the file it returns a C0000005 exception and with the current code the new file info is appended to the bottom of the file instead of overwritten in the middle. How do I write to were my pointer is set?
|
|
|
|
|
From MSDN:
When a file is opened with the "a" or "a+" access type, all write
operations occur at the end of the file. The file pointer can be
repositioned using fseek or rewind but is always moved back to the end of
the file before any write operation is carried out. Thus, existing data
cannot be overwritten.
When the "r+", "w+", or "a+" access type is specified, both reading and
writing are allowed (the file is said to be open for "update"). However,
when you switch between reading and writing, there must be an intervening
fflush, fsetpos, fseek, or rewind operation. The current position can be
specified for the fsetpos or fseek operation, if desired.
So instead of using append mode try to use r+ it is for both reading and writing.
Hope this helps.
-- modified at 0:31 Monday 18th December, 2006
|
|
|
|
|
Using w+ overwrites the previous file, so I get an x size file because the data between 0x00 to where where fseek is set is filled with 0's and whatever was in fputw is at the end. I need to reserve the previous contents too.
|
|
|
|
|
"r+"
Opens for both reading and writing. (The file must exist.)
"w+"
Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.
If your file already exists,try using r+
|
|
|
|
|
I have a functioning Microsoft Visual C++ (6.0) application that uses both MFC (Microsoft Foundation Class) and COM (Component Object Model). I am trying to turn this application to a simple Win32 Console Application by getting a rid of any reference to MFC. When it is done, I would like to just compile it and run it from a command line instead of GUI.
The site didn't allow me to attach a zip file (120k). If you can help, please e-mail me and I will send you the zip file.
Thank you
Mohamed.
My e-mail: mohamed.douffir@monotypeimaging.com
|
|
|
|
|
You could create a new Win32 Console project and then move your code into it incrementally.
This is the easiest way to have a project properly set up as a console app (it can be done
manually as well).
You'll have to remove all uses of MFC classes and any GUI-related Win32 API calls.
You'll have an entry point _tmain (which MFC's CWinApp class hides from you) that is called when
the CRT is done initalizing. This is your app's main thread so you'll need to call (non-MFC)
initialization code that's in your MFC application class' InitInstance() override, do whatever
your app does, and call cleanup code that's usually in your MFC application class' ExitInstance()
override, before returning from _tmain (exiting the app).
|
|
|
|
|
Mark Salsbery wrote: You'll have to remove all uses of MFC classes
This is not the case; I've seen console applications that use MFC classes, CString for example. You are correct in that most MFC classes are GUI related and will be of little use however.
Steve
|
|
|
|
|
Thanks Steve.
The OP stated "by getting a rid of any reference to MFC" so I answered accordingly.
CString and the database classes can be useful in a console app
Cheers!
|
|
|
|
|
Mark Salsbery wrote: The OP stated "by getting a rid of any reference to MFC" so I answered accordingly.
Fair call; I didn't notice that.
Steve
|
|
|
|
|
No problem. Without any feedback I wouldn't learn anything here, which is the whole reason I
hang out here
|
|
|
|
|
Thank you Mark and Stephen for your responses . I am still trying and I am getting no where. As of now, I have no knowledge in MFC world.
Ideally, this what I would like to achieve:
When I run the application from a command line (No GUI), the following calls will be executed:
void StartCANoe();
void LoadCfg(string filename);
void StartMeasurement();
void CallCAPLFunc();
void StopMeasurement();
void QuitCANoe();
In other word, I will perform one measurement per execution of the application.
If this is achieved, I know what I need to do next.
I would really appreciate if you one of you is willing to take a look. If you are, please send an e-mail to:
mohamed.douffir@monotypeimaging.com
and I will respond with the zip file ((120k). I wanted to attach the zip file but I don't think codeproject allows attachments. I could be wrong.
Thank you.
|
|
|
|
|
hi,
I want to display my CDialog in a specific position of the screen how can I do this ?
thank's
|
|
|
|
|
see CWnd::SetWindowPos on MSDN.
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.
|
|
|
|
|
|
hello, i have a problem when i try to load a bitmap to a CToolBar object.
i have a bitmap resource, and it is true color. I want to load it to my Toolbar object. but then, the buttons only display a full-black bitmap on them. When i change this bitmap on 16 colors, the buttons display them.
can anyone how to load a 24-bit bitmap on my toolbar?
this is the code:
m_dialogToolbar.Create(this);
m_dialogToolbar.LoadBitmapW(IDB_BITMAP4);
m_dialogToolbar.SetButtons(toolBarButtons,3);
m_dialogToolbar.SetSizes(CSize(rect.Width(),rect.Height()),CSize(16,15));
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
m_dialogToolbar.ShowWindow(SW_SHOW);
-- modified at 13:59 Sunday 17th December, 2006
|
|
|
|
|
Maybe try using an image list instead of the CToolBar::LoadBitmap(), something like:
CImageList m_dialogToolbarImageList;
...
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP4);
m_dialogToolbarImageList.Create(16, 15, ILC_COLOR24|ILC_MASK, 3, 1);
m_dialogToolbarImageList.Add(&bitmap, RGB(0x00,0xFF,0x00));
...
m_dialogToolbar.Create(this);
m_dialogToolbar.GetToolBarCtrl().SetImageList(&m_dialogToolbarImageList);
m_dialogToolbar.SetSizes(CSize(23,21), CSize(16,15));
m_dialogToolbar.SetButtons(toolBarButtons,3);
-- modified at 16:57 Sunday 17th December, 2006
*EDIT* Fixed constructor code
-- modified at 17:01 Sunday 17th December, 2006
|
|
|
|
|
It still doesn't work. I mean, the method works but the buttons keep displaying the bitmaps only in 16 colors My bitmap resource is truecolor.
at least now , even if the bmp is 24 bit, it shows it, but in 16 colors
-- modified at 16:01 Sunday 17th December, 2006
|
|
|
|
|
levelboy wrote: even if the bmp is 24 bit, it shows it, but in 16 colors
Sorry I didn't realize you actually wanted to see your 24 bit bitmaps in true color
Just kidding.
I fixed the code in my previous post (the imagelist construction code).
Mark
|
|
|
|
|
yeah thanks.
it works just fine now
thanks again
|
|
|
|
|
What is a handle? I see this alot in MFC. Is it some type of pointer or reference to an object or resource (like a window or button)?
Thanks,
BP
|
|
|
|
|
BlitzPackage wrote: What is a handle? I see this alot in MFC. Is it some type of pointer or reference to an object or resource (like a window or button)?
Not exactly a pointer but it in fact an identifier of, for instance, windows and files.
E.g. when you ask to the OS to create a window, it will return to you its HANDLE. Then, each time you will need to identify that window with the OS (for example to send a message to it), you will have to pass to the OS that returned handle.
However the handle is not a pointer to the window because the OS cannot return to you a pointer to memory which is relocable; giving you a handle, instead, introduces an indirection layer (a kind of table linking handles to memory addresses), warranting that the handle value will not change on memory relocation.
hope that helps.
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.
|
|
|
|
|
|
A handle is some opaque data structure used to represent some system resource. The term “opaque” means the user should not assume anything about the representation used and the actual representation used could change from OS version to OS version. A handle could be a pointer, an index into a table or something else but it doesn’t matter to the user as all access is via APIs.
Steve
|
|
|
|
|
Hi,I suggest you to read 《Programming for Microsoft Windows》by Jeffrey Richter,In the chapter 3 of the book,Jeffrey described the handle clearly.
|
|
|
|