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

memcpy equivelant in C#

Hi,

I am currently trying to re-write some VC++ code into C#
but are having problems finding a way to convert the C++
memcpy into C#. The following is part of the code:

static int search_count;
static CFGINFO SearchInfo[MAX_DEVICE_NUM];

typedef struct _DS_INFO{
DWORD apid;
WORD hwid;
WORD flag;
DWORD real_ip_addr;
DWORD pseudo_ip_addr;
DWORD host_ip_addr;
BYTE mac[MACLEN];
}DS_INFO, *PDS_INFO;

typedef struct _CONFIGINFO {
DS_INFO ds_info;
DS_HANDLE dshdl;
PIFCONFIGINFO p_ifconfig;
int ipcfgsetting;
PSERPARMITEM pserial_info;
int baud_index;
BYTE port_type;
char svr_name[16];
int watchdog;
int operation_mode;
PKERNELINFO pkernel_info;
int system_changed;
char new_passwd[17];
char new_privatekey[16];
} CFGINFO, *PCFGINFO;
int CALLBACK EnumSearchProc(PDS_INFO dsinfo)
{
if (dsinfo == NULL)
return true;

if (dsinfo->hwid == 802)
{
memcpy(&SearchInfo
search_count].ds_info, dsinfo, sizeof(DS_INFO));
search_count++;
}

return true;
}

Any help to convert the memcpy to a C# equivelant would be
highly appreciated.

Thank you

Torben
Nov 16 '05 #1
5 5273
See the class System.Buffer and its method, BlockCopy, this might help you,
Good Luck !

"Torben S. Petersen" <an*******@discussions.microsoft.com> wrote in message
news:17****************************@phx.gbl...
Hi,

I am currently trying to re-write some VC++ code into C#
but are having problems finding a way to convert the C++
memcpy into C#. The following is part of the code:

static int search_count;
static CFGINFO SearchInfo[MAX_DEVICE_NUM];

typedef struct _DS_INFO{
DWORD apid;
WORD hwid;
WORD flag;
DWORD real_ip_addr;
DWORD pseudo_ip_addr;
DWORD host_ip_addr;
BYTE mac[MACLEN];
}DS_INFO, *PDS_INFO;

typedef struct _CONFIGINFO {
DS_INFO ds_info;
DS_HANDLE dshdl;
PIFCONFIGINFO p_ifconfig;
int ipcfgsetting;
PSERPARMITEM pserial_info;
int baud_index;
BYTE port_type;
char svr_name[16];
int watchdog;
int operation_mode;
PKERNELINFO pkernel_info;
int system_changed;
char new_passwd[17];
char new_privatekey[16];
} CFGINFO, *PCFGINFO;
int CALLBACK EnumSearchProc(PDS_INFO dsinfo)
{
if (dsinfo == NULL)
return true;

if (dsinfo->hwid == 802)
{
memcpy(&SearchInfo
search_count].ds_info, dsinfo, sizeof(DS_INFO));
search_count++;
}

return true;
}

Any help to convert the memcpy to a C# equivelant would be
highly appreciated.

Thank you

Torben

Nov 16 '05 #2
Since your structure uses pointer variables and the sizeof operator, why
not use it in the unsafe context and let everything remain as it is ?

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Hi J.V,

Since I'm not very familiar with C++ syntax and have only
been programming C# for about 6 month it would be great if
you could provide me with an example of what you suggest.

Any help is very much appreciated!.

Thank you,

Torben
-----Original Message-----
Since your structure uses pointer variables and the sizeof operator, whynot use it in the unsafe context and let everything remain as it is ?
with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!
.

Nov 16 '05 #4
Since I'm not very familiar with C++ syntax and have only
been programming C# for about 6 month it would be great if
you could provide me with an example of what you suggest.

Any help is very much appreciated!.

Thank you,

Torben
-----Original Message-----
See the class System.Buffer and its method, BlockCopy, this might help you,Good Luck !

"Torben S. Petersen" <an*******@discussions.microsoft.com> wrote in messagenews:17****************************@phx.gbl...
Hi,

I am currently trying to re-write some VC++ code into C#
but are having problems finding a way to convert the C++
memcpy into C#. The following is part of the code:

static int search_count;
static CFGINFO SearchInfo[MAX_DEVICE_NUM];

typedef struct _DS_INFO{
DWORD apid;
WORD hwid;
WORD flag;
DWORD real_ip_addr;
DWORD pseudo_ip_addr;
DWORD host_ip_addr;
BYTE mac[MACLEN];
}DS_INFO, *PDS_INFO;

typedef struct _CONFIGINFO {
DS_INFO ds_info;
DS_HANDLE dshdl;
PIFCONFIGINFO p_ifconfig;
int ipcfgsetting;
PSERPARMITEM pserial_info;
int baud_index;
BYTE port_type;
char svr_name[16];
int watchdog;
int operation_mode;
PKERNELINFO pkernel_info;
int system_changed;
char new_passwd[17];
char new_privatekey[16];
} CFGINFO, *PCFGINFO;
int CALLBACK EnumSearchProc(PDS_INFO dsinfo)
{
if (dsinfo == NULL)
return true;

if (dsinfo->hwid == 802)
{
memcpy(&SearchInfo
search_count].ds_info, dsinfo, sizeof(DS_INFO));
search_count++;
}

return true;
}

Any help to convert the memcpy to a C# equivelant would be highly appreciated.

Thank you

Torben

.

Nov 16 '05 #5
In that case... just copy it with the assignment operator (=).

I fell for you if you are trying to convert a lot of C++ code to C# line for
line with little experience with both. C++ and C# don't always work the same
way.

Good luck. :)

Etienne Boucher.
Nov 16 '05 #6

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

Similar topics

13
by: franky.backeljauw | last post by:
Hello, following my question on "std::copy versus pointer copy versus member copy", I had some doubts on the function memcpy, as was used by tom_usenet in his reply. - Is this a c++ standard...
5
by: manya | last post by:
Ok, it's been a while since I've done the whole memcpy stuff with C++ and I'm having a hard time remembering everything. I hope, however, that you can help me with my problem. I memcpy a...
35
by: Christopher Benson-Manica | last post by:
(if this is a FAQ or in K&R2, I didn't find it) What parameters (if any) may be 0 or NULL? IOW, which of the following statements are guaranteed to produce well-defined behavior? char src;...
16
by: Amarendra GODBOLE | last post by:
Hi, I am a bit confused over the correct usage of memcpy(). Kindly help me clear the confusion. The linux manpage for memcpy(3) gives me the following prototype of memcpy(3): #include...
33
by: Case | last post by:
#define SIZE 100 #define USE_MEMCPY int main(void) { char a; char b; int n; /* code 'filling' a */
6
by: myhotline | last post by:
hi all im very confused about using memcpy and i have three questions....memcpy takes a pointer to src and a pointer to dest and copies src to destination...but im very confuzed about when to...
18
by: Mark | last post by:
Hi List, I want to write a function to copy some data out of a hardware buffer. The hardware can change the contents of this buffer without it being written to by my function. I want to use...
47
by: Nathan Sokalski | last post by:
VB.NET has a function, Asc(), that gets the Ascii value of a character. I am attempting to find an equivelant function for C#. Can somebody help me here? -- Nathan Sokalski njsokalski@hotmail.com...
18
by: sam | last post by:
(newbie)Technically what's the difference between memset() and memcpy() functions?
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
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...

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.