vector not access from vc++2010 App same code works fine in Qt App.

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 4059 Views - Last Post: 16 April 2012 - 09:05 PM Rate Topic: -----

#1 BegineerC++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-March 12

vector not access from vc++2010 App same code works fine in Qt App.

Posted 29 March 2012 - 12:14 AM

Hi,

I have one very strange issue. i have API which returns vector pointer. i have two application accessing same API(DLL) one in Qt App another MFC App.
when i call API from Qt App function returns with proper Vector elements. but same code when tried from MFC App does not return element with values but some junk values. even i saw Count for Vector returns properly in Qt App but junck values in MFC App.
i do not understand problem its pretty simple code.

Is This A Good Question/Topic? 0
  • +

Replies To: vector not access from vc++2010 App same code works fine in Qt App.

#2 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 663
  • View blog
  • Posts: 2,277
  • Joined: 31-December 10

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 29 March 2012 - 06:06 AM

Could you post the code? It's hard to say what the problem is without seeing the code.
Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg  Icon User is online

  • member icon


Reputation: 4076
  • View blog
  • Posts: 12,589
  • Joined: 25-December 09

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 29 March 2012 - 06:16 AM

How are you passing the values from managed code to unmanaged code and vice-verse? Mixing managed and unmanaged code is in my opinion quite messy. See these links for possible pitfalls. Mixing Managed and Unmanaged Code, and MSDN.

And a Quote from the first link:

Quote

Conclusion

Mixing managed and unmanaged code can be very powerful, and it gives us programmers - a lot more freedom to decide on how to code. However, we should be aware that mixing these technologies introduces some extra difficulties and should be taken care off from the beginning, when starting to design your .NET applications.


Jim
Was This Post Helpful? 0
  • +
  • -

#4 BegineerC++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-March 12

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 29 March 2012 - 09:08 PM

Hi,

Rest all API works perfectly fine i am getting response (return values) properly only in case of Vector elements it is having problem. i am sending Reference still i have debug memory address nothing seems going wrong return values has correct valus and returning with proper memory address but in MFC application i can not see only vector elements or values inside vector where as in Qt application i can see both are different application using same DLL built in QT but pure C++ code.
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2993
  • View blog
  • Posts: 10,343
  • Joined: 08-August 08

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 29 March 2012 - 09:13 PM

See post #2
Was This Post Helpful? 1
  • +
  • -

#6 BegineerC++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-March 12

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 29 March 2012 - 09:27 PM

Hi,

Actually i can not put code here it is complex but concept wise simple. it is very big...the way fectfing data in vector n all...but from application it is like one line of code.

std::vector<BigStructure*> pStruct = NULL; // This is Vector each element will have pointer to Structure

pStruct = ClassObj->GetValuesStructre("<XML String>"); // Dynamically calling API after creating class object, class is in header file. API will return pointer to vector.

inside DLL works fine no issue..i have debug with Memory address, even same memory address remains after coming out from DLL it does not get delete or some thing but in "pStruct" vector element i can not Travers. even Count or pStruct->List->pList.at(i) gives exceptional handle. but my problem is same thing when i tried in QT Application works fine.
is i am missing of some thing to include of QT in MFC for Vector?
Was This Post Helpful? 0
  • +
  • -

#7 BegineerC++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-March 12

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 30 March 2012 - 01:49 AM

Hi,

I have found some thing on Net while goolgling can any one tel me meaning of it..i mean i guess that is the solution but i did not get proper meaning of it. below is the link:

http://forums.codegu...ad.php?t=339019

if i add code inside function i am getting error as:
error C2530: 'ar' : references must be initialized // @ CArchive& ar; what is CArchive?
Was This Post Helpful? 0
  • +
  • -

#8 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 663
  • View blog
  • Posts: 2,277
  • Joined: 31-December 10

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 30 March 2012 - 05:54 AM

Quote

API will return pointer to vector.

If that's the case, then this is wrong:
std::vector<BigStructure*> pStruct = NULL;


It should be:
std::vector<BigStructure*>* pStruct = NULL;


Was This Post Helpful? 0
  • +
  • -

#9 BegineerC++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-March 12

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 30 March 2012 - 06:24 AM

std::vector<BigStructure*>* pStruct = NULL; statement gives exceptional handel at time of push_back item inside list. exactly at
 size_type size() const
		{	// return length of sequence
		return (_Mylast - _Myfirst);         // exceptional handle
		}

Was This Post Helpful? 0
  • +
  • -

#10 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 663
  • View blog
  • Posts: 2,277
  • Joined: 31-December 10

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 30 March 2012 - 06:51 AM

Well you can't push_back on the pointer to vector if it's NULL. These code snippets don't help, we need more context to be able to help. What API are you trying to use?
Was This Post Helpful? 0
  • +
  • -

#11 BegineerC++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-March 12

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 30 March 2012 - 09:52 AM

API i mean DLL which i am using is i have created. which will talk to webservice and get some details. there are almost 80 API's i have created depending on webservice. all works fine except for one which returns vector elements.
i was checking through Qt application but since it was platform independent DLL it was necessary to check with Visual studio Application. here i encounter with issue.
i got only above post in case of using vector in MFC. is there any serialise kind of class require in MFC to populate out Values ?
i did not fine any serialise class for vector in MFC on net..
Was This Post Helpful? 0
  • +
  • -

#12 BegineerC++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-March 12

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 03 April 2012 - 10:47 PM

Hi,

No one has any solution for Vector issue.
Was This Post Helpful? 0
  • +
  • -

#13 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 663
  • View blog
  • Posts: 2,277
  • Joined: 31-December 10

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 05 April 2012 - 10:46 AM

View PostBegineerC++, on 04 April 2012 - 01:47 AM, said:

Hi,

No one has any solution for Vector issue.

Like I have already said, we need to see the function that returns a vector* and where you call the function. Without that, we can only guess as to what's going wrong. I would guess that the function is returning NULL, and then you try to use that vector* and because it points to NULL, you get an exception/error.
Was This Post Helpful? 0
  • +
  • -

#14 BegineerC++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-March 12

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 08 April 2012 - 08:57 PM

No function does not returning NULL as i have mentioned i have done memory debug and if at all it was returning with NULL i should have get same memory issue with Qt Application.i have kept record of memory and verify same memory address in MFC App i am getting values this is of each methylene in vector. that is the reason i am thinking it might be as have to access vector element in MFC in different way.
Was This Post Helpful? 0
  • +
  • -

#15 BegineerC++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-March 12

Re: vector not access from vc++2010 App same code works fine in Qt App.

Posted 08 April 2012 - 09:43 PM

i had used below code for try:
template CArchive& STORE_VECTOR(CArchive& ar, const std::vector& t_vector) { ar << to_store.size(); end = t_vector.end(); // i am getting one element from vector for(std::vector::size_type i = 0; i < t_vector.size(); i++ ar << t_vector[i]; return ar; }
at end = t_vector.end(); line i am getting only one element from t_vector (if suppose 3 elements are present in vector) not end one but 1st one. like if size_type size() const { // return length of sequence return (_Mylast - _Myfirst); } _Mylast shows 1 element which is actually 1st element. _Myfirst shows junck values. this i am getting only inside function not outside if i try to access.
also i ept track of all memory of elements and put in MFC Local it shows all the values this behavior also very weird and i really can not understand.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2