Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

export vector from dll

Status
Not open for further replies.

butthead

Programmer
Feb 24, 2002
545
US
the records vector is declared in a class as follows

class Table
{
vector<string> __declspec(dllexport) Records;
}

The class is included in the dll that I am exporting from.

I can access the individual items in the vector by other means as below.

char* __declspec(dllexport) TableRecord (void *table)
{
Table *Table;
Table = (Table*) table;
return Table->Record ();
}

Table->Record (); is a method of class table that returns
the present record.

but when I try to do the following

Records.size (); from the main form of the calling
executable.

I get a value of 0. I know before hand the record contains
over 3500 records. It would seem that I am accessing a
different intance of Records. what pray tell am I doing
wrong. I have tried to pass a pointer, the address of all
to no avail.

any tips would be appreciated.

thanks in advance

tomcruz.net
 
Just a quick reminder - in C++ Builder, if using static RTL, you must explicitly use Borland's memory manager for instantiating any non-TObject-derived class. It is memmgr.lib, I think, that should be added to both DLL and calling-app.
Not completly sure about this, but try it (if you haven't already!), because it seems that RTL doesn't know for sure where your instance is!
 
I have dilligently followed all of the items that borland warns about in dealing with strings and such. the use of the memory manager has been take into account and the recommendations have been tried all to no avail. I would just like to know if it is indeed possible so I will not be beating my head against a brick wall for nothing.

does any body out there know of an instance were a vector has been exported from a dll.
 
OK, I've just tried exporting your vector from DLL, and it works fine!
First, why don't you export class Table itself, not just inner methods? I made things working AFTER exporting class itself!
Second, I'm not sure what are you copying exactly?! If you try to return a Records vector from your function DON'T return it by value! Make it a pointer! Looks like, that you are copying vector BY VALUE, and maybe copy-constructor for vector is not copying elements! (Not sure about this though..., have to look at STL vector definition)
Anyway, I returned a pointer to vector from my (exported) class and everything is working like charm :)
 
Ive tried to export it by pointer but the access to the items in the vector was not working, i.e

int x = vector.size ();
or
int x = vector->size ();

did not work. I forget the details of the issue but I know
that I was having trouble iterating through the vector of
strings.

the problem seems to be the usage of pointers and address
and I still have trouble keeping track of which is what and
when while I am working with pointers and such.

I never thought of exporting the entire class but I will
work on that in a day or so. This would certainly simplify
things considerably.

thanx for the tip.

tomcruz.net
 
I remember now.

I dont want to have to include the header file for the table definition everytime I link some code to the DLL.

tomcruz.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top