473,396 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

String in MC++

Hello.
I have some class written in C++ and I'm trying to use it in C#. So I've
created new Managed C++ Library in Visual Studio .NET and copied that
code there. But one method takes one parameter of type char*. When I'm
trying to use it in C#, calling it with some string, the compiler gives
some errors. I was also trying to change this char* to String, but the
errors were very similar. Is there any way to do this???

--
Piecu
Nov 15 '05 #1
3 1632
the problem maybe is that the call of your method have a
pointer, char * , and need to be in 'unsafe' block of
code. if you write
unsafe{
myfunction(ref mystring);

}

maybe works. remember to configure in the C# proyect
properties to accept unsafe blocks of code
-----Original Message-----
Hello.
I have some class written in C++ and I'm trying to use it in C#. So I'vecreated new Managed C++ Library in Visual Studio .NET and copied thatcode there. But one method takes one parameter of type char*. When I'mtrying to use it in C#, calling it with some string, the compiler givessome errors. I was also trying to change this char* to String, but theerrors were very similar. Is there any way to do this???

--
Piecu
.

Nov 15 '05 #2
If you make the managed code method take a System::String* then in C++ you
can get a wchar_t like this:

System::String* fontName = ....
const wchar_t __pin* szFontName = PtrToStringChars( fontName );

Visual Programming Ltd mail PO Box 22-222, Khandallah, Wellington, New
Zealand site Level 2, 2 Ganges Road, Khandallah, Wellington, New Zealand
phone +64 4 479 1738 fax +64 4 479 1294 web http://www.xmlpdf.com
"Scafe" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...
the problem maybe is that the call of your method have a
pointer, char * , and need to be in 'unsafe' block of
code. if you write
unsafe{
myfunction(ref mystring);

}

maybe works. remember to configure in the C# proyect
properties to accept unsafe blocks of code
-----Original Message-----
Hello.
I have some class written in C++ and I'm trying to use it

in C#. So I've
created new Managed C++ Library in Visual Studio .NET and

copied that
code there. But one method takes one parameter of type

char*. When I'm
trying to use it in C#, calling it with some string, the

compiler gives
some errors. I was also trying to change this char* to

String, but the
errors were very similar. Is there any way to do this???

--
Piecu
.

Nov 15 '05 #3
What error message are you getting?

Pete

"Piecu" <pi***********@go2.pl> wrote in message
news:br**********@nemesis.news.tpi.pl...
Hello.
I have some class written in C++ and I'm trying to use it in C#. So I've
created new Managed C++ Library in Visual Studio .NET and copied that
code there. But one method takes one parameter of type char*. When I'm
trying to use it in C#, calling it with some string, the compiler gives
some errors. I was also trying to change this char* to String, but the
errors were very similar. Is there any way to do this???

--
Piecu

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Daniel Lidström | last post by:
Hi, I'm currently using this method to extract doubles from a string: System::String* sp = S" "; System::String* tokens = s->Trim()->Split(sp->ToCharArray()); m_Northing =...
5
by: Mark Ingram | last post by:
Hi, how can i return an array of strings from an unmanaged c++ dll into a c# application? cheers Mark
2
by: rmathieu | last post by:
Hi, I want to initialize a static String array in MC++. What I want to do is to initialize my String array like the C# way: new String {"11", "22"} but I could not find an equivalent in MC++. The...
6
by: paul reed | last post by:
Hello, I need to retrieve strings that are bounded by special characters from a larger string **item1%%**item2%%**item3%%. What is the most efficient way to do this? Thanks, Paul
1
by: Maxwell | last post by:
Hello, I having having oodles of trouble using the std lib in my MC++ (VS.NET 2003) Class library. I figured out a simple sample to reproduce the errors I am having. Create a MC++ (VS.NET 2003)...
1
by: Simon | last post by:
Hi, I have a class that does not seem to work. I cannot see the problem, and the "fix" I have found does not help me understand what the problem was I know I don't need a copy constructor but...
2
by: sovarschizsuzsa | last post by:
Hy! I have written a MC++ wrapper DLL file for use in a C# project. This wrapper DLL is built on a C DLL. I have the following functions in the C DLL: int First(char* a1, char* a2, void* *a3,...
3
by: Kevin Frey | last post by:
I am porting Managed C++ code from VS2003 to VS2005. Therefore adopting the new C++/CLI syntax rather than /clr:oldSyntax. Much of our managed code is concerned with interfacing to native C++...
6
by: Arnshea | last post by:
(apologies for the crosspost) I'm working with an MFC based COM object. From C# I'd like to be able to call a method on the COM object that takes a string array and modifies the contents. Is...
14
by: Jamenson | last post by:
Hi everyone! I want to convert strings like "LEONARDO DI CAPRIO" to "Leonardo di Caprio". The function StrConv converts to "Leonardo Di Caprio" and we think it is innapropriated. Any help...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.