Referencing data from unmanaged code to managed code in C++ Wrapper class 
Author Message
 Referencing data from unmanaged code to managed code in C++ Wrapper class

Hi.

I've been writting C++ wrapper code between managed/unmanaged code
for unmanaged C++ <-> C++ wrapper <-> VB.NET interactions,

here is my code.

void myfunc(String *s)
{
    char *str;
    IntPtr ptr;

    ptr = Marshal::StringToHGlobalAuto(s);
    if (ptr != 0) {
        str = (char *)ptr.ToPointer();
        m_pArg->CreateString(str);
        Marshal::FreeHGlobal(ptr);
    }
    return;

Quote:
}

I just want to read the content of String s.
unmanaged c++ function (m_pArg->CreateString()) make a copy of it.
but, I found the above sample code and couldn't find a method of reading the
contect of String class.

here is my Question.
Must I allocate a buffer in unmanaged heap to read the contect of managed
String class?
is there any way to "JUST" read the contect of managed String class?

Regards,
Donghyun Kim



Sat, 13 Aug 2005 14:02:40 GMT  
 Referencing data from unmanaged code to managed code in C++ Wrapper class


[Acess String content]

/me would like to learn about it as well. I know you can access the String
char-by-char with String::Chars (resp. the indexer in C#), and I am pretty
sure you will never ever get the chance to write to the String content (
String "Represents an immutable series of characters"). At this time I only
now the method you described (using StringToXXX). I don't know about the
internal representation of the string. I looked around a bit with idlasm,
but the interesting functions (e.g. FastAllocateString, FillString etc.) are
*empty* using ildasm. Don't know what MS does here. If the string
representation is non-linear, e.g. using several fixed-size chunks to avoid
memory fragmenting, I guess there won't be any way to access the data.

^-- {*filter*} speculations, ain't it *g*

- Andre



Sat, 13 Aug 2005 16:48:05 GMT  
 Referencing data from unmanaged code to managed code in C++ Wrapper class
Check out the PtrToStringChars method in vcclr.h (ATL 7.1)

/Thomas

--
Thomas Olsson, Vinga System AB, Sweden
http://www.vinga.se
(Reply adress is invalid to avoid spam)


Quote:
> Hi.

> I've been writting C++ wrapper code between managed/unmanaged code
> for unmanaged C++ <-> C++ wrapper <-> VB.NET interactions,

> here is my code.

> void myfunc(String *s)
> {
>     char *str;
>     IntPtr ptr;

>     ptr = Marshal::StringToHGlobalAuto(s);
>     if (ptr != 0) {
>         str = (char *)ptr.ToPointer();
>         m_pArg->CreateString(str);
>         Marshal::FreeHGlobal(ptr);
>     }
>     return;
> }

> I just want to read the content of String s.
> unmanaged c++ function (m_pArg->CreateString()) make a copy of it.
> but, I found the above sample code and couldn't find a method of reading
the
> contect of String class.

> here is my Question.
> Must I allocate a buffer in unmanaged heap to read the contect of managed
> String class?
> is there any way to "JUST" read the contect of managed String class?

> Regards,
> Donghyun Kim



Sat, 13 Aug 2005 17:30:09 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Possible vc++ bug: using c++ references to managed objects in unmanaged code

2. managed C++ wrapper around unmanaged C++ classes: causing StackOverflow exception

3. Managed C++ wrappers for unmanaged C++ classes

4. Unmanaged code doesn't run properly from managed wrapper

5. Fatal Error C1010 in Mixing Managed C++ and Unmanaged C++ Code

6. calling managed code from unmanaged code

7. Calling managed code from unmanaged Code

8. Extended MAPI in c++ managed code wrapper

9. Debugging into managed c++ DLL that is being used by unmanaged code

10. Managed c++ with unmanaged code Linking problem...

11. Making managed wrapper for legacy unmanaged classes.

12. C++ Dot net: calling managed method from unmanaged code

 

 
Powered by phpBB® Forum Software