Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I still don't get it. The moment I issue a CreathThread command control will pass over to the thread, where I have put a sleep function of say 10 minutes. In my main function, immediately after this CreateThread command, I have given a WriteFile command to write to the serial port. Now, will this write be executed after the sleep period of 10 minutes or before that?

Think of the two threads as if they are two completly different programs. They are executed independently of each other. So the Sleep() in one thread will be executed independently of the WriteFile() in the other thread.

On a side note, if I have a thread which reads an input from the serial port, is there a way to pass this input back to the main thread, while still ensuring that this thread continues monitoring for any other input?

Yes -- use global variables. All threads access the same global space. But you have to be careful to include thread synchonization techniques to prevent one thread from writing to the global variable at the same time that another thread tries to read or write to it. The simplest way to do this is with system mutex. See MSDN for CreateMutex() or google for examples.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your program has probably trashed memory somewhere. I'm 99.999% certain the problem is NOT witth std::string so it must be somewhere else. Look for buffer overruns and use of initialized pointers or dereferencing null pointers.

If you can please attach the files instead of just posting them with code tags. You can tar them (or zip them) without object files to make the tar file smaller.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you almost have it. PathAppend() is not needed in your example.

void EnumerateFolderFS(LPCTSTR path)
{
   TCHAR searchPath[MAX_PATH];

   // a wildcard needs to be added to the end of the path, e.g. "C:\*"
   lstrcpy(searchPath, _T("C:\\*.h"));
   //PathAppend(searchPath, _T("*")); // defined in shell lightweight API (v4.71)

>>2. MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
You created a console program but coded a windows GUI program using WinMain().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>strcpy(searchPath, L"c:\\*.h");
That doesn't work because strcpy() requires char*, not wchar_t* Instead use _tcscpy() _tcscpy(searchPath, _T("c:\\*.h")); Note that _tcscpy() is a macro defined in tchar.h which translates to either strcpy() when UNICODE is undefined or wcscpy() for UNICODE.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Override the OnCalcel() method in the dialog. The below code works from any dialog box within the SDI or MDI program.

void CAboutDlg::OnCancel() 
{
    CWnd* pWin = AfxGetMainWnd();
    ::PostMessage(pWin->m_hWnd, WM_CLOSE,0,0);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>This is the code i get some where online. Why i get an error message stating that " error C3861: '_T': identifier not found"?

You have to include tchar.h

>>2. and where actually i should place the wildcard for me to search files of certain type (for exp: .h)?

In the FindFirst() function call. Unless you want UNICODE support I'd replace TCHAR and _T macros to make the code more readable.

char searchPath[MAX_PATH];
strcpy(searchPath, "c:\\*.h");
...
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Someone has to be in the center.

But it doesn't have to be the government -- it should be your family and friends.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

TCHAR is defined in tchar.h. LPTSTR and LPCTSTR as well as a lot of others are defined in windows.h

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

After calling CreateThread() the operating system will add the new thread to its thread scheduling list and give each thread CPU time. So thread1 will get a slice of CPU time, then when that time slice expires the os will halt the thread and give another thread some CPU time. It works like that for all threads running on the computer.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> was wondering if anyone could provide any advice on how to create and use a dynamic library using gcc on Linux
They are called shared libraries on those operating systems. Here are some google links.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That fixed it. Thanks for the help. So apparently I should have created a windows project, not a console project.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Are you using *nix or MS-Windows ? If MS-Windows you can use FindFirstFile() and FindNextFile() to get the file names. See examples on MSDN and here at DaniWeb.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Alright, i cant get this to work. Im not sure what u mean by substitute argv[1], argv[2], ... for the hard-coded names in the open statements.

Sorry, but i am very new to c++, only been using it for a few weeks now so i will need more precise instructions if you could pls.

Here is what I meant

int main(int argc, char* argv[]) // declaration of all variables
{
    if( argc != 4)
    {
           cout << "Now enough arguments\n";
           return 1;
    }
	string line;
	fstream chapter_one (argv[1]); //open the 3 text files
	fstream chapter_two (argv[2]);
	fstream chapter_three (argv[3]);
	ofstream book (argv[4]); //creates book.txt
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I've downloaded and compiled wxWindows using VC++ 2008 Express. Also am able to compile/link the Calculator example program (haven't tried the others yet).

Now I want to begin writing my own program. So I searched google for tutorials to help get starte. None of them contain main(), and neither does the Calculator example program. I started a new console project and added the Hello World code from one of the tutorials. Since the tutorials don't have main() I deleted main() from my project. It compiles but link gets error

MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
D:\dvlp\simple\Debug\simple.exe : fatal error LNK1120: 1 unresolved externals

So, what am I missing ?

// main.h
class MyApp : public wxApp
{
  public:
    virtual bool OnInit();
};
// simple.h
class Simple : public wxFrame
{
public:
    Simple(const wxString& title);

};
// main.cpp
#include "main.h"
#include "simple.h"

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    Simple *simple = new Simple(wxT("Simple"));
    simple->Show(true);

    return true;
}
// simple.cpp
#include "simple.h"

Simple::Simple(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250, 150))
{
  Centre();
}

