473,597 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pass a value from unmanaged code to managed code

Im very new to coding in C++ so use to coding in C#. My question is
how to pass some values (string) from unmanaged code to managed code. I
have two source files on a win32 console application one I used #pramga
managed to change to managed code but I need to get the values from the
unmanaged code and pass it to the managed code. Thanks...

Jun 16 '06 #1
4 2851
> Im very new to coding in C++ so use to coding in C#. My question is
how to pass some values (string) from unmanaged code to managed code. I
have two source files on a win32 console application one I used #pramga
managed to change to managed code but I need to get the values from the
unmanaged code and pass it to the managed code. Thanks...


Is the unmanaged string unicode?
if so, you can simply pass it to the System.String constructor.
otherwise you could use the PtrToStringAnsi method of the Marshal class
in the System.Runtime. InteropServices namespace.

--

Kind regards,
Bruno van Dooren
br************* *********@hotma il.com
Remove only "_nos_pam"
Jun 16 '06 #2
Hi Bruno!
Is the unmanaged string unicode?
if so, you can simply pass it to the System.String constructor.
You can also pass ANSI-Strings to the String constructor.
otherwise you could use the PtrToStringAnsi method of the Marshal class
in the System.Runtime. InteropServices namespace.


PtrToStringANsi is only helpfull in converting "String" into ANSI! Not
vice-versa!

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Jun 16 '06 #3
Hello Jochen,
Is the unmanaged string unicode?
if so, you can simply pass it to the System.String constructor.

You can also pass ANSI-Strings to the String constructor.


didn't know that. never tried it.
otherwise you could use the PtrToStringAnsi method of the Marshal class
in the System.Runtime. InteropServices namespace.

PtrToStringANsi is only helpfull in converting "String" into ANSI! Not
vice-versa!


MSDN doesn't think so :-)

<quote>
Copies all characters up to the first null from an unmanaged ANSI string to
a managed String. Widens each ANSI character to Unicode.
[Visual Basic] Overloads Public Shared Function PtrToStringAnsi (IntPtr) As
String
[C#] public static string PtrToStringAnsi (IntPtr);
</quote>

--

Kind regards,
Bruno van Dooren
br************* *********@hotma il.com
Remove only "_nos_pam"
Jun 16 '06 #4
Hi Bruno!
PtrToStringAN si is only helpfull in converting "String" into ANSI! Not
vice-versa!


MSDN doesn't think so :-)


Upps.. yes I forgot that there are two functions... sorry...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Jun 17 '06 #5

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

Similar topics

16
14106
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the byteArray and afterwards see the changes in C#. (if you wanna know more details: the goal is to write the content of an existing char-array in c++ precisely into the passed byteArray, so that after the function has proceded the content of the...
1
2838
by: Alexander Arlievsky | last post by:
Hi, I have mixed mode dll, which contains files with managed objects written in MC++, and files with regular "C" functions. One of those functions receives function pointer as parameter. I want to pass to it delegate to managed object method. I know how to do it from C# - DllImport etc. I suspect I can declare "stub" method using those attributes, so it will actually reference "C" method, and call this stub, letting marshaler to do the...
5
2710
by: apm | last post by:
Any and all: Is there an efficient way to pass a large array from .NET to COM? Can references (or pointer) be passed from COM to NET and NET to COM without the object it refers to being copied? Thanks in advance. David
7
8221
by: Klaus Bonadt | last post by:
I have an existing VC6 application using the MFC. I am able to pass CString and other parameters from such a VC6 dll to an unmanaged MFC dll (compiled in Visual Studio .NET). Now I want to use .Net functionality, i.e. calling methods in managed code. How do I pass CString variables for input and output usage, i.e. providing and retrieving char arrays? Regards, Klaus
1
1637
by: Sparhawk | last post by:
Hi, my company is going to migrate a large VC++ application to .NET to make use of Windows Forms (the old class library is not updated any more). We are not planning to migrate the rest of the code which works well. I understand the basic concept: our code is unmanaged, Windows Forms is Managed and Unmanaged may not call Managed code. I read about Wrappers, PInvoke, Runtime Callable Wrappers for COM and about It just
0
954
by: stanley | last post by:
hello all, 1 - is it posiblle to pass ADO Recordset as a parameter from C++ managed code (.Net MC++) to a C++ unmanaged code (the old existing code) function?? how can i do it using the P-Invoce mechanism? if it's not posibble - how can i call an exisiting C++ unmanaged function that expect me to pass a Recordset parameter??? 2- the same question but i need to pass the unmanaged function an IUnknown* parameter(hold the connection to the...
5
1500
by: | last post by:
Hi, In our system we get image buffers through a native dll as void*. We want to manage several of this blocks by C# objects an pass them wen needed to a native image processing library. What is the best way to do this? Can I just declare a unsafe pointer as member of a class? Best regards
6
4111
by: Stephen Walch | last post by:
Our application environment consists of three basic layers: 1. Third-party unmanaged DLLs that were written before the CLR was invented and maintain a significant amount of information (including memory management and connection pooling constructs) as static variables which were intended to scoped to the process. 2. Managed C++ assemblies (.NET 1.1) that wrap the unmanaged DLLs as nice neat classes with managed interfaces.
9
3542
by: =?Utf-8?B?RWR3YXJkUw==?= | last post by:
I would greatly appreciate some help on passing managed object into unmanaged code. I need to pass a reference (address of) of a managed class into unmanaged code (written by a thrid party). The 3rd party unmanaged DLL will pass this reference into standard Win32 unmanaged static callback function in my code. Inside this unmanaged callback function I need to cast this unmnaged pointer that I have received from 3rd party back into the...
0
7893
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,...
1
8040
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,...
0
8259
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5847
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 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...
0
3889
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3932
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2408
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
1
1495
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1243
bsmnconsultancy
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...

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.