L
Lonewolf
Hi,
I'm not sure if this has been asked before so please pardon me if this
is a repeated question. Basically I have some performance critical
directshow codes which is implemented in native, unmanaged C++. I have
written a managed wrapper for it using C++/CLI. problem comes when I try
to pass a C# string over to the DLL via C++/CLO. Basically I have a
textbox in the C# GUI, and I declared my C++/CLI property as follows.
C++/CLI property
~~~~~~~~~~~~~~
public ref class CMR
{
property String^ SetFileName
{
void set(String^ value)
{
Debug::Write("\n FileName passed in is "+ value);
pNativeClass->(value->ToCharArray());
}
};
};
C# code
~~~~~~~~
mref is reference to C++/CLI assembly
CMR mref;
mref.SetFileName=txtboxFileName.Text;
whenever I tried to do that, the program would give a null reference
exception. I never saw the debug string. So I guess it failed when
trying to read the String value. Now, the question is, both C# and
C++/CLI are part of the .NET framework, why is it that the native string
class used by both are not compatible?? Is there some .NET string class
which is supported by all .NET lang? the C++/CLI assembly has to work
with all .NET lang, so the property for the file name has to be able to
process the value passed in without knowing what lang is being used.
Coudl someone please enlighten me ?
in the native class, I also need to convert from String^ to the normal
WCHAR buffer, what is the way to do it? those examples I found are all
related to MC++, I don't know what is the correct C++/CLI way of doing
it. Basically the native cdoe copies the file name into a unmanaged
array declared as
WCHAR szFilename[MAX_PATH];
I tried ToCharArray but that is converting to a wchar_t array, not a
WCHAR*, and the compiler complained. could some kind souls please
enlughten me on this as well?
I could pass a C# string to a WCHAR buffer, that's not an issue, but it
involves the ugly Marshalling code, I want to make C# development as
painless as possible by handling all the conversion from managed data
type to native C/C++ data type within C++/CLI. It amazed me that desite
the CLI claim in C++/CLI, the String class is not compatible with C#'s
string.
I'm not sure if this has been asked before so please pardon me if this
is a repeated question. Basically I have some performance critical
directshow codes which is implemented in native, unmanaged C++. I have
written a managed wrapper for it using C++/CLI. problem comes when I try
to pass a C# string over to the DLL via C++/CLO. Basically I have a
textbox in the C# GUI, and I declared my C++/CLI property as follows.
C++/CLI property
~~~~~~~~~~~~~~
public ref class CMR
{
property String^ SetFileName
{
void set(String^ value)
{
Debug::Write("\n FileName passed in is "+ value);
pNativeClass->(value->ToCharArray());
}
};
};
C# code
~~~~~~~~
mref is reference to C++/CLI assembly
CMR mref;
mref.SetFileName=txtboxFileName.Text;
whenever I tried to do that, the program would give a null reference
exception. I never saw the debug string. So I guess it failed when
trying to read the String value. Now, the question is, both C# and
C++/CLI are part of the .NET framework, why is it that the native string
class used by both are not compatible?? Is there some .NET string class
which is supported by all .NET lang? the C++/CLI assembly has to work
with all .NET lang, so the property for the file name has to be able to
process the value passed in without knowing what lang is being used.
Coudl someone please enlighten me ?
in the native class, I also need to convert from String^ to the normal
WCHAR buffer, what is the way to do it? those examples I found are all
related to MC++, I don't know what is the correct C++/CLI way of doing
it. Basically the native cdoe copies the file name into a unmanaged
array declared as
WCHAR szFilename[MAX_PATH];
I tried ToCharArray but that is converting to a wchar_t array, not a
WCHAR*, and the compiler complained. could some kind souls please
enlughten me on this as well?
I could pass a C# string to a WCHAR buffer, that's not an issue, but it
involves the ugly Marshalling code, I want to make C# development as
painless as possible by handling all the conversion from managed data
type to native C/C++ data type within C++/CLI. It amazed me that desite
the CLI claim in C++/CLI, the String class is not compatible with C#'s
string.