|
|
I need to read from the file a list of persons(person it is a struct that I defined)in unknown size , but I success to read only the first person.
then my loop being infinite.Why ??? What can I do ???
_______MY CODE___________________________________________
void CRegWinDlg::read_persons(CFile* persons)
{
person* q = new person;
if file.Read(q, sizeof(person)))
{
q->next = q->back = NULL;
p_head = p_tail = q;
}
else
{
MessageBox("Have not register of users ! ");
delete q;
return;
}
//---------------------------------- Until here it is working excellent !!!
file.Seek(sizeof(person), CFile::current);
while(file.GetPosition() != CFile::end )
{
p_person q = new person;
if(file.Read(q, sizeof(person)))
{
q->next = NULL;
q->back = p_tail;
p_tail->next = q;
p_tail = q;
}
else
delete q;
file.Seek(sizeof(person), CFile::current);
}
}
|
|
|
|
|
|
Geez, it was only like 40 minutes. Anyway, why are you calling Seek()? The file pointer automatically gets advanced when you read from the file.
|
|
|
|
|
I dont think you need to call Seek since Read advances the position. Also CFile::end, cannot be used to determine the end of the file... it is used for seeking from the end of the file.
You could try something like this;
...<br />
DWORD dwRead = 1;<br />
<br />
while ( dwRead > 0 ) {<br />
<br />
p_person q = new person; <br />
<br />
if ( 0 != ( dwRead = file.Read ( q, sizeof ( person ) ) ) ) {<br />
<br />
q->next = NULL;<br />
q->back = p_tail;<br />
p_tail->next = q;<br />
p_tail = q;<br />
<br />
}<br />
else {<br />
<br />
delete q;<br />
<br />
}<br />
<br />
}<br />
...
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Hello All,
I have my App as a SDI, With the CFormView as the base class of the view class. the problem is this,
when maximize the Main App window (to fill the screen) the Form doesn't get resized to fill the App main window, but it stays at its original size and location.
I was wondering if there is a way to get the view form (dialog) gets resized to fill the App main window when I maximize the App window, and to Get it to be resized to fill the App window if I resized the App.
Basically I want the View Form to occupy the App Main window at all times.
Thanks in advance.
Fady.
|
|
|
|
|
I need to be able to build my project with different IDR_MAINFRAME icons.
is this possible? given that VC will rewrite resource.h and myapp.rc, there's no chance of putting and #ifdefs in there.
anyone ever do this?
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Each resource (dialog, icon, menu, etc) has the 'Condition' field in its property sheets accessed directly from the Resource View. It can contain the preprocessor symbol - the resource will be included only if the symbol is #defined. This gives you the chance to conditionally change the resource contents.
Unfortunately, VC IDE has apparently some bug here. Sometimes your resource condition changes from SYMBOL to "SYMBOL" - the quotes appear automagically and destroy your carefully crafted solution.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Hi All !
Please help who is able to
I am creating a component that will provide information to several different client applications. Some of these applications have higher priority than others, and the component must prioritize requests for information.
I'd like to develop this component as COM server component that accepts a reference to a notification object(with Priority property) from each And use asynchronous callbacks to pass information back to the client applications in order of priority
Well, what type of COM server I should rather use ?
Thanks.
|
|
|
|
|
Does your server need to be in-proc?
Is there an interprocess communication between clients through the server?
Do you need to have one server per all clients? i.e. singleton?
If your sever is a singleton, then I guess you should make it out-of-proc
Good luck!
Mh2!
|
|
|
|
|
Hi, I have 2 processes that communicate through a mailslot. The mailslot is created using CreateFile and data is being sent using WriteFile. The mailslot performs well for some time before it crashes. I notice that every WriteFile function returns Error 59 ("ERROR_UNEXP_NET_ERR") .
I never send more that 1.4 kb of data and mailslot is created between 2 processes in the same computer (max data transfer is 64 kb). Any idea anyone .... Any help is greatly appreciated....
|
|
|
|
|
I have created a button control that has an Enable property. I also have a MultiLine property. When the button's Enable property is set to false, the image (caption in this case) is embossed.
// Now draw the caption
if (NewState & ODS_DISABLED)
{
// BUG with multiline when the button is disabled
CPoint pt = CPoint(ClientRect.left, ClientRect.top);
CSize NewcsSize = pDC->GetTextExtent(NewCaption);
pDC->DrawState(pt, NewcsSize, NewCaption, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
}
else
{
pDC->SetTextColor (GetSysColor(COLOR_BTNTEXT));
pDC->DrawText (NewCaption, &ClientRect, DT_WORDBREAK);
}
This works fine until I set the MultiLine property to true. The Caption is still embossed, but instead of breaking the word I get the '|' symbol where the wordbreak should be. Of course MultiLine works fine if the Enable property is set to true. Does anyone know what I am doing wrong here? I am using DrawSate if the button is disabled and DrawText if it is enabled. Any suggestions would be great.
|
|
|
|
|
I have a dialog application which performs a registry backup. I need to perform the same functionality from the command line without showing the frontend.
I have looked into m_lpCmdLine function but I don't fully understand how to setup all of my commands.
I need to be able to consider the following: -
1)My program is called "Registry Backup"
2)Establish whether it needs to be imported or exported e.g. /Export or /Import
3) Then include the possibilty of entering a filename for Local_machine and/or current_user.
I have no idea how to do this. I know I have to do it in InitInstance() with the m_lpCmdLine function but I am now lost.
Thankyou in advance.
|
|
|
|
|
just use __argc and __argv. they behave exactly like the C argc and argv parameters.
run down argv and parse the command line parameters yourself. or, use one of the many command line parsing classes around: here's one
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
if ( (argc > 1) && ((*argv[1] == '-') || (*argv[1] == '/')) )
{
if ( _stricmp( "export", argv[1]+1 ) == 0 )
{
CmdExport();
}
else if ( _stricmp( "import", argv[1]+1 ) == 0 )
{
CmdImport();
}
exit(0);
}
}
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
You have to ignore my ignorance but I am reasonably inexperienced in this particular area.
I am working in a Dialog application in the InitInstance function therefore the old style isn't as appropriate how can it be modified. I understand that __argc and _targc are appropriate in this case. Is this true and how does it alter from what you have already posted.
Thanks for your help
|
|
|
|
|
this isn't specific to dialog apps (works fine in doc/view, too):
BOOL CThumb7App::InitInstance()
{
...
if (__argc > 1)
{
firstParam = __argv[1];
}
else
{
firstParam="";
}
...
}
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
I think I am slowly getting it.
I have the following options of:
Program is called "Registry Backup.exe"
Export or Import (/Export or /Import)
Local Machine file or Current User file ( LM: or CU: )
Then the path to which it will be exported or imported (arg1)
So I could have a command line of:
Registry Backup.exe /Export LM: "C:\Sofware\Registry.dat"
The path would have to be inclosed in speech marks, correct?
How would your example be modfied in such a scenerio?
|
|
|
|
|
any parameter with spaces in it must be in quotes, otherwise, the shell will break it into multiple parameters. i'm not sure what happens if your application name contains spaces.
assuming the command line you gave, this is the contents of __argv:
__argv[0] = application name
__argv[1] = "/Export"
__argv[2] = "LM:"
__argv[3] = "C:\..."
so, grab __argv[1], test it for "/Export" or "/Import" and proceed accordingly.
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
I am attempting to write a C library of routines for my DVD player. (It talks over a serial port.) I want the library as portable as possible, so I'm attempting to do it in C. I know it'd be alot easier for me to do it with classes, but as far as I'm concerened, C++ is out of the question.
I can successfully compile the header below with it's .c file. The problem comes when other C++ modules (I'm trying to use the C library in an MFC app) #include the header. The compiler chokes on the first paranthesis inside the struct definition. I'm thinking it's something having to do with switching into C++ mode.
The whole reason why I'm doing this is because I don't want the user to have to mess with a buffer. All they need to provide are callbacks for Open, Close, Read, and Write (reguarldess if they are using J.P. Naughter's serial wrappers, raw win32 api, or Unix file i/o) of the serial port library and users can do something simple like: DVDPlayer.Execute(PLAY); and not have to worry themselves with formatting, writing and returning the response to me for parsing. This way, it can all be handled internally. And in C.
[ccode]
#pragma once
int DVF07Error(struct DVF07*);
void DVF07StoreTOC(struct DVF07*, struct toc_type*);
void DVF07StoreTrack(struct DVF07*, struct toc_type*, int);
void DVF07TraceTOC(struct toc_type*);
int DVF07Format(struct DVF07*, int, int);
int DVF07Execute(struct DVF07*, int, int);
int DVF07ReturnedInt(struct DVF07*);
int DVF07SizeofBuf(struct DVF07*);
typedef struct DVF07{
/* in c++ files, when this is #included, the ( of int (*Error is */
/* where the compiler chokes, but it compiles fine when */
/* the .c file #includes it */
int (*Error)(struct DFV07 *this);
void (*StoreTOC)(struct toc_type*, struct *toc_type);
void (*StoreTrack)(struct toc_type*, int i);
void (*TraceTOC)(struct toc_type *toc);
int (*Format)(struct DVF07 *this, int, int);
int (*Execute)(struct DVF07 *this, int, int);
int (*ReturnedInt)(struct DVF07 *this);
int (*SizeOfBuf)(struct DVF07 *this);
/* user provided routines below */
int (*Write)(struct DVF07 *this);
int (*Read) (struct DVF07 *this);
int (*Open) (struct DVF07 *this, int port);
int (*Close)(struct DVF07 *this);
char buf[256];
} DVF07_Type;
[/ccode]
|
|
|
|
|
I see one potential problem with that line: "this" is a C++ keyword. Could that be the problem? What happens if you comment that line?
"Harland Pepper, would you stop naming nuts" - Harland Pepper
|
|
|
|
|
I don't think so. I've compiled code before using 'this' in C. I think it only is a problem when __cplusplus is defined. And in this case, it is not -
I hope
|
|
|
|
|
#ifdef __cplusplus<br />
extern "C" {<br />
#endif<br />
<br />
<br />
#ifdef __cplusplus<br />
}<br />
#endif
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Thanks! this worked after I cleaned up a a few issues...
|
|
|
|
|
Anyone know how I can find what the path to the "My Documents" directory is please?
|
|
|
|