无法将DWORD64或double转换为char *以通过套接字发送 [英] Can't convert DWORD64 or double to char* to send over socket

查看:64
本文介绍了无法将DWORD64或double转换为char *以通过套接字发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些代码来读取可用磁盘空间,如下所示:

I am writing some code to read the free disk space as follows:

//declare the params to pass into the method to check disk usage
		ULARGE_INTEGER uliFreeBytesAvailable;
		ULARGE_INTEGER uliTotalNumberOfBytes;
		ULARGE_INTEGER uliTotalNumberOfFreeBytes;

		//init the params to pass into the method to check disk usage
		uliFreeBytesAvailable.QuadPart = 0L;
		uliTotalNumberOfBytes.QuadPart = 0L;
		uliTotalNumberOfFreeBytes.QuadPart = 0L;

		if(GetDiskFreeSpaceEx(lpDirectoryName,
			&uliFreeBytesAvailable,
			&uliTotalNumberOfBytes,
			&uliTotalNumberOfFreeBytes))



然后,我得到uliTotalNumberOfFreeBytes.QuadPart,它是一个DWORD64,我需要使用socket :: send方法通过Windows套接字将其发送到另一个应用程序,要求将数据作为char *发送.请有人帮助我将DWORD64转换为char *,或告诉我是否有替代方法可以执行此操作.

我可以将DWORD64转换为双精度型,因此,如果有人可以告诉我如何将双精度型转换为char *,这也将非常有用:)



I then get the uliTotalNumberOfFreeBytes.QuadPart which is a DWORD64 and I need to send it to another application via a windows socket using the socket::send method requires the data to be sent as a char*. Please could somebody help me to convert the DWORD64 to a char*, or tell me if there is an alternative option for doing this.

I can conver the DWORD64 to a double so if someone could tell me how to convert a double to a char* that would be very helpful too :)

推荐答案

您好,

如果您知道自己在做什么,则可以使用静态演员表
(char *)TotalNumFree等.

通过发送时确保大小正确(sizeof(xyz))

干杯,

AT
Hi,

If you know what you''re doing you could use a static cast
(char *)TotalNumFree etc.

Make sure you got the size right when sending though (sizeof(xyz))

Cheers,

AT


socket::sendchar*参数是指向应发送的数据存储器的指针.使用强制转换时,您可以传递任何类型的数据的地址:

The char* parameter of socket::send is a pointer to the data memory that should be send. You can pass the address of any kind of data when using a cast:

ULARGE_INTEGER val = 123;;
send(s, (char *)&val, sizeof(ULARGE_INTEGER), 0);


这篇关于无法将DWORD64或double转换为char *以通过套接字发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