mitrmkar 1,056 Posting Virtuoso

resource.h is not the place to define _WIN32_IE. Do it instead above the #includes, i.e.

#define _WIN32_IE 0x0301
#include <windows.h>
#include <commctrl.h>

Or alternatively in the project's configuration.

mitrmkar 1,056 Posting Virtuoso

I still get an error:

Main.cpp In function `BOOL DlgProc(HWND__*, UINT, WPARAM, LPARAM)': 
Main.cpp `InitCommonControlsEx' undeclared (first use this function) 
  (Each undeclared identifier is reported only once for each function it appears in.) 
 Makefile.win [Build Error]  [Main.o] Error 1

In your project, #define _WIN32_IE to at least 0x0300 .

InitCommonControlsEx() takes a pointer to a INITCOMMONCONTROLSEX struct. You are not using the function correctly ...

I added the WM_CREATE in the Message switch

case WM_CREATE:
    InitCommonControlsEx();
break;
mitrmkar 1,056 Posting Virtuoso

A typo has slipped in ... it should be localVariable .

mitrmkar 1,056 Posting Virtuoso

Setting the Default to a specific button is not the solution I want because in the future I would want 10 edit boxes with 10 buttons to correspond to each box.
I'm looking for a more generic solution.
Thanks.

Seems that I misunderstood the problem. Anyhow, the CMyEdit class' code that you have should capture the Enter key.
Maybe you don't have the following in the dialog class implementation

DDX_Control(pDX, IDC_EDIT1, m_eFirst);
mitrmkar 1,056 Posting Virtuoso

What I would like is that when write text in the first edit box and hit ENTER the dialog would push the first button that I created.

That functionality can be achieved by simply making sure that:

  • the first button (only) has the 'default button' -option checked
  • the first edit box does not have the 'want return' -option checked OR it is not a multiline edit control
mitrmkar 1,056 Posting Virtuoso

Is it possible to get the return value of a function started with the CreateThread function or is the only way I can get a value from it to use global variables? I searched but i found nothing.

Thanks.

See GetExitCodeThread()

mitrmkar 1,056 Posting Virtuoso

Don't allocate using the operator new, use _aligned_malloc() instead to have the data properly aligned.

mitrmkar 1,056 Posting Virtuoso

py2exe don't require the user to install python.. somehow but I can't figure out how to use those.

Try going through the py2exe tutorial.

EDIT: Actually I guess the exe file could just be a function that does the command "python foo.py" and it could find the other file since its in the same folder... Would that work?

If you'll use py2exe to assemble all the files your python prog needs, you can skip the idea of coding anykind of wrapper application in C just to get the game up and running. I.e. the dist directory will contain the files you need to distribute, including the .exe.

I think using py2exe would be handy, since no python installation is required on the target computers (and you can code everything in python).

mitrmkar 1,056 Posting Virtuoso

any cryptic clues or help is much appreciated :)

One approach would be to

  • generate a default MFC-based add-in
  • study it so that you understand how things work
  • strip off all MFC/AFX -based stuff, converting the add-in to a standard DLL (i.e. with a DllMain(...) instead of CWinApp, etc (leave the COM-code in-place though))

A (cryptic) clue: the interfaces you'll need, are; IApplication, ITextDocument, ITextWindow and ITextSelection.

You'll get some understanding about how things are organized by looking into the #include <ObjModel\*auto.h> files.

I'm not aware about any decent documentation on the msvc 6.0 add-ins/object model. However, if you are happy with a simple add-in, providing a command or two via a command bar, then you'll probably not be missing the documentation too much.

You might also get some general insight by taking a look at
How to automate tasks by using COM objects in Visual C++

mitrmkar 1,056 Posting Virtuoso

To get 'non-destructive writes', open the file specifying also the ios::in mode.

mitrmkar 1,056 Posting Virtuoso

It appears as if you might have stumbled upon the virtualization feature of Windows Vista. Try looking it up on the MSDN.

mitrmkar 1,056 Posting Virtuoso

The error says: "initialization skipped by case label."

You can circumvent that by ...

int main()
{
    ...
    switch(option)
    {
    case 'h':
    case 'H':
    {  // new scope begins here ...
        ...
	ifstream input("Help.txt");
        ...
    }	// ... and ends here
    break;
    ...
    }
    return 0;
}
mitrmkar 1,056 Posting Virtuoso

Wouldn't it be easiest to add 'standard' ON_UPDATE_COMMAND_UI handlers for those two sub-menus, i.e. you'd have something along the lines of:

ON_UPDATE_COMMAND_UI(IDM_SUBMENU1, OnUpdateSubmenu1)
ON_UPDATE_COMMAND_UI(IDM_SUBMENU2, OnUpdateSubmenu2)
...
void SomeClass::OnUpdateSubmenu1(CCmdUI* pCmdUI)
{
    pCmdUI->Enable( ... )
}
void SomeClass::OnUpdateSubmenu2(CCmdUI* pCmdUI)
{
    pCmdUI->Enable( ... )
}
mitrmkar 1,056 Posting Virtuoso

Hmm, you have to understand that char editControl_Content[2]; allocates space for two chars.
The array indexes start from zero, meaning that the only indexes you are allowed to access in this case are:

1) editControl_Content[0]
2) editControl_Content[1]

So, to get the window text (or a single char in this case), use the following

char editControl_Content[2];
GetDlgItemText(hwnd, LOWORD(wParam), editControl_Content, 2);

Note that, if GetDlgItemText() succeeds, it will set editControl_Content[1] to '\0'.

