CString in Managed and Unmanaged C++ 
Author Message
 CString in Managed and Unmanaged C++

If this question is a repeat, I apologize.  I did search before posting.

I have a function in a VC++ 6.0 dll as follows:
    BOOL LoadSystemList(CString& sBuf, int iControlId);

I am using DllImport in a managed C++ 7.0 dll to expose and call the
function, but the reference to the CString is throwing me for a loop.  Any
ideas on how I can return CString to the managed C++ code?

Ken



Mon, 19 Sep 2005 03:48:03 GMT  
 CString in Managed and Unmanaged C++


Quote:
> If this question is a repeat, I apologize.  I did search before posting.

> I have a function in a VC++ 6.0 dll as follows:
>     BOOL LoadSystemList(CString& sBuf, int iControlId);

> I am using DllImport in a managed C++ 7.0 dll to expose and call the
> function, but the reference to the CString is throwing me for a loop.  Any
> ideas on how I can return CString to the managed C++ code?

You cannot.  You will have to discover the
underlying purpose and intended usage for
that interface and redesign it.  There is
only one string type in the standard CLR,
and it is not anything like CString.

It will help, while considering that
redesign, to recognize that there is no
"managed C++ code" per se.  There are
managed and unmanaged classes, which
distinction is determined by the data
types held or contained, not by the
code that effects the class behavior.

--
-Larry Brasfield
(address munged, s/sn/h/ to reply)



Mon, 19 Sep 2005 03:58:21 GMT  
 CString in Managed and Unmanaged C++


Quote:
> You cannot.  You will have to discover the
> underlying purpose and intended usage for
> that interface and redesign it.  There is
> only one string type in the standard CLR,
> and it is not anything like CString.

> It will help, while considering that
> redesign, to recognize that there is no
> "managed C++ code" per se.  There are
> managed and unmanaged classes, which
> distinction is determined by the data
> types held or contained, not by the
> code that effects the class behavior.

> --
> -Larry Brasfield
> (address munged, s/sn/h/ to reply)

Thanks for the quick reply.  The unmanaged function can be revised.  The
only requirement is to return a string to the managed class.  Ideas?

Ken



Mon, 19 Sep 2005 04:06:38 GMT  
 CString in Managed and Unmanaged C++


...

Quote:


> Thanks for the quick reply.  The unmanaged function can be revised.  The
> only requirement is to return a string to the managed class.  Ideas?

So, the CString reference was actually just
an out parameter. (?)  That is a much happier
circumstance than something like "Provide a
reference to something that will be modified
in place by subsequent calls."

You will want the C# signature to be
  bool LoadSystemList(ref String sBuf, int iControlId);
which in (managed) C++ will be
  System::Boolean LoadSystemList(
    System::String * * sBuf, System::Int32 iControlId);
You can use the Marshall class, in System::Runtime::
InteropServices, to copy the CString content out.
The PtrToStringUni(...) method is probably best.

--
-Larry Brasfield
(address munged, s/sn/h/ to reply)



Mon, 19 Sep 2005 04:46:51 GMT  
 
 [ 4 post ] 

 Relevant Pages 

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

2. Performance of unmanaged C++ in a managed C++ app

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

4. Inherit unmanaged c++ classes from .Net platform (managed c++ or c#)

5. C# client crashs when calling into Managed C++ which calls unmanaged c++ function

6. managed c++ vs unmanaged c++

7. How to pass a function pointer from Managed C++ to unmanaged c++

8. Managed C++ and Unmanaged C++ and Inheritance

9. Interoperability UnManaged C++, Managed C++, C#

10. How to call managed C++ DLL from unmanaged C++ EXE

11. debugging unmanaged c++ from a managed c++ class library

12. Visual form inheritance from base form implemented in C++ with Managed Extensions (migrated from unmanaged C++)

 

 
Powered by phpBB® Forum Software