你好,正如标题所说,我需要创建一个包装器才能在我的 C# 代码中使用它。但事实是我对 C 一无所知,但我比 C# 更好。
C
HRESULT ( STDMETHODCALLTYPE *Connect )(
ExCtrl * This,
/* [in] */ EX_CONNECT *pConnect);
HRESULT ( STDMETHODCALLTYPE *Disconnect )(
ExCtrl * This);
HRESULT ( STDMETHODCALLTYPE *IsConnected )(
ExCtrl * This);
HRESULT ( STDMETHODCALLTYPE *GetStatus )(
ExCtrl * This,
/* [out] */ ExStatus **ppStatus);
HRESULT ( STDMETHODCALLTYPE *GetPreview )(
ExCtrl * This,
/* [out] */ HBITMAP *phbm);
我设法为“Connect”、“Disconnect”、“IsConnected”写作
C++
HRESULT Connect(String^ ServerIP)
{
IntPtr ptr = Runtime::InteropServices::Marshal::StringToBSTR(ServerIP);//
CComBSTR bstr; //Converting ip string
bstr.Attach(static_cast<BSTR>(ptr.ToPointer()));
if (IsConnected())
return E_UNEXPECTED; // already connected
ExCtrl *piCtrl = NULL;
HRESULT hr = Ex_CreateController(__uuidof(ExCtrl), __uuidof(ExCtrl), (void **)&piCtrl);
if (FAILED(hr)) return hr;
EX_CONNECT connection = {0}; // Connection data
connection.appType = APP_TYPE;
connection.bstrPrimaryName=CComBSTR(bstr); //
connection.layerId = (int)LAYER0 + m_iLayerNum;
connection.masterServer = SERVER_PRIMARY;
TIME_ZONE_INFORMATION tz;
connection.pTz = &tz;
hr = piCtrl->Connect(&connection);
if (FAILED(hr)) {
piCtrl->Release(); // connection failed - clear the controller
} else
m_piCtrl = piCtrl; // succefully connected
return hr;
}
bool IsConnected()
{
return (m_piCtrl != NULL);
}
HRESULT Disconnect()
{
if (!IsConnected())
return E_UNEXPECTED; // not connected
HRESULT hr = m_piCtrl->Disconnect();
if (SUCCEEDED(hr)) m_piCtrl->Release();
m_piCtrl = NULL;
return hr;
}
问题在于“GetPreview”,我不知道如何将 HBitmap 转换为位图。我试过这样:
HRESULT GetImagePreview(BITMAP bm)
{
HBITMAP hB =NULL;
tExCtrl *piCtrl = NULL;
HRESULT hr = Ex_CreateController(__uuidof(ExCtrl), __uuidof(ExCtrl), (void **)&piCtrl);
hr = piCtrl->GetPreview(&hB);
hr = GetObject(hB, sizeof(BITMAP), &bm);
return hr;
}
但没有运气
谢谢,