在VB中用WM_COPYDATA向VC程序发送一个Type,但遇到double数值就出错!!
Look
'VB+++++++++++++++++++++++++++++++++++
Private Declare Function CopyDataSendMessage Lib "user32" Alias "SendMessageA" (ByVal WndID As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As COPYDATASTRUCT) As LongPublic Type COPYDATASTRUCT
dwData As Long
cbData As Long
lpData As Long
End Type
Public Type TPosInfo
MCTNumber As Long
Longitude As Double
Latitude As Double
PositionTime As Long
ErrorType As Integer
End TypePublic Function NotifyPosInfo(MCTNumber As Long, Longitude As Double, Latitude As Double, PositionTime As Long, Optional ErrorType As Integer = 0) As Long
Dim pi As TPosInfo
Dim cs As COPYDATASTRUCT
With pi
.MCTNumber = MCTNumber
.Longitude = Longitude
.Latitude = Latitude
.PositionTime = PositionTime
.ErrorType = ErrorType
End With
With cs
.dwData = NT_POS_INFO
.cbData = Len(pi)
.lpData = VarPtr(pi)
End With
NotifyPosInfo = CopyDataSendMessage(g_hwndParent, WM_COPYDATA, g_hwndSelf, cs)
End Function'当如下这样调用NotifyPosInfo时:
NotifyPosInfo 804485, 113.1235, 23.8631, 1478941, 0//VC++++++++++++++++++++++
struct TPosInfo
{
long MCTNumber;
double Longitude;
double Latitude;
long PositionTime;
short ErrorType;
};但它收到的数值竟然是:
MCTNumber = 804485
Longitude = 9.7745056398871749e-159
Latitude = 3.1383071093937146e-308
PositionTime = -33751040
ErrorType = -515救命啊,到底为何????????
Look
'VB+++++++++++++++++++++++++++++++++++
Private Declare Function CopyDataSendMessage Lib "user32" Alias "SendMessageA" (ByVal WndID As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As COPYDATASTRUCT) As LongPublic Type COPYDATASTRUCT
dwData As Long
cbData As Long
lpData As Long
End Type
Public Type TPosInfo
MCTNumber As Long
Longitude As Double
Latitude As Double
PositionTime As Long
ErrorType As Integer
End TypePublic Function NotifyPosInfo(MCTNumber As Long, Longitude As Double, Latitude As Double, PositionTime As Long, Optional ErrorType As Integer = 0) As Long
Dim pi As TPosInfo
Dim cs As COPYDATASTRUCT
With pi
.MCTNumber = MCTNumber
.Longitude = Longitude
.Latitude = Latitude
.PositionTime = PositionTime
.ErrorType = ErrorType
End With
With cs
.dwData = NT_POS_INFO
.cbData = Len(pi)
.lpData = VarPtr(pi)
End With
NotifyPosInfo = CopyDataSendMessage(g_hwndParent, WM_COPYDATA, g_hwndSelf, cs)
End Function'当如下这样调用NotifyPosInfo时:
NotifyPosInfo 804485, 113.1235, 23.8631, 1478941, 0//VC++++++++++++++++++++++
struct TPosInfo
{
long MCTNumber;
double Longitude;
double Latitude;
long PositionTime;
short ErrorType;
};但它收到的数值竟然是:
MCTNumber = 804485
Longitude = 9.7745056398871749e-159
Latitude = 3.1383071093937146e-308
PositionTime = -33751040
ErrorType = -515救命啊,到底为何????????
如果把double换成Single(float)传输数据就没问题~~
Why??