Jump to content

Threads in eVC++


Guest dchurch24

Recommended Posts

Guest dchurch24

Hi, this may be a really stupid question, but how do I create threads in eVC++ without MFC (which of course is not supported) a quick example would be appreciated if anyone has the time.

I am a Java/VB programmer, so I have been able to get started quite quickly, C was not a problem for me, but eVC++ seems to be giving me very high blood pressure!! :lol:

Link to comment
Share on other sites

Guest dchurch24

...any examples? The CreateThread keyword cannot be found in my eVC++ docs, and a quick search of the web only gave me an example that wouldn't work.

..or just a quick primer. Like, why do I need a long pointer to the start address. In fact, what is the start address :?

Link to comment
Share on other sites

Guest Zorglub

CreateThread is indeed found just fine in the eVC documentation. If you dont see it, it means you have not installed eVC properly. CreateThread exists in Windows, Pocket PC and Smartphone, and uses the exact same parameters on all WIN32 platforms.

If you actually read the documentation you see that it is incredibly easy to use. Just call it with the name of the function that you want to be run in the new thread, e.g.: CreateThread(NULL,0,MyCoolFunction,MyParameter,0,&dwThreadID);

MyCoolFunction will be called with MyParameter.

Link to comment
Share on other sites

Guest dchurch24

Thanks for that. I still can't get it to work, something about undeclared identifier. Maybe c++ isn't my language!

I just re-installed eVC++ and the Smartphone SDK, and still it's not in the documentation. Maybe I've got a corrupt version or something!

Link to comment
Share on other sites

Guest Zorglub

Well there is something definetly &*%^$&*% with your eVC installation. CreateThread is defined in WINBASE.H which is one of the most basic header files in Windows development. It is included when you include windows.h

Link to comment
Share on other sites

Guest dchurch24

I have this:

....

case WM_PAINT:

{

HDC hdc;

PAINTSTRUCT ps;

hdc = BeginPaint(hwnd, &ps);

DWORD dwThreadID;

CreateThread(NULL,0, DrawRectangle,hdc,0, dwThreadID);

EndPaint (hwnd, &ps);

}

break;

....

void DrawRectangle (HDC hdc){

Rectangle(hdc,10,10,20,20);

}

..it doesn't do much. It's just a learning exercise really.

Link to comment
Share on other sites

Guest Zorglub

1- As explained in the documentation, the function you call should be defined as:

DWORD WINAPI DrawRectangle(void* param)

You should define this in your headers or at the top of your file.

2- Inside DrawRectangle you can then do HDC hDC = (HDC) param;

3- When you call Create thread you do like this

hHandle = CreateThread(NULL,0,DrawRectangle,(void)hDC,0,&dwThread)

CloseHandle(hHandle);

4- there is actually a CreateThread example in one of the samples that come with the Smartphone SDK. This should be always your first point of reference before posting as these are great to see things in detail. You can compile them and see how they run.

5- anyway I wouldnt really do any painting in a separate thread !! Or at least I would start the thread at the begining of the program and just notify it with an Event when it needs to do painting. Creating a thread takes a lot of time (relatively), so unless you are drawing something that takes 4-5seconds by itself, it might not be worth it.

Link to comment
Share on other sites

Guest dchurch24

I see!!! Excellent. Thank you very much. I'm struggling with this quite a bit more than I though I would. By day I'm a Java programmer, and I didn't thing C++ was going to be that different - how wrong was I!!!???

I'm going to have to sort out this documentation issue with eVC. I wonder if the same docs are available at msdn.microsoft.com.

Link to comment
Share on other sites

Guest dchurch24

Any idea why I would get this error:

test7.obj : error LNK2019: unresolved external symbol "unsigned long __cdecl DrawRectangle(void *)" (?DrawRectangle@@YAKPAX@Z) referenced in function "long __cdecl WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YAJPAUHWND__@@IIJ

It does look like gibberish, but being new to c++, the whole lot seems like gibberish to me.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.