在 eclipse 中使用 migw 编译器对构建 Tapi3 c++ 示例时出错
Error when traying build Tapi3 c++ example using migw compiler in eclipse
当我尝试在 Eclipse 中使用 mingGw w64 编译器构建这个 tapi3 c++ 示例时,我遇到了一个问题,我一步一步地遵循了 MSDN 的 ewample
#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 ++进行编译时,它可以工作
srcmain.o:main.cpp (.rdata$.refptr.IID_ITMediaSupport[.refptr.IID_ITMediaSupport]+0x0): undefined reference to `IID_ITMediaSupport'
srcmain.o:main.cpp:(.rdata$.refptr.CLSID_TAPI[.refptr.CLSID_TAPI]+0x0): undefined reference to `CLSID_TAPI'
srcmain.o:main.cpp:(.rdata$.refptr.IID_ITTAPI[.refptr.IID_ITTAPI]+0x0): undefined reference to `IID_ITTAPI'
collect2.exe: error: ld returned 1 exit status
请你能帮我解决这个问题吗,对不起我的英语
确保添加了以下库文件:
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是外部符号,因此需要库。IID_ITTAPI是已知的,也可以直接添加为标头声明,如下所示:
const IID IID_ITTAPI = {0xB1EFC382,0x9355,0x11d0,{0x83,0x5C,0x00,0xAA,0x00,0x3C,0xCA,0xBD}};