Board index » cppbuilder » TThreads and Vectors...

TThreads and Vectors...


2006-05-10 09:29:35 PM
cppbuilder35
Hi everybody.
Having a problem using a vector in my thread. I've got a thread created
with the wizard and a descendant of TTread. I want to use a vector in it to
store a structure that I have define. It's all pretty straightforward... I
typedef my structure in the threads header, include vector.h and then
declare a vector to hold the typedef'ed structure. However I then start to
get compile errors, complaining about _pair.h, specifically:
E2132 Templates and overloaded operators cannot have a C linkage
E2040 Declareation terminated incorrectly
is there any known problems using threads and vectors?
Thanks in advance,
K
 
 

Re:TThreads and Vectors...

Quote
However I then start to get compile errors, complaining about
_pair.h, specifically:
Are you using normal C vectors or STL std::vector? Please show
some code to reproduce the problem.
Quote
is there any known problems using threads and vectors?
No. Not generally speaking.
SF.
 

Re:TThreads and Vectors...

Hi SF,
I'm using STL std::vector...
TFileThread.h...
#include <vector>
typedef struct
{
AnsiString szPath;
HFILE hfHandle;
} TSTR_FILE_DATA;
class TFileThread : public TThread
{
private:
vector<TSTR_FILE_DATA>vecFileData;
...
TFileThread.cpp
__fastcall TFileLockThread::TFileLockThread(bool CreateSuspended) :
TThread(CreateSuspended)
{
OFSTRUCT ofs;
AnsiString szPath;
TSTR_FILE_DATA strFileDat;
vecFileData.clear();
strFileDat.szPath.SetLength(MAXPATH + 1);
strFileDat.szPath.SetLength(GetModuleFileName(HInstance,
strFileDat.szPath.c_str(),
strFileDat.szPath.Length()));
strFileDat.hfHandle = OpenFile(strFileDat.szPath, &ofs,
OF_SHARE_DENY_WRITE);
if (strFileDat.hfHandle != HFILE_ERROR)
vecFileData.push_back(strFileDat);
thats about it really.. not much to it.. Any ideas?
"SF" < XXXX@XXXXX.COM >wrote in message
Quote
>However I then start to get compile errors, complaining about _pair.h,
>specifically:

Are you using normal C vectors or STL std::vector? Please show some code
to reproduce the problem.

>is there any known problems using threads and vectors?

No. Not generally speaking.

SF.

 

{smallsort}

Re:TThreads and Vectors...

Quote
I'm using STL std::vector...

TFileThread.h...
I changed:
vector<TSTR_FILE_DATA>vecFileData;
with
std::vector<TSTR_FILE_DATA>vecFileData;
and
MAXPATH
with
MAX_PATH
and got no errors at compile-time (BCB5). Your problems are
somewhere else, most likely not related to vectors. Where
exactly are you getting:
E2132 Templates and overloaded operators cannot have a C linkage
E2040 Declareation terminated incorrectly
HTH,
SF.
 

Re:TThreads and Vectors...

"Kevin Johnson" < XXXX@XXXXX.COM >wrote in message
Quote
However I then start to get compile errors, complaining about
_pair.h, specifically:
Please show your actual code.
Gambit
 

Re:TThreads and Vectors...

Hi remy,
Apologies for any confusion with regards to the two senders, I posted the
original message from another station which had another account. I think
i've tracked the problem down. Gina specific once again :)
In order to explain, i must digress somewhat... I was having issues with
naming conventions and the naming / symbols used when compiling my BCB based
DLL - winlogon couldn't access the exported functions because they had an @
and the start. I resolved this (although I honestly don't understand why it
work) by using the statement :
extern "C"
{
#include <winwlx.h>
};
I had originally thought this was because the winwlx.h was a pure C header
file, although i though the extern "C" statement had something to do with
turning of name mangling. Anyway, it seemed to work but the down side of it
is that it seems to prevent the inclusion of the vector.h and corresponding
libraries... If I remove the extern statement, i can include the vectors
header no problem but then i have the export table naming problem again...
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Kevin Johnson" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>However I then start to get compile errors, complaining about
>_pair.h, specifically:

Please show your actual code.


Gambit


 

Re:TThreads and Vectors...

"Mike Collins" < XXXX@XXXXX.COM >wrote in message
Quote
I had originally thought this was because the winwlx.h was a pure C
header file, although i though the extern "C" statement had something
to do with turning of name mangling.
It does. Or more accurately, it removes the decoration from the exported
names. But the mangling is also controlled by the calling convention of
each individual function. For Win32 API functions and callbacks, the
calling convention has to be __stdcall.
Quote
Anyway, it seemed to work but the down side of it is that it seems to
prevent the inclusion of the vector.h and corresponding libraries... If I
remove the extern statement, i can include the vectors header no problem
but then i have the export table naming problem again...
You are not supposed to be placing vector.h inside the "extern "C" block to
begin with. Place them outside, ie:
#ifdef __cplusplus
extern "C" {
#endif
#include <winwlx.h>
#ifdef __cplusplus
};
#endif
#include <vector>
//...
Gambit