mitrmkar 1,056 Posting Virtuoso
mitrmkar 1,056 Posting Virtuoso

I'm trying to create a function that will delete an already saved file. I was hoping std::remove() would do the trick but I don't know the syntax.

remove()

mitrmkar 1,056 Posting Virtuoso

You are not converting from a char to int in the valid() function when comparing with 'a'.

Then a couple of notes:

- try choosing meaningful names, e.g. the valid() function takes three arguments named: a, b, c. That's a poor practice.
- when you ask why a program fails to do something, post code that compiles cleanly (so that there is a program in the first place).

mitrmkar 1,056 Posting Virtuoso

mouse function is not defined into two files.. what can I do?

That error occurs also if you have implemented the mouse() function in a header file (.h) and include that header file in two or more source files (.cpp). So, you should move the implementation of the mouse() function to a single source file.

mitrmkar 1,056 Posting Virtuoso

You might download SysInternal's Process Explorer and use its Find handle or DLL utility to see which process has that .nrg file open.

mitrmkar 1,056 Posting Virtuoso

I thought of that too, so I added pragma to force link with the library and it still won't link.

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <winsock.h>
#include "mysql.h"
#pragma comment(lib,"C:\\Program Files\\MySQL\\MySQL Server 5.0\\lib\\opt\\libmysql.lib")

Could it be a 32/64-bit mismatch, for example libmysql.lib actually being the 64-bit version?

mitrmkar 1,056 Posting Virtuoso

I used dumpbin.exe to get a list of all the symbols in libmysql.lib and noted that the function names did not have _ in front of them

Sounds strange, I dumped the libmysql.lib exports

dumpbin /exports libmysql.lib =>
...
_my_realloc
_my_strdup
_myodbc_remove_escape@8
_mysql_affected_rows@4
_mysql_autocommit@8
_mysql_change_user@16
_mysql_character_set_name@4
...

whereas, dumpbin /exports libmysql.dll =>

...
28   1B 00002C2A my_realloc
29   1C 00004502 my_strdup
30   1D 0000454D myodbc_remove_escape
31   1E 00001280 mysql_affected_rows
32   1F 000037A6 mysql_autocommit
33   20 00001C2B mysql_change_user
34   21 0000362F mysql_character_set_name
...

Maybe you accidentally dumped the .DLL?

The sample program you've tried, compiles and links (with libmysql.lib) OK with VS 2005. To me it appears as if the libmysql.lib simply wasn't specified as input to the linker.

mitrmkar 1,056 Posting Virtuoso

i am a beginner in MFC programming and using MS VC++ 6.0. I am trying to create my own window using AfxRegisterWndClass(). My code is as follows :

Frame::Frame()
{
	LPCTSTR className;
	HBRUSH brush;
	brush = (HBRUSH) ::GetStockObject (BLACK_BRUSH);
        className = ::AfxRegisterWndClass (WS_OVERLAPPEDWINDOW,         AfxGetApp()->LoadStandardCursor (IDC_CROSS),
brush,
AfxGetApp()->LoadStandardIcon (IDI_ERROR));
	Create (className, "BHOOT");
//	Create (NULL, "Bhoot", WS_OVERLAPPEDWINDOW, rectDefault, NULL, NULL, 0, NULL);
}

Don't use window styles there, instead specify a combination of class styles, see http://msdn.microsoft.com/en-us/library/ms633574(VS.85).aspx#class_styles

mitrmkar 1,056 Posting Virtuoso

flush is a function

There is also a manipulator by the same name, flush

mitrmkar 1,056 Posting Virtuoso

Hmm, just a thought .. how about changing one line of the signature to:

cout << "Hi there!" << "I'm a non-standard-compliant C++ coder!";


;)

mitrmkar 1,056 Posting Virtuoso

It appears as if you might find already deleted students, because of the ...