The project contains these libraries, which I copied from another example project.

wxmsw28d_core.lib wxbase28d.lib wxtiffd.lib wxjpegd.lib wxpngd.lib wxzlibd.lib wxregexd.lib wxexpatd.lib winmm.lib comctl32.lib rpcrt4.lib wsock32.lib odbc32.lib
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm new to C++ (long time java user though), and still not quite sure when I should and shouldn't use pointers. I'm going to go back and make the change you suggested.

Rule-of-thumb: never use pointers unless absolutely required. In your class, pointers are not needed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

main() has two optional arguments that are the number of command line arguments and an array of strings are are the arguments

int main(int argc, char* argv[])
{

}

argc is always >= 1 because argv[0] is the name of the executable program.
In your example joinTextFiles chapter1.txt chapter2.txt chapter3.txt book.txt argv[0] == "joinTextFiles"
argv[1] == chapter2.txt
argv[2] == chapter3.txt
argv[3] == book.txt

Now in your progrsam just substitute argv[1], argv[2], ... for the hard-coded names in the open statements.

Dave Sinkula commented: Making the previous rep count. +14
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is something else. Possibly something that has not been declared. Try this -- it compiles ok for me with VC++ 2008 Express

struct geom_Point3
{
    int x,y;
};

double Min(vector<geom_Point3> &Points, int n)
{
    return 0.0;
}

int main()
{
    vector<geom_Point3> Vertices_;
    double min_x = Min(Vertices_, 0);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
colHeadVector = new std::vector<QLabel*>(); //line 342
	rowHeadVector = new std::vector<QLabel*>(); //line 343
	widgetVector = new std::vector<std::vector<QWidget*>* >();  //line 344
	arrayGrid = new QGridLayout(); //line 345

Why are those pointers? Just declare those vectors without pointers. You are not saving anything by making them pointers, instead you are creating a lot of headaches for yourself.

std::vector<QLabel*>  colHeadVector;
std::vector<QLabel*>  rowHeadVector;
std::vector< std::vector<QWidget*> >  widgetVector;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster


double Max(vector<geom_Point3> &Points, int n);

min_x = Min(Vertices_, 0);

Dave: Those are two different functions. Post the prototype for the Min() function, it apparently is different than for the Max() function which you posted.

>>but then isn't it passing the entire array (which is very big in this case) instead of just its address?
Yes its passing the entire array, which can be very time consuming for the program when the vector has a large amount of items.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Welcome to DaniWeb.

>>Also, I really liked that you could donate me money in instructions that I give you
Oh me too -- me too. :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Welcome to DaniWeb -- care to share other personal info with us, such as where you are from ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Welcome to DaniWeb. You will get lots of help around here -- just ask away in any of the tech boards.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Welcome to DaniWeb. Oh I envy your graphic talent :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

For you guys who have never had a suit fitted - the question "do you dress right or left" has to do with how you hang so the tailor know where to 'adjust' the fit of your trousers.

But you probably knew that.

I actually thought you meant "I dress correctly ...". You're treading on very thin ice if you are talking about what I think you are talking about. Don't go that direction.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That doesn't answer the question...
You have just proven that the government IS the center of our existence. But you've not stated whether it should be...

I can't imagine life without the interference of government. It isn't really the center of my life, only is a large part. The only way government could not be such as huge part is if I lived on some remote island all by myself with no outside influence.

As for should it be? Yes. We need someone to do those things and provide those services that we can not do ourselves.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I suspect the problem is actually somewhere else. Will you post the code that calls SetScheme() -- hopefully attach the rest of the problem so that I can compile and run it, assuming this is for MS-Windows operating system. Instead of attaching the files one at a time just use WinZip and zip them all then attach the *.zip file (remove object files and other compiler-generated files).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>You are not blaming me for anything else. Does that mean I am right?.
No, it just means that line had a typ. To check if you are right or wrong you have to compile and run the program.

>>ill I registered in this forum the only world I knew was Turbo C.
Great move :) I'm sure you won't regret the move.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>MessageBox( NULL, TEXT("Welcome", NULL, NULL ) ;

You have a typo. There should be a closing parenthese ) after the word Welcome. like this: MessageBox( NULL, TEXT("Welcome"), NULL, NULL ) ;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are compiling your program for UNICODE. Turn that feature off. Go to menu Properties --> Project (at the bottom of the menu). Expand Configuration Properties, then click General.

1) Change the Configuration: at the top of the window to All Configurations

2) In the right pain near the bottom you will see Character Set. Select Not Set from the combo box.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> promise to have your babies
OMG you are desperate aren't you :)

