首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

小弟我写了一个从Excel中读取数据的DLL,参数用的是vector<vector<string> >& ,不会有有关问题吧!

2012-03-27 
我写了一个从Excel中读取数据的DLL,参数用的是vectorvectorstring & ,不会有问题吧!?如下:externC _

我写了一个从Excel中读取数据的DLL,参数用的是vector<vector<string> >& ,不会有问题吧!?
如下:
extern   "C "   __declspec(dllexport)
int     __stdcall   ParseData(char*   szFileName   ,   vector <vector <string>   > &   vvFinalData);
这个DLL是一个系统的一部分,只负责读出数据到vvFinalData中,读取之后主程序会处理这些数据然后存到数据库中。一开始没有什么问题,后来系统其他部分编写完毕后,回头再测试,居然出问题了,可是从调用DLL到处理DLL读取的数据到保存至数据库中这部分代码一直就没动过!
出问题的Code在主程序中,而且出问题的地方不确定,意思就是说把出错的语句注释掉,则另一个地方出错,无厘头似的错误,按照以前的经验,应该是DLL的问题。我以前发生过调用DLL后主程序无法再使用AnsiString的问题,后来发现是调用约定写错了,漏了个__stdcall(详见:
http://community.csdn.net/Expert/topic/4831/4831856.xml?temp=.3345606
)这次调用约定肯定是没错了,看来看去,难道是调用参数用vector <vector <string>   > &   也不行!?

[解决办法]
肯定不行。只能用基本类型。
[解决办法]
Most classes in the Standard C++ Libraries use static data members directly or indirectly. Since these classes are generated through template instantiation, each executable image (usually with DLL or EXE file name extensions) will contain its own copy of the static data member for a given class. When a method of the class that requires the static data member is executed, it uses the static data member in the executable image in which the method code resides. Since the static data members in the executable images are not in sync, this action could result in an access violation or data may appear to be lost or corrupted.

RESOLUTION
Export accessor methods from the executable image that created the STL object. These methods wrap the required functionality of the STL object. In this way, the STL object will only be directly accessed inside a single executable image. For example, suppose MyProgram.EXE needs to get the next element in deque <MyClass> that resides in MyLibrary.DLL. MyLibrary.DLL could export an accessor method, MyClass* DequeNextItem (/*...*/). Then MyProgram.EXE could execute this method to get the next item in the deque. See the code sample below for a more complete example.
[解决办法]
//---------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE 's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char * " or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, you do not need to
// explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------
[解决办法]
executable image is the executable file
For example, you are expecting some static data in your DLL but you got the static data in EXE instead.
[解决办法]
you should not pass template class to another executable image.


[解决办法]
You can use OLE safe array and BSTR types

热点排行