PC Review


Reply
Thread Tools Rate Thread

Best practice needed to marshal STL data from managed code to unmanaged code & vice versa

 
 
=?Utf-8?B?Sm9oYW5uZXMgVW5mcmllZA==?=
Guest
Posts: n/a
 
      27th Feb 2004
Problem
Best practice needed to marshal STL data from managed code to unmanaged code & vice vers

Details
managed code is written in managed C++ & accesses the unmanaged code (i.e. lives in a mixed mode DLL
unmanaged code is written in unmanaged C++ & resides in an unmanaged DL
Product used is VS.NET 200

Please tell me what is the best practice for getting and setting data fro
unmanaged to managed part when I have a class with references to STL objects as member
function parameters
For instance if I have the following class in an unmanaged Dll

class UNMAN1_API CUnman1

public
int GetStdString(std::string & strText)
int GetStdVector(std::vector<std::string>& vectText)

int SetStdString(const std::string & strText_p)
int SetStdVector(const std::vector<std::string>& vectText)
}

I can create the class in a managed C++ mixed mode Dll without problems. I searched the Web (Internet) and have found a solution for setting the standard string, whic
looks like follows

int Form2::TestSTL2(void

CUnman1 cUnman1
std::string stdstrText

String *pStrTmp = S"This is a string with more than 15 characters.\r\n"
IntPtr intPtr = Marshal::StringToHGlobalAnsi(pStrTmp);
char *pcTmp = static_cast<char*>(intPtr.ToPointer());

stdstrText = pcTmp

cUnman1.SetStdString(stdstrText)
Marshal::FreeHGlobal(intPtr)

return 0


But it looks strange because when you assign the unmanaged allocated character array to the standar
string, should there not be a new allocation in the standard string class?. Is this kind of processing correct

For the other three function
- int GetStdVector(std::vector<std::string>& vectText)
- int GetStdString(std::string & strText)
- int SetStdVector(const std::vector<std::string>& vectText)
I have not found anything, neither in MSDN nor on the Web

Is there a generic approach how to pass STL objects between both worlds in the mixed mode DLL

Any help / hints would be apreciated

Regards & thanks in advanc
Johannes Unfrie

---------------------------------------------------------------------------
D.I. Johannes Unfrie
Senior Engineer SpeechMagi
Philips Speech Processing
Speech Recognition System
Triesterstrasse 64, P.O. Box 217, A-1101 Vienna, Austri
Tel. +43 1 60101 280
Fax +43 1 60101 414
mail: (E-Mail Removed)
web: www.speechrecognition.philips.co



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Managed referencing non-managed and vice-versa =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?= Microsoft VC .NET 5 6th May 2005 06:31 PM
Drag N Drop from managed -> unmanaged & vice versa Deepak Malkan [Bentley] Microsoft Dot NET Framework Forms 3 15th Mar 2005 01:38 PM
RE: Best practice needed to marshal STL data from managed code to unmanaged code & vice versa =?Utf-8?B?UFNQX1VOSl9NU19OZXdzZ3JvdXBfUmVxdWVzdEBu Microsoft VC .NET 9 6th Apr 2004 02:51 PM
RE: Best practice needed to marshal STL data from managed code to unmanaged code & vice versa Anant Dimri [MSFT] Microsoft VC .NET 0 27th Mar 2004 12:02 AM
Best practice needed to marshal STL data from managed code to unmanaged code & vice versa =?Utf-8?B?UFNQX1VOSl9NU19OZXdzZ3JvdXBfUmVxdWVzdEBw Microsoft VC .NET 0 11th Mar 2004 01:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:35 AM.