Import std::vector from other DLL

Import std::vector from other DLL

Anonymous
Not applicable
742 Views
3 Replies
Message 1 of 4

Import std::vector from other DLL

Anonymous
Not applicable

Hello,

 

I have a DLL(MFC extension) that has user defined member variables of STL vector of class, for example, std::vector<Line2D>.

It works fine between arx vs arx to export and import.

However, it doesn't work between arx and MFC DLL.

Does anybody know how to export/import?

What I did was that;

//--------------------------------------------------------

#ifdef GEOMATH_MODULE
#define _IDMD_GEOMMATH __declspec(dllexport)
#define EXPORT_TEMPLATE_GEOMATH
#else
#define _IDMD_GEOMMATH __declspec(dllimport)
#define EXPORT_TEMPLATE_GEOMATH extern
#endif

 

class _IDMD_GEOMMATH    Line2D

{

 ....

};

 

EXPORT_TEMPLATE_GEOMATH template class _IDMD_GEOMMATH std::vector<Line2D>;

//--------------------------------------------------------

in the header file to use both module.

Any advice will be appreciated.

 

ChangHoon

 

0 Likes
743 Views
3 Replies
Replies (3)
Message 2 of 4

maisoui
Advocate
Advocate

Hi,

 

I don't know why you want to "export" type "EXPORT_TEMPLATE_GEOMATH template class _IDMD_GEOMMATH std::vector<Line2D>;". You don't need this line. In your Dll, you need to include and use std (for vector) and include Line2D, you correctly exported. Voila.

 

Regards,

--
Jonathan
0 Likes
Message 3 of 4

Anonymous
Not applicable

Thank you for your support.

I didn't wite the code "EXPORT_TEMPLATE_GEOMATH template class _IDMD_GEOMMATH std::vector<Line2D>" at the begining.

I made several arx(dll) for my application before(using VS2008). AT that time, no problem to inport/export.

At this time(VS2010) I make them separate DLL(Not arx, MDF DLL) to use in other project.

 

I made vector<Line2D> in Arx using class Line2D in MFC DLL. If works fine. 

However,  if I call a function in MFC DLL just after making the vector<Line2D> and passing it as a parameter, vector<Line2D> is wrong in a funtion in MFC DLL.

 

in Arx.

//-------------------

extern __declspec(dllimport) int fun_a(std::vector<Line2D> LineV);

...

void ReadLine(int lindex, AcDbEntity *pEnt, std::vector<Line2D>& LineDataV)

{

AcDbLine* pLine = AcDbLine::cast(pEnt);
Point2D StartPt;
Point2D EndPt;

StartPt.x = pLine->startPoint().x;
StartPt.y = pLine->startPoint().y;

EndPt.x = pLine->endPoint().x;
EndPt.y = pLine->endPoint().y;

Line2D L2(lindex, StartPt, EndPt);
LineDataV.push_back(L2);

return;

}

.....

 

vector<Line2D> LineV1;

if (pEnt->isKindOf(AcDbLine::desc()))
{
  ReadLine(0, pEnt, LineV1);
}

 int test=func_a(LineV1);

//----------------------------------------------

 

Funtion in MFC DLL(Not arx).

//-------------------

class _IDMD_GEOMMATH Point2D;

class _IDMD_GEOMMATH Line2D;

{

....

};

 

extern __declspec(dllexport) int fun_a(std::vector<Line2D> LineV2)

{

   int res = 0;

   return res;

}

//-------------------

LineV1 is OK. but LineV2 has wrong value.

Of course, if I make Arx instead of MFC DLL, it works fine.

I would appreciate it if you could how to solve it.

 

Thanks,

0 Likes
Message 4 of 4

autodaug
Autodesk
Autodesk

I suspect that the compiler switches or preprocessor defines are different for building the MFC and ARX dlls, causing the STL vectors to be incompatible. Possible areas of mismatch that might cause problems:

 

1. Compiler version

2. debug/release mode

3. c runtime lib (use dll-based one)

4. struct alignment (pragma pack macro)

5. _ITERATOR_DEBUG_LEVEL setting

 

As a quick check, maybe you could add a line like: int nSize = sizeof(std::vector<Line2D>); to see if the vector object has different sizes in the two modules. (Note that's not the same thing as their number of elements).

 

 

0 Likes