memcpy equivelant in C#

  • Thread starter Thread starter Torben S. Petersen
  • Start date Start date
T

Torben S. Petersen

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
 
See the class System.Buffer and its method, BlockCopy, this might help you,
Good Luck !
 
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
 
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
 
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"
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


.
 
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.
 
Back
Top