>>The std::map in VC98 seems to be playing up
Have you tried compiling and running with more recent compiler? That compiler is extremely old. Download VC++ 2008 Express and test your program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why is that I am not able to understand what you are talking? I was never thought about MAKEFILE :( What is a makefile?

A makefile is a text file that tells a compile how to compile and link a program. Tutorial here.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do you mean this function?

void Weather::SetScheme(SceneArg *sceneArg)
{
	memcpy(&mScheme,sceneArg,sizeof(SceneArg));
	mIsLoaded = true;
	_update();
}

The only problem I see in that function is that sceneArg should be declared const. Also check that it is a valid pointer.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I could be wrong, but to make a graphbar without using additional toolkits (like wxWidgets etc), you would need Visual Studio standard or pro, which aren't free.
But you can try the pro-version here (90 day-trial)

You are wrong. The Express edition can be used to write windows GUI using win32 api functions. You need the Standard or better $$$ editions to get MFC and the resource editor. I think there are also free resource editors on the net.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>How hard would that be?
It may take anywhere from a couple days (for experienced programmers) to about a lifetime for beginners. For your compiler you might also want to download free wxWindows. Or if you want to use pure win32 api functions here's a tutorial.

Nick Evan commented: You've discovered the wonderfull world of wxWidgets :) +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try this example DLL: I compiled it but didn't test it

#include <windows.h>
#include <stdio.h>

static DWORD WINAPI myThreadProc(void* parmeter)
{
   while(true)
   {
      printf("Hello world!!!\n");
      Sleep(1000);
      }
   return 0;
}
   
__declspec( dllexport )  int WINAPI HelloWorld()
{
   CreateThread(0, 0, myThreadProc, 0, 0, 0);
   return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Is CreateFile equivalent to using a CreateThread
No. CreateFile() works with files and CreateThread() creates new threads. They are two completly different animals.


>>I would be highly obliged if you could give me a link with some samples of multi-threaded applications
There are billions of examples on the net. Here are some in DaniWeb.

>>or will I have to explicitly give 2 CreateThread commands after the CreateFile for reading & writing?

Only one CreateThread() function call. main() is alread in one thread so all you have to do is create another thread. In the new thread function you can put the code to open the file using CreatFile() and do all the phone dialing and other stuff.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Microsoft discontinued that feature with 2005. It was replaced by VCBuild.exe, which uses the solution file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The Arabs have been at war for the last 5,000 years? I would hope you have some sort of documentation for this.

Yes I have -- I have personally witnessed it for that long :) But seriously, no -- the 5,000 years should have been an obvious streatch of the imagination. Could have sait 5 billion years as well.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I am 28, and we (friends, family) simply use the brand name. For the most part, the generic terms associated with the description of a softdrink have never been used by us. Now that I think about it, not too many other people take that approach....I do not know how or why that trend started, it just did!

The term soda goes way way back to the 19th century or maybe evey earlier. In my teen-age years and early adulthood we had soda fountains where we could buy beverages and ice cream, and it was a place to hang out with other people of our age.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It is in the thinking part that I engaged when I read this morning the signature of one of our elderst posters. In Ancient Dragon two part signature it says:

Wrong link. :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Must goverment be the center of our existence?
Yes, it is. Without government there would be just chaos. Government, from the tiny village to the federal government affects our every day lives. I can't think of a thing I do (yes, even in the privacy of my bedroom and bathroom) that isn't affected by some goverment in some way.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sorry, but that's the only cross platform library I know of that might help you.

I just discovered (using google) that the wxWindows library might contain code that you want.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Metalsiege: you never did say what compiler you are using. Exactly how to do what you want depends on what compiler IDE you are using because each one is different. I used VC++ 2008, created a new project, then added each of the *.cpp and *.h files to the project. Compiles and links without errors that way.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Have you looked at the boost libraries ? I don't know if their time functions contain milliseconds or not.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It compiled without error for me. What error message(s) did you get with your compiler. I used VC++ 2008 Express.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is a simple example. You need to overload the [] operator, as below.

const int MAXSIZE = 20;
class MyClass
{
public:
    MyClass() 
    { 
        x = 0; 
        for(int i = 0; i < MAXSIZE; ++i)
            array[i] = i+1;
    }
    int& operator[](int n) {return array[n];}
private:
    int x;
    int array[MAXSIZE];
};


int main()
{
    MyClass mc;
    int n = mc[4];
    cout << n << "\n";
    mc[4] = mc[4] * 100;
    n = mc[4];
    cout << n << "\n";

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do what the forum admins do here.. snip url's.

delete threads and ban spammers. We have mods located all over the world so that DaniWeb gets 24/7 (normally) coverage. And what the mods don't immediately catch there are many regular members who report spam and other problems to the mod staff for quick resolution, which is what the Flag Bad Post button is used for.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Welcome to DaniWeb Abbhie

>>Eyes: black
Are you sure? I never heard of a human with black eyes. You are human aren't you :) Maybe you mean you have grey eyes ?