当我尝试在eclipse中使用mingGw w64编译器构建这个tapi3 c ++示例时,我遇到了一个问题,我已经按照msdn的步骤逐步进行了示例
#include <iostream>
#include <tapi3.h>
using namespace std;
int main() {
// Initialize COM.
HRESULT hr = CoInitializeEx(
NULL, COINIT_MULTITHREADED);
if (hr != S_OK)
cout << "CoInitializeEx Failed !!!" << endl;
// Create a TAPI entry point object.
ITTAPI *gpTapi; // globally allocated
hr = CoCreateInstance(CLSID_TAPI, NULL, CLSCTX_INPROC_SERVER, IID_ITTAPI,
(LPVOID *) &gpTapi);
if (hr != S_OK)
cout << "CoCreateInstance Failed !!!" << endl;
// Initialize TAPI.
hr = gpTapi->Initialize();
if (hr != S_OK)
cout << "gpTapi->Initialize() Failed !!!" << endl;
// Declare the interfaces used to select an address.
IEnumAddress * pIEnumAddress;
ITAddress * pAddress;
ITMediaSupport * pMediaSupport;
VARIANT_BOOL bSupport;
// Use the TAPI object to enumerate available addresses.
hr = gpTapi->EnumerateAddresses(&pIEnumAddress);
// If (hr != S_OK) process the error here.
// Locate an address that can support the media type the application needs.
while ( S_OK == pIEnumAddress->Next(1, &pAddress, NULL)) {
// Determine the media support.
hr = pAddress->QueryInterface(IID_ITMediaSupport,
(void **) &pMediaSupport);
if (hr != S_OK)
cout << "pAddress->QueryInterface() Failed !!!" << endl;
// In this example, the required media type is already known.
// The application can also use the address object to
// enumerate the media supported, then choose from there.
hr = pMediaSupport->QueryMediaType(TAPIMEDIATYPE_AUDIO | TAPIMEDIATYPE_VIDEO, &bSupport);
if (hr != S_OK)
cout << "pMediaSupport->QueryMediaType() Failed !!!" << endl;
if (bSupport) {
break;
}
}
// pAddress is now a usable address.
return 0;
}
我已经获得了lib ole32和old32,但是当我构建这个例子时,它会返回这个错误的时间,但是当我使用visual c ++编译时它可以工作
src\main.o:main.cpp (.rdata$.refptr.IID_ITMediaSupport[.refptr.IID_ITMediaSupport]+0x0): undefined reference to `IID_ITMediaSupport'
src\main.o:main.cpp:(.rdata$.refptr.CLSID_TAPI[.refptr.CLSID_TAPI]+0x0): undefined reference to `CLSID_TAPI'
src\main.o:main.cpp:(.rdata$.refptr.IID_ITTAPI[.refptr.IID_ITTAPI]+0x0): undefined reference to `IID_ITTAPI'
collect2.exe: error: ld returned 1 exit status
请你帮我解决这个问题,对不起我的英文
答案 0 :(得分:-1)
确保添加了这些lib文件:
version.lib ole32.lib oleaut32.lib uuid.lib
(来源:http://microsoft.public.win32.programmer.tapi.narkive.com/e4h0yQcj/com-and-tapi-initialize-error)
CLSID_TAPI和IID_ITMediaSupport是外部符号,因此需要lib。 IID_ITTAPI是已知的,也可以直接添加为头声明,如下所示:
const IID IID_ITTAPI = {0xB1EFC382,0x9355,0x11d0,{0x83,0x5C,0x00,0xAA,0x00,0x3C,0xCA,0xBD}};