for (int n = 0; n < MAX_STUDENTS; n++)
{
    if (strcmp(delStudent, students[n].ID) == 0)
    {
mitrmkar 1,056 Posting Virtuoso

its giving me so many errors....

Well, first of all, be consistent with the names of the member functions, for example

int BST::SEARCHtree(node* i, int k)
{
	if(i==NULL)
	{
		return 0;
	}
		
	else if(k == i->key)
	{
		return(i->key);
	}
	
	else if(k < i->key)
	{
		return TreeSearch(i->left, k);
	}
	
	else(k >= i->key)
	{
		return TreeSearch(i->right, k);
	}
}
mitrmkar 1,056 Posting Virtuoso

I think you'd want to have the string and the newline the other way around, i.e.

text += Dummy2 + System::Environment::NewLine;
mitrmkar 1,056 Posting Virtuoso

why is the size of an empty class 1 byte ? does the compiler add some null byte ?

Stroustrup's C++ Style and Technique FAQ

mitrmkar 1,056 Posting Virtuoso

It appears indented when in the text editor, once it's edited it appears non-indented.

If you don't use code tags, the indentation simply gets lost.

mitrmkar 1,056 Posting Virtuoso

how do i indent ? i press tab and it just tabs over to the reply button

Indent using the space bar.

And the simplest form of using code tags is

[code]

your code here ...

[/code]

mitrmkar 1,056 Posting Virtuoso

I am a PHP guy and present my view only for php Professionals not for C++

But please note that this is strictly a C++ forum.

mitrmkar 1,056 Posting Virtuoso

oh, that worked, what exactly does it mean though?

Simply put, it invalidates the view so that its OnDraw() function gets called.

By the way, the OnDraw() leaks memory since you are not deleting the CRect that you allocate there.

mitrmkar 1,056 Posting Virtuoso

it's not doing anything, i am probably missing something, here's the relevant parts of the code:

void CALLBACK EXPORT TimerProc( HWND hWnd, UINT nMsg, UINT_PTR nIDEvent, DWORD dwTime );

BEGIN_MESSAGE_MAP(CGDI1View, CView)
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
	ON_BN_CLICKED(1,&OnButton1Clicked)
END_MESSAGE_MAP()


void CGDI1View::OnInitialUpdate(){
	button1Rect.SetRect(250,50,400,100);
	button1.Create(_T("HI"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1);
	m_Timer1 = SetTimer(1,33,&(TimerProc));
}

void CGDI1View::OnDraw(CDC* pDC){
	CGDI1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CRect *dims = new CRect;
	pDC->GetClipBox(dims);
	button1.MoveWindow(dims->right-150,0,150,50,0);
	//AfxMessageBox(_T("") + ,MB_OK)
	pDC->MoveTo(pDoc->x,pDoc->y);
	pDC->LineTo(pDoc->x+10,pDoc->y+10);
	pDC->LineTo(pDoc->x+10,pDoc->y);
	pDC->LineTo(pDoc->x,pDoc->y);
	pDC->SetPixel(pDoc->x,pDoc->y,RGB(0,255,0));
	pDC->SetPixel(pDoc->x+10,pDoc->y,RGB(0,255,0));
	pDC->SetPixel(pDoc->x+10,pDoc->y+10,RGB(0,255,0));
	pDoc->step();
}

void CGDI1View::OnButton1Clicked(){
	//AfxMessageBox(_T("you Clicked button1"),MB_OK);
	CGDI1Doc* pDoc = GetDocument();
	pDoc->x=10;
	pDoc->y=10;
	KillTimer(m_Timer1);
}

void CALLBACK EXPORT TimerProc( HWND hWnd, UINT nMsg, UINT_PTR nIDEvent, DWORD dwTime ){
RedrawWindow(hWnd,NULL,NULL,RDW_ALLCHILDREN);
}
void CGDI1Doc::step(){
	x+=1;
	y+=1;
}

is there a message i am supposed to add...

I'm not quite sure what you actually expect to happen, but I think you maybe want to add the RDW_INVALIDATE flag to the RedrawWindow() call.

mitrmkar 1,056 Posting Virtuoso

Ive been trying to look that up for a while now using the 'help' provided by the borland compiler but i cant seen to find anything that i can make sense of unfortunately

Here is how you get items of a single (selected) row

TListItem * Item = ListView1->Selected;
if(Item)
{
    AnsiString text = Item->Caption;
    TStrings * subItems = Item->SubItems;

    for(int ii = 0; ii < subItems->Count; ++ii)
    {
        text += ", " + subItems->Strings[ii];
    }
}
tootypegs commented: cheers for the help! +1
mitrmkar 1,056 Posting Virtuoso

We, want a simple source control system, as we are working in a collaborative mode.

You might do well with e.g. Subversion or CVS.

mitrmkar 1,056 Posting Virtuoso

However I have my code below which wen run, puts the caption (first column content) into a list box. This is just while im testing it to get it to work, but ideally i want all the content from the entire row in the listbox.

I thought there maybe some change in syntax from "Item->Caption" to "Item->Row" to copy the entire row contents but unfortunately i should have known it wasnt going to be this simple:(

TItemStates selected = TItemStates() << isSelected;
   TListItem *Item = ListView1->Selected;
   while (Item){

      ListBox1->Items->Add(Item->Caption);

      Item = ListView1->GetNextItem(Item, sdAll, selected);
   }

Lookup the SubItems property of the TListItem.

mitrmkar 1,056 Posting Virtuoso

Hi, sorry but the link doesnt appear to be working?

So it seems ... now the link is fixed.

I have enables row select from the properties of my listview but Im just having problems calling it

What do you mean by calling it?

PS. In order for the full row select to work, the listview must be in report mode, i.e. ViewStyle==vsReport (maybe you did not know that?)

mitrmkar 1,056 Posting Virtuoso

You need to apply the LVS_EX_FULLROWSELECT style to the listview control, see
Extended List-View Styles

mitrmkar 1,056 Posting Virtuoso

what will the boolean tell, if it worked or not,

If it is TRUE, then it worked, else not (i.e. it is FALSE).

MFC provides the VERIFY() macro, which you might find useful, i.e.

VERIFY(button1.Create(_T("HI"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1));

If the 'verified' funtion fails (returns NULL or FALSE), you'll be seeing a Debug Assertion Failure dialog box with an option to debug the program, so you can quickly figure out where things are going wrong. In Release builds, VERIFY() does nothing.

About generic Windows error codes, here is a brief introduction.

mitrmkar 1,056 Posting Virtuoso

but it isn't working, no errors, just not showing up.

You are not checking the return value of Create(...), so you are unaware of the error.

Override the view's OnInitialUpdate() method and create the button there. At that point the view is readily constructed, hence 'this' can be passed to Create(...) as a valid parent of the button.

mitrmkar 1,056 Posting Virtuoso
int _tmain(int argc, char* argv[])

and the errors are:

Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main

You have to #include <tchar.h>

mitrmkar 1,056 Posting Virtuoso

Maybe a program that scans any Windows installation and makes it absolutely bug-free.

mitrmkar 1,056 Posting Virtuoso

how can i make main to wait on threads

Use one of the Wait Functions.

mitrmkar 1,056 Posting Virtuoso

Maybe your window is missing a style that enables its sizing.

mitrmkar 1,056 Posting Virtuoso

Most of the people who are posting their question over here or sharing their problems are students.
I have posted that code to work on freely available compiler such as TurboC.

But really consider that presumably TurboC was released before most of the students posting here were even born. So, please do not advertise an antiquated/out dated tool for these students. (If anyone is interested in TC, it is available for free from Borland, tagged as antique software ;) )

Nick Evan commented: Sounds like good advice to me! +8
mitrmkar 1,056 Posting Virtuoso

You should encourage the people to post their answers either it is useful or not is the secondary thing....

I would rather emphasize that any answer primarily ought to be useful and that should be considered before posting.

mitrmkar 1,056 Posting Virtuoso

Hi

I was wondering how to create a window to run my programs in. It talks about it in many posts but I couldn't find anything on how to actually make one. I have no idea where to start so you will need to tell me pretty much everything (e.g. examples, code, #include).

Thank you.

Here is one example (assuming you are on Windows).

mitrmkar 1,056 Posting Virtuoso

I am trying to write a multi threaded program in C++ , but it suddenly exits and i can not understand what happens , it actually do not get any error message or exceptions error , just get out of the program.

Could it be so simple that your main() simply exits after the call to Create() has returned?

mitrmkar 1,056 Posting Virtuoso

Maybe sprintf() would be of use ...

char filename[20];

for(int ii = 0; ii < 10000; ii ++)
{
    sprintf(filename, "passenger %04d", ii);

    // display the file name
    puts(filename);

    // try opening and processing the file here
    // ...
}
mitrmkar 1,056 Posting Virtuoso

Since you are calling FreeLibrary(hLib); , maybe you've forgotten to (re)LoadLibrary(...)?

mitrmkar 1,056 Posting Virtuoso
int _stdcall sampleFunc(int iVar, char cVar){
    //Code here
    ...
}
typedef int (*myFunc)(int, char);

Your myFunc typedef does not match the DLL function's signature because you've omitted the calling convention from the typedef (by default, VC++ uses the _cdecl calling convention). So you need to have

typedef int (_stdcall *myFunc)(int, char);
murderotica commented: Explanation is good. The answer is flawless. +1
mitrmkar 1,056 Posting Virtuoso

I need to know Why there is need to operload () this.

STL is one reason, some discussion/examples here

mitrmkar 1,056 Posting Virtuoso

Hi !

I m a new guy in software development. Recently i m assigned wit a job where i got to modify a C++ project built in Visual studio 6 to work in visual studio 2008! any one got any advise where should i start frm?

MSDN has a number of documents explaining the changes between the VS versions, see for example.

To get started, you might just simply build the project in VS 2008 and work your way through the errors/warnings, learning the porting issues as you go. AFAIK, generally the porting should not be too much of an issue.

mitrmkar 1,056 Posting Virtuoso

I've done a search through the Internet and found this this is quite a common case. However, there isn't much clue as to how to fix it code-wise. Any help is very much appreciated.

Now, if you think of it, nobody here has a clue as to what your code does ... how could anyone help you?

mitrmkar 1,056 Posting Virtuoso

Thank you for the info, Edward. Here's more information.

The application calls a function in a DLL (which was written by me). When the debug's DLL is used, the application does not crash when exit (running on Vista). However, it crashes upon exit when the release's DLL is used instead (also running on Vista). The application works fine with both the debug's and release's DLL running on XP.

Unless you post the code and perhaps a screenshot of the error message, it is pretty much impossible to help here any further.

mitrmkar 1,056 Posting Virtuoso

If you are on Windows, then you can use SetConsoleWindowInfo

mitrmkar 1,056 Posting Virtuoso

i dont understand you sorry?

edit:

i did that now i have

Linking...
Main.obj : error LNK2005: "struct CLIENT_HANDLE * Clients" (?Clients@@3PAUCLIENT_HANDLE@@A) already defined in CServer.obj
Release/Chat Server.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

You probably have two times the following: PCLIENT_HANDLE Clients; One in main and the other in CServer, you need to remove or rename one.

mitrmkar 1,056 Posting Virtuoso

A copy constructor of Book/Item probably won't help here, because it is leaking a std::string, so maybe you could devise and use an arbitrary 'type id' construct for the classes you use. I.e. toss away usage of RTTI altogether.

mitrmkar 1,056 Posting Virtuoso

Don't #include "CServer.cpp" in main.cpp.
Instead #include "CServer.h" and move the CServer:: stuff from main.cpp to CServer.cpp.

mitrmkar 1,056 Posting Virtuoso

Both blocks (146 and 147) refer to the following line:

if(book.compare(typeid(*(*itr)).name()) == 0)  //This line!

I don't see how it can contribute to the leak.

Well you don't know what takes place behind the scenes, i.e. how the compiler actually manages typeid(*(*itr)).name() .

mitrmkar 1,056 Posting Virtuoso

Data: <class Book > 63 6C 61 73 73 20 42 6F 6F 6B 00

Based on that, I'd figure the leak occurs in e.g.

if(book.compare(typeid(*(*itr)).name()) == 0)

But anyhow, do as Salem suggested, so you'll be learning debugging techniques ...

mitrmkar 1,056 Posting Virtuoso

The base class of Book, Item, had a virtual destructor defined. The destructor does nothing other than delete a set container that was allocated in the constructor. I made it virtual because some of the derived classes had additional sets that needed to be deleted also.
I removed the virtual from ~Item()

Then the destructor of the derived class will not get called when you
do a thing like ...

Item* book = new Book(title, author, nPages);
delete book; // ~Book() will not be invoked

Maybe you should post the complete code ...

mitrmkar 1,056 Posting Virtuoso

Go through the stored items in the Library 's destructor and explicitly delete the items there.

Undertech commented: Definitely something important that I didn't realize! +1
mitrmkar 1,056 Posting Virtuoso

You have to get there a const char * , which is what the c_str() function gives you (i.e. hello.c_str()).