The reason why you got gibberish, is that you passed an illegal address (&editControl_Content[2]) to GetDlgItemText() in the first place.

mitrmkar 1,056 Posting Virtuoso

You are not getting the window text properly, it should be

char editControl_Content[2];
// the following gets one char into editControl_Content[0] and sets
// editControl_Content[1] to '\0'
int charCount = GetWindowText(GetDlgItem(hwnd, LOWORD(wParam)), editControl_Content, 2);
if(charCount > 0)
{
    // got a char ...
}

And further on, when you use isdigit(), be sure to use the valid index (0) i.e.

if(isdigit(editControl_Content[0]))
...
mitrmkar 1,056 Posting Virtuoso

Well, by doing the following ...

...
background = load_image("background.bmp");

if(background == NULL)
{
    // load_image() failed ...
    cout << "load_image() failed, error: " << SDL_GetError() << endl;
}

apply_surface(100, 100, message, screen);
...

I got output as follows:

load_image() failed, error: File is not a Windows BMP file

Xarver commented: Thanks +1
mitrmkar 1,056 Posting Virtuoso

I still need help here. :|

Assuming that SDL is unable to load the image, you might place a call to SDL_GetError() immediately after the line: background = load_image("background.bmp"); to get a description of the cause of the failure.

mitrmkar 1,056 Posting Virtuoso

Try with these changes

//CUSTOMERDLL.H
#ifndef DllH
#define DllH
#include "customerForm.h"
extern TCustomerF* DllCustomer;
//---------------------------------------------------------------------
void __fastcall Search (AnsiString, AnsiString, TIBTable*);
extern "C" __declspec(dllexport) __stdcall void CreateCustomer(TComponent *Owner);
//---------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
//CUSTOMERDLL.CPP
#include <vcl.h>
#include <windows.h>
#pragma hdrstop

#pragma argsused
#include "customerdll.h"

TCustomerF* DllCustomer = NULL;

int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
	return 1;
}
//---------------------------------------------------------------------------
void __stdcall CreateCustomer(TComponent* Owner)
{
	DllCustomer = new TCustomerF (Owner);
	DllCustomer->ShowModal();
}
//----------------------------------------------------------------------------


void __fastcall Search (AnsiString NameP, AnsiString FieldP, TIBTable* Table)
 {

	TLocateOptions Opts;
	Opts.Clear();
	Opts << loPartialKey;
	Opts << loCaseInsensitive;
Table->Locate(FieldP,NameP, Opts );
 Table->IndexFieldNames=FieldP;
}
//---------------------------------------------------------------------------

Try reading up on usage of extern , once you get the idea of it, you might reorganize the code a bit (you already have one extern TCustomerF* declaration there but it seems that you are not using it)

uim_1977 commented: I was so easy.. Thank you MAN!!!! +1
mitrmkar 1,056 Posting Virtuoso

I think you are using a 32-bit toolset (VS Express) and trying to link with the 64-bit version of libmysql.lib.
The 32-bit version of libmysql.lib comes with those missing symbols, what you have is the 64-bit library.

Ancient Dragon commented: You nailed it. :) +36
mitrmkar 1,056 Posting Virtuoso

Tried what you said but getting the same result. :-/

Perhaps your intention was to replace also a '\v' with a space but you forgot to do it?

mitrmkar 1,056 Posting Virtuoso

Which compiler/OS are you using?
The (modified) code worked for me (Visual Studio 2005), but NOT with GCC 3.4.2.

mitrmkar 1,056 Posting Virtuoso

A couple of things

1) When opening the file, in addition to the ios::out|ios::in flags, specify one of: app, ate or trunc flag.

2) When closing the file, close it only if it is open, i.e.

if(file.is_open())
    file.close();

Also you probably want to understand the error state flags and the related member functions.

mitrmkar 1,056 Posting Virtuoso

ok,I put those checkings but there still seems no problem,but
no output too...
I tried char* instead of strings but it still didnt work...

One fix to the reading problem is to re-open the file, or alternatively you might implement
something similar to seekg() to set position of the get pointer.

int main(){
	string filename = "example.txt";
	Handler fileHandler(filename);
	
	
	fileHandler.openFile();
	string str = "hello";
	fileHandler.writeLine(str);

        // re-open the file so that the read occurs
        // at the beginning of the file
	fileHandler.openFile();

	string str2;
	str2 = fileHandler.readLine();
	cout << str2 << endl;

	return 0;
}
mitrmkar 1,056 Posting Virtuoso

I think you are after ...

typedef List<String^> Vec1;
typedef List<Vec1^> Vec2;

Vec2 List1;

for( int j = 0; j < 1000; j++ )
{	
	List1.Add(gcnew Vec1());

	for( int i = 0; i < 1000; i++ )
	{
		List1[j]->Add("0");
	}
}
mitrmkar 1,056 Posting Virtuoso

regarding the question again, i will now continue to find the solution, so, instead of using namespace, can anyone give me some clue how to implement the clocking code in .c files? thanks1

Use #include <time.h> , and use clock_t and clock() instead of std::clock_t and std::clock() .

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

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

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

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

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

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

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'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

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

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()).

mitrmkar 1,056 Posting Virtuoso

You can use also stringstream to convert to int

int final;
stringstream strm;
char * value_a = "123456";

strm << value_a;
strm >> final;
mitrmkar 1,056 Posting Virtuoso

Thaks it solved that problem. Now i'm getting the following error message
[Linker error] undefined reference to `vtable for ConjVector'

You have one or more virtual methods declared but not implemented in the class.