Hi,
I have a c# GUI that needs to untimately send its data down to
unmanaged c++. I've decided to do this by having a ref struct in the
CLI layer and have the c# populate this, and then pass it back to the
CLI layer. The CLI layer will then populate the unmanged struct where
the data needs to end up.
Now, my question, I just realized that I'm going to have alot of
strings. I need to have these things end up as char*, but they start
as String^. I'm just thinking about overhead, I was thinking about
Marshalling the strings via Marshal::String ToHGlobalAnsi, but I'm a
little worried about the overhead. Any ideas?
Thanks in advance. 4 4403
"DaTurk" <mm******@hotma il.comwrote in message
news:11******** **************@ l77g2000hsb.goo glegroups.com.. .
Now, my question, I just realized that I'm going to have alot of
strings. I need to have these things end up as char*, but they start
as String^. I'm just thinking about overhead, I was thinking about
Marshalling the strings via Marshal::String ToHGlobalAnsi, but I'm a
little worried about the overhead. Any ideas?
If you don't plan to modify the strings you can use PtrToStringChar s(): http://blogs.msdn.com/slippman/archi...02/147090.aspx
IMO, it's only by profiling that you'll be able to determine if your worries
are warranted or if one method is materially better than another.
Regards,
Will
"DaTurk" <mm******@hotma il.comwrote in message
news:11******** **************@ l77g2000hsb.goo glegroups.com.. .
Hi,
I have a c# GUI that needs to untimately send its data down to
unmanaged c++. I've decided to do this by having a ref struct in the
CLI layer and have the c# populate this, and then pass it back to the
CLI layer. The CLI layer will then populate the unmanged struct where
the data needs to end up.
Now, my question, I just realized that I'm going to have alot of
strings. I need to have these things end up as char*, but they start
as String^. I'm just thinking about overhead, I was thinking about
Marshalling the strings via Marshal::String ToHGlobalAnsi, but I'm a
little worried about the overhead. Any ideas?
Most of the overhead there is in Unicode->ANSI conversion. If the client
can use byte[] (cli::array<Sys tem::Byte>^) instead, it will be faster.
Depends on whether it acts like character strings or raw byte data.
>
Thanks in advance.
On Mar 28, 3:47 pm, "Ben Voigt" <r...@nospam.no spamwrote:
"DaTurk" <mmagd...@hotma il.comwrote in message
news:11******** **************@ l77g2000hsb.goo glegroups.com.. .
Hi,
I have a c# GUI that needs to untimately send its data down to
unmanaged c++. I've decided to do this by having a ref struct in the
CLI layer and have the c# populate this, and then pass it back to the
CLI layer. The CLI layer will then populate the unmanged struct where
the data needs to end up.
Now, my question, I just realized that I'm going to have alot of
strings. I need to have these things end up as char*, but they start
as String^. I'm just thinking about overhead, I was thinking about
Marshalling the strings via Marshal::String ToHGlobalAnsi, but I'm a
little worried about the overhead. Any ideas?
Most of the overhead there is in Unicode->ANSI conversion. If the client
can use byte[] (cli::array<Sys tem::Byte>^) instead, it will be faster.
Depends on whether it acts like character strings or raw byte data.
Thanks in advance.- Hide quoted text -
- Show quoted text -
That's interesting, I didn't think about that. There will still have
to be someconversion at some point as the information I'm going to be
using is going to be coming from a WinForm, so it will be of the type
String^ at the presentation layer. SO I huess the question then
becomes, would it be more costly to convert a String^ -a byte[] at
the presentation layer, or to convert a String^ -a char* down lower
in the program?
That's interesting, I didn't think about that. There will still have
to be someconversion at some point as the information I'm going to be
using is going to be coming from a WinForm, so it will be of the type
String^ at the presentation layer. SO I huess the question then
becomes, would it be more costly to convert a String^ -a byte[] at
the presentation layer, or to convert a String^ -a char* down lower
in the program?
I think the Unicode->ANSI conversion may be implemented differently in .NET
vs native, so that could be a consideration too. Otherwise, I don't see why
either path would be any faster. I would probably hand a String^ to C++ to
keep the presentation layer free from implementation details.
My basic suggestion was that not all char* start life as strings, some are
more "magic numbers". E.g. in SMTP, the "MAIL TO:" command isn't a string
subject to localization, it has to be those exact bytes. Similarly for HTML
tags and the filetype codes used by a lot of programs (GIF does this).
Yours is user-entered though, so you do need the conversion. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Johannes Unfried |
last post by:
Problem
Best practice needed to marshal STL data from managed code to unmanaged code & vice vers
Details
managed code is written in managed C++ & accesses the unmanaged code (i.e. lives in a mixed mode DLL
unmanaged code is written in unmanaged C++ & resides in an unmanaged DL
Product used is VS.NET 200
Please tell me what is the best practice for getting and setting data fro
unmanaged to managed part when I have a class with...
|
by: Dragon |
last post by:
Hello all,
I ran into trouble with GetStdHandle API. When I'm trying to get standard
output with GetStdHandle(-11I), it returns strange values such as 1548,
1876. If I try to WriteConsole() into these handles, it does not work, and
GetLastError returns ERROR_INVALID_HANDLE. But when I CloseHandle() them, it
succeeds! I tested this in VC++ and VBA, and GetStdHandle(-11) always
returns 7, which is valid. There is the same problem with...
|
by: Marcus Kwok |
last post by:
Hello, I am working on cleaning up some code that I inherited and was
wondering if there is anything wrong with my function. I am fairly
proficient in standard C++ but I am pretty new to the .NET managed C++.
It seems to work fine, but everyone knows that programs with errors can
still appear to "work fine" :)
I am working with VS .NET 2003; I am unable to upgrade to 2005 at this
time, so I cannot use the newer syntax or features.
...
|
by: gs |
last post by:
I want to pass a string array to C which uses ansi
in a test, I tried:
unsafe public int ctstAny1dp(String* strOut)
{
private string strMyC = {
"abcdef string 1",
"abcdef string 2",
"abcdef string 3",
"abcdef string 4",
|
by: Goran |
last post by:
Hi all!
I need to pass managed String from to C-style APIs. I see I can use
Marshal::StringToXXX functions. Is this the best we have? I understand
this will allocate a new string and create copy of my String. I want to
pass it as constant (LPCWSTR). I don't need allocation and copying,
just the pointer. Can I have it, pretty please?
In normal C++, we usually have conversion operator or a function to get
it from a string class...
| |
by: sabys |
last post by:
I've been noticing a memory leak with the following sample code
snippet. Can someone please advise.
Have a C# Winforms app with the following code on a button-click
event.
private void button1_Click(object sender, System.EventArgs e)
{
IntPtr p1 = new IntPtr(-1);
string inputStr;
|
by: Kerem Gümrükcü |
last post by:
Hi,
i want to emulate a (synchronous) BroadCastSystemMessage
with EnumWindows and SendMessage. I dont want to use
the BroadcastSystemMessage because it needs the SE_TCB_NAME
Privilege (you dont have this in normal). So i decided to use the
EnumWindows with SendMessage. What i try here is to pass a
WM_USER+1111 with LParam and WParam, pointing to strings.
But when i try to get the strings at the other end with
Marshal.PtrToStringAnsi,
|
by: Dilip |
last post by:
I have cross-posted this question to 3 newsgroups since I am not sure
exactly where it belongs (and some NG's have very less activity).
Apologies in advance for this. I have set the followup to the
dotnet.framework.interop NG but feel free to chage it as appopriate.
I have a question regarding converting a Managed System.String^ to
unmanaged const char*.
I inherited a code that does it like this:
String^ s = "00000";
|
by: Kenneth Porter |
last post by:
I try to be const correct everywhere and found that I can't pass a const
String to this API. Is it going to change the value? Or is the signature
not the best it could be?
I want to write this:
// based on http://msdn.microsoft.com/en-us/magazine/bb985936.aspx
std::string MarshalString (const System::String^ s)
{
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |