short*->long*? 急救!简单问题送高分!

sheng_hu 2002-08-01 10:06:28
我在使用Windows Media Encoder SDK编程时,使用如下代码:

HRESULT hr;
IWMEncBroadcast* pBroadcast;

USES_CONVERSION;

//保存广播端口
short PortNum;
hr = pEncoder->get_Broadcast(&pBroadcast);
hr = pBroadcast->get_PortNumber(WMENC_PROTOCOL_HTTP,&PortNum);
g_VideoEncoderOutputInf[iIndex].iGbdk = (long) PortNum;

但编译时却报告如下错误:

D:\SLencoder\EncoderView.cpp(1514) : error C2664: 'get_PortNumber' : cannot convert parameter 2 from 'short *' to 'long *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe.

>>>>>>
>>>>>>为什么?请高手指点解决方法.......^_^
...全文
7 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sheng_hu 2002-08-01
这是Windows Media Encoder SDK help中关于get_PortNumber()函数的说明:


IWMEncBroadcast::get_PortNumber
The get_PortNumber method retrieves the port number used for broadcasting encoded content.

Syntax

HRESULT get_PortNumber(
WMENC_BROADCAST_PROTOCOL enumProtocol,
short* piPort
);
Parameters

enumProtocol

[in] short containing the protocol for transmitting encoded content. Currently, this must be the following value.

Value Number Meaning
WMENC_PROTOCOL_HTTP 1 The transmission uses the HTTP protocol.


piPort

[out] Pointer to a short containing the port number.

Return Values

If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.

Return code Number Description
E_POINTER 0x80004003 The pointer to the port number is NULL.
E_INVALIDARG 0x80070057 The protocol is invalid.


Remarks

Only the HTTP protocol can be used. To specify a port number, use the IWMEncBroadcast::put_PortNumber method.

Example

// Include libraries.

#include <windows.h>
#include "wmencode.h"

// Declare variables.

HRESULT hr;
IWMEncoder* pEncoder;
IWMEncBroadcast* pBrdcst;
short PortNum;

// Initialize the COM library and retrieve a pointer to the
// IWMEncoder interface.
hr = CoInitialize(NULL);

CoCreateInstance(CLSID_WMEncoder,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncoder,
(void**) &pEncoder);

// Retrieve a pointer to the IWMEncBroadcast interface.
hr = pEncoder->get_Broadcast(&pBrdcst);

// Retrieve the port number. The port number defaults to zero.
hr = pBrdcst->get_PortNumber(WMENC_PROTOCOL_HTTP, &PortNum);

// Set the port number.
PortNum = 2356;
hr = pBrdcst->put_PortNumber(WMENC_PROTOCOL_HTTP, PortNum);

回复
wistaria 2002-08-01
try
hr = pBroadcast->get_PortNumber(WMENC_PROTOCOL_HTTP,(long*)&PortNum);
回复
tomPeakz 2002-08-01
人家需要的是LONG型的变量,你传递short的怎么可以呢?强制转换一下或者
传递LONG型的数据。
回复
发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告
暂无公告