0

I have source code for USB communication ("USBThread class") written in Borland C++ and uses Visual Component Library("vcl.h"). Now my task is to port that to Visual C++, because we did not buy Borland C++.

But this "USBThread class" has inheritance from a base class in "vcl.h", called "TThread".

May I ask , in Visual C++, What kind of base class I can use to substitute "TThread' as new inheritance source?

The original code uses "WaitFor" and "Terminate" methods coming TThread, I do not know how to implement these two menthods with Visual C++.

Thanks!

Johan
  • 74,508
  • 24
  • 191
  • 319
  • That depends. What do you need this replacement class to do? – Greg Hewgill Apr 24 '12 at 03:13
  • I want to implement "WaitFor" and "Terminate" methods in Visual C++, these two methods inherits from TThread in Borland C++. – user1352716 Apr 24 '12 at 03:40
  • I suppose you don't have the source code for `TThread`, do you? I don't think there's a threading convenience class in Visual C++, so you'll just have to use the Win32 API threading functions directly. – Greg Hewgill Apr 24 '12 at 03:44
  • No, I do not have source code for TThread. – user1352716 Apr 24 '12 at 03:54
  • if you are unable to port it to VC style source you can still use Borland. for example BDS2006 Turbo C++ has free licence for 100 years even for commercial use if you have just single language per machine. It is discontinued but I am sure that you will find it on some p2p network. Also borland 5.5 compiler (which is the same as bds2006 Turbo C++) is for free completely (I think) but it has no IDE. – Spektre Jan 29 '14 at 09:00

2 Answers2

0

This is likely to be a difficult exerice imo but it looks like Boost.Thread using join for WaitFor and interrupt for Terminate would get you started.

I am basing this on review of the docs for VCL found here. I say this is likely to be difficult because VCL may have behaviour that is undocumented or otherwise unexpected.

Steve Townsend
  • 53,498
  • 9
  • 91
  • 140
0

Although you could translate the VCL's TThread class into C++, it would not work very well because it relies on some Delphi semantics that simply do not translate to C++ at all (in particular the TObject::AfterConstruction() method). You are best off simply re-writing USBThread to use Win32 thread functions directly, namely CreateThread() and WaitForSingleObject(). For Terminate(), you simply set a bool flag somewhere that your thread procedure can look at periodically and stop its work when set to true.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770