473,465 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C# String conversion

Hi, I'm having some difficulty converting a String to a std::basic_string
(c++).

I've tried using StringBuilder and Marshal.LPxxxx , no luck.

I consistently get AccessViolation errors.

I've been reading all day but I can't seem to find the same problem posted
anywhere.

bool NNSMCAPI::Client::initialize(class std::basic_string<unsigned
short,struct std::char_traits<unsigned short>,class std::allocator<unsigned
short const &)

Can anyone help me with this issue?

thanks!

Sep 23 '08 #1
3 1886
It wont work becuase Marshal.LPxxxx does not convert to basic_string, but
only gets you a pointer to the raw string charcters in memory.

You can try using a wrapper around your function which takes LPTSTR, this
way you can use Marshal.LPxxxx

---------
- G Himangi, LogicNP Software http://www.ssware.com
Shell MegaPack: GUI Controls For Drop-In Windows Explorer like File/Folder
Browsing Functionality (.Net & ActiveX Editions).
EZNamespaceExtensions: Develop namespace extensions rapidly in .Net and
MFC/ATL/C++
EZShellExtensions: Develop all shell extensions,explorer bars and BHOs
rapidly in .Net & MFC/ATL/C++
---------
"Neomite" <Ne*****@discussions.microsoft.comwrote in message
news:0B**********************************@microsof t.com...
Hi, I'm having some difficulty converting a String to a std::basic_string
(c++).

I've tried using StringBuilder and Marshal.LPxxxx , no luck.

I consistently get AccessViolation errors.

I've been reading all day but I can't seem to find the same problem posted
anywhere.

bool NNSMCAPI::Client::initialize(class std::basic_string<unsigned
short,struct std::char_traits<unsigned short>,class
std::allocator<unsigned
short const &)

Can anyone help me with this issue?

thanks!

Sep 24 '08 #2
I read a few similiar posts that talked about using StringBuilder? Are you
familiar with this approach?

"G Himangi" wrote:
It wont work becuase Marshal.LPxxxx does not convert to basic_string, but
only gets you a pointer to the raw string charcters in memory.

You can try using a wrapper around your function which takes LPTSTR, this
way you can use Marshal.LPxxxx

---------
- G Himangi, LogicNP Software http://www.ssware.com
Shell MegaPack: GUI Controls For Drop-In Windows Explorer like File/Folder
Browsing Functionality (.Net & ActiveX Editions).
EZNamespaceExtensions: Develop namespace extensions rapidly in .Net and
MFC/ATL/C++
EZShellExtensions: Develop all shell extensions,explorer bars and BHOs
rapidly in .Net & MFC/ATL/C++
---------
"Neomite" <Ne*****@discussions.microsoft.comwrote in message
news:0B**********************************@microsof t.com...
Hi, I'm having some difficulty converting a String to a std::basic_string
(c++).

I've tried using StringBuilder and Marshal.LPxxxx , no luck.

I consistently get AccessViolation errors.

I've been reading all day but I can't seem to find the same problem posted
anywhere.

bool NNSMCAPI::Client::initialize(class std::basic_string<unsigned
short,struct std::char_traits<unsigned short>,class
std::allocator<unsigned
short const &)

Can anyone help me with this issue?

thanks!



Sep 24 '08 #3
Yes, but that works only if data flow is from called function to yourself.
In this case, if i understand correctly, its the other way round.

---------
- G Himangi, LogicNP Software http://www.ssware.com
Shell MegaPack: GUI Controls For Drop-In Windows Explorer like File/Folder
Browsing Functionality (.Net & ActiveX Editions).
EZNamespaceExtensions: Develop namespace extensions rapidly in .Net and
MFC/ATL/C++
EZShellExtensions: Develop all shell extensions,explorer bars and BHOs
rapidly in .Net & MFC/ATL/C++
---------

"Neomite" <Ne*****@discussions.microsoft.comwrote in message
news:F5**********************************@microsof t.com...
>I read a few similiar posts that talked about using StringBuilder? Are you
familiar with this approach?

"G Himangi" wrote:
>It wont work becuase Marshal.LPxxxx does not convert to basic_string, but
only gets you a pointer to the raw string charcters in memory.

You can try using a wrapper around your function which takes LPTSTR, this
way you can use Marshal.LPxxxx

---------
- G Himangi, LogicNP Software http://www.ssware.com
Shell MegaPack: GUI Controls For Drop-In Windows Explorer like
File/Folder
Browsing Functionality (.Net & ActiveX Editions).
EZNamespaceExtensions: Develop namespace extensions rapidly in .Net and
MFC/ATL/C++
EZShellExtensions: Develop all shell extensions,explorer bars and BHOs
rapidly in .Net & MFC/ATL/C++
---------
"Neomite" <Ne*****@discussions.microsoft.comwrote in message
news:0B**********************************@microso ft.com...
Hi, I'm having some difficulty converting a String to a
std::basic_string
(c++).

I've tried using StringBuilder and Marshal.LPxxxx , no luck.

I consistently get AccessViolation errors.

I've been reading all day but I can't seem to find the same problem
posted
anywhere.

bool NNSMCAPI::Client::initialize(class std::basic_string<unsigned
short,struct std::char_traits<unsigned short>,class
std::allocator<unsigned
short const &)

Can anyone help me with this issue?

thanks!



Sep 25 '08 #4

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

Similar topics

10
by: Marcin Kalicinski | last post by:
Why string literals are regarded as char * not as const char *? (1) void f(char *); (2) void f(const char *); f("foo") will call version (1) of function f. I understand that the exact type...
2
by: Thomas Matthews | last post by:
Hi, I'm working with Borland C++ Builder 6.2. My project uses the std::string class. However, Borland in its infinite wisdom has its own string class, AnsiString. To make my life easier, I...
12
by: ABeck | last post by:
Hello List, I have ar more or less academical question. Can there arise runtime errors in a program, if the include of <string.h> has been forgotten? If all the arguments to the functions of...
6
by: Marco Herrn | last post by:
Hi, I need to serialize an object into a string representation to store it into a database. So the SOAPFormatter seems to be the right formatter for this purpose. Now I have the problem that...
6
by: tommaso.gastaldi | last post by:
Hi, does anybody know a speedy analog of IsNumeric() to check for strings/chars. I would like to check if an Object can be treated as a string before using a Cstr(), clearly avoiding the time...
4
by: Russell Warren | last post by:
I've got a case where I want to convert binary blocks of data (various ctypes objects) to base64 strings. The conversion calls in the base64 module expect strings as input, so right now I'm...
10
by: =?Utf-8?B?RWxlbmE=?= | last post by:
I am surprised to discover that c# automatically converts an integer to a string when concatenating with the "+" operator. I thought c# was supposed to be very strict about types. Doesn't it seem...
5
by: jeremyje | last post by:
I'm writing some code that will convert a regular string to a byte for compression and then beable to convert that compressed string back into original form. Conceptually I have.... For...
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++...
10
by: Dancefire | last post by:
Hi, everyone, I'm writing a program using wstring(wchar_t) as internal string. The problem is raised when I convert the multibyte char set string with different encoding to wstring(which is...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.