473,386 Members | 1,773 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,386 software developers and data experts.

Use windows C++ API in dotnet

Hi

Can someone please tell me how to use C++ API in c# code. Like I have to use
the functionality of memcpy in my C# code. I have to copy the bytes of an
integer variable to 4 character bytes to convert it to string, if there's
any alternative to this in C#, please recommend otherwise tell me how can I
use memcpy itself in C# code.

Regards

Usman Jamil
Jul 4 '06 #1
2 1888

Usman wrote:
Hi

Can someone please tell me how to use C++ API in c# code. Like I have to use
the functionality of memcpy in my C# code. I have to copy the bytes of an
integer variable to 4 character bytes to convert it to string, if there's
any alternative to this in C#, please recommend otherwise tell me how can I
use memcpy itself in C# code.
First of all, there is no C++ Windows API (with the marginal exception
of GDI+) : All the Windows native API is C, not C++.

Next, memcpy is a CRT API, it is not part of the Windows API (whereas
RTLCopyMemory is).

To finish with, in your particular case, your best bet is to use the
BitConverter.GetBytes method.

Arnaud
MVP - VC

Jul 4 '06 #2

"Usman" <us***@advcomm.netwrote in message
news:ey*************@TK2MSFTNGP03.phx.gbl...
Hi

Can someone please tell me how to use C++ API in c# code. Like I have to
use
the functionality of memcpy in my C# code. I have to copy the bytes of an
integer variable to 4 character bytes to convert it to string, if there's
any alternative to this in C#, please recommend otherwise tell me how can
I
use memcpy itself in C# code.
For Win32 API, like CopyMemory, see http://pinvoke.net
The pure .NET version is System.Runtime.InteropServices.Marshal.Copy (still
requires unmanaged code permission).

However, for your need, I don't think CopyMemory is going to help you (it's
the exact windows analogue to the ANSI C runtime function memcpy).

If you are ok with using the machine byte ordering, you can just use an
unsafe code block and cast a pointer (simplest, fastest).
For verifiability,
create a MemoryStream
use a BinaryWriter to write your data
use the MemoryStream's ToArray() method to get the raw bytes.

In reverse, you can construct a memory stream from an array of bytes, then
use BinaryReader to get back typed variabled.

However, this seems very expensive.

Does anyone know of any method for doing this in verifiable code (not
expecting to see the insides of references, only value types) without
creating a bunch of extra objects? I know you could reuse the same
BinaryWriter/MemoryStream by calling Seek(), but it will still allocate a
new byte[] for each call to ToArray, right?
>
Regards

Usman Jamil


Jul 4 '06 #3

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

Similar topics

5
by: Eric Chong | last post by:
I created a Windows Service in C# that requires to get passed command arguments like a Console App. I noticed that there is an option "Start parameters" text box in the property of a Windows...
1
by: Codemonkey | last post by:
Hi, Sorry for the cross group post, but I couldn't find a group that deals with threading in .net. Anyway, I've noticed a difference in the way my program acts on Windows 98 than it does on...
3
by: Nick | last post by:
I am working a new application...well actually a series of applications for my company. They want internal users to be able to go to a site and everything regarding security is transparent,...
8
by: Bill Sonia | last post by:
I've written a Windows Service to send e-mails on events like OnStart, OnStop, OnShutDown using System.Web.Mail. It works for everything but OnShutdown. My guess is that for OnShutDown, once my...
3
by: Harry Simpson | last post by:
Windows Server 2003 is supposed to include Framework 1.1 right. I don't have it here but have reports that the web is not running. The users say that the %COMPUTERNAME%\ASPNET user doesn't exist....
4
by: bob lambert | last post by:
Help I am trying to deploy to another pc a vb.net std 2002 windows form application. I am confused. I created a project - windows form I built form, compiled and debugged. I created a...
2
by: Val3 | last post by:
Hi all. I need to build dll(s) and windows services using VB .NET 2005 Express. When I make File/New project the windows contain only Windows application, Windows control library, Console...
3
by: Mark Findlay | last post by:
When programming reads of the Windows Registry, do the registry keys and values need to be localized for international use? For example, do I need to convert the key name...
7
by: Alice Wong | last post by:
I am setting up my Web ASP.net application to connect to Sql server using windows authentication. I set up IIS to have integrated windows authenication and sql to allow Windows authentication....
9
by: =?Utf-8?B?RGFuaWVs?= | last post by:
Hi, I downloaded the sample application that the Microsoft video ASPNETAJAXForWinMobile described but it doesn't work on my Windows Mobile 6 emulator. After enabling the script error reporting...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.