I am having some difficulty with AWS Transcribe for C++. I believe a simple code example would solve it for me, but I find no code examples of the AWS Transcribe API in C++, (I realize there is one for TranscribeStreamingService, but my task is far simpler.)
According to the AWS docs for TranscribeServiceClient and StartTranscriptionJobRequest I need to create a StartTranscriptionJobRequest object, fill it in with setters, and hand it to the TranscribeServiceClient like this:
#include <aws/core/Aws.h>
#include <aws/core/auth/AWSCredentialsProviderChain.h>
#include <aws/core/client/AWSClient.h>
#include <aws/transcribe/TranscribeServiceClient.h>
using namespace Aws;
using namespace Aws::TranscribeService;
using namespace Aws::TranscribeService::Model;
void TestAWSTranscript() {
Aws::SDKOptions options;
Aws::InitAPI(options);
{
Aws::Client::ClientConfiguration config;
TranscribeServiceClient TranscriptClient(Auth::AWSCredentials(user_access_key.c_str(), user_private_key.c_str()), config);
StartTranscriptionJobRequest request = new StartTranscriptionJobRequest();
// request.SetLanguageCode(Aws::TranscribeService::Model::LanguageCode::en_US);
// more setters here...
TranscriptClient.StartTranscriptionJob(&request);
// check for completion
// enjoy transcript...
}
Aws::ShutdownAPI(options);
}
but the line:
StartTranscriptionJobRequest request = new StartTranscriptionJobRequest();
produces the errors:
Allocation of incomplete type 'Aws::TranscribeService::Model::StartTranscriptionJobRequest'
Variable has incomplete type 'Aws::TranscribeService::Model::StartTranscriptionJobRequest'
If it helps, the aws sdk is open-source and available on git.
What am I misunderstanding?
incomplete type means the complete class definition is not available/the class is only forward declared.
adding
#include <aws/transcribe/model/StartTranscriptionJobRequest.h>
should fix this
Related
I develop an UMDF2.0 driver using VS2019.
Inside this driver I need to communicate with an BLE device.
I have to use BluetoothLEDevice class to do this. This is a WinRT Api.
I'm completely lost on how to call C++/WinRT from my driver.
Does anyone have experienced this situation ?
Thank a lot for your great support,
EDIT 1#
I use the following simple test code in new cpp file into umdf2 sample project:
#include <windows.devices.h>
#include <windows.devices.bluetooth.h>
#include <windows.devices.bluetooth.genericattributeprofile.h>
using namespace ABI::Windows::Devices::Bluetooth;
void testBle()
{
BluetoothLEDevice dev;
}
I have the following error :
Error C2079
'dev' uses a class of 'ABI::Windows::Devices::Bluetooth::BluetoothLEDevice' not defined
EDIT 2
I found one usefull project on GitHub that help me a lot to make all this work. Please find the link below :
https://github.com/bucienator/ble-win-cpp
Thank you again for your help
You cannot instantiate the BluetoothLEDevice with default constructor because there is no such constructor in this case.
Please use this code snippet in instantiate the BT device.
#include <winrt/windows.devices.h>
#include <winrt/Windows.Devices.Bluetooth.h>
using namespace Windows::Devices::Bluetooth;
void testBle()
{
BluetoothLEDevice btDev = NULL;
IAsyncOperation<BluetoothLEDevice> launchOp =
BluetoothLEDevice::FromIdAsync(L"test");
btDev = launchOp.GetResults();
}
I am trying to figure out how to access the WinRT API via WRL in C++, using visual studio 2022 with the latest update 17.1.2.
(Background: I've done a fair amount of old-fashioned Windows desktop programming with the Win32 API. However, I now wish to access parts of the Windows API that are supported only in WinRT, such as access to Bluetooth LE devices. Note that I am trying to avoid UWP applications, as I fear it may cause my applications to be bloated, and am not sure what needed functionality it might remove from my programs. Further, I have tried Microsoft's C++/WinRT, but was having lots of trouble at points where the Microsoft compiler was telling me there was a problem up in the generated C++ headers--not my own code. So I am now trying to work closer to the ground with WRL.)
So, starting with an example provided in MS documentation (uri winRT class, which I can get to work as they wrote it), I have tried to try use of the ActivateInstance WRL class (which is not used in their example).
It seems not to be working for me. But I am probably doing something wrong. Can anyone help?
I have pared down the code to show the precise issue:
#include <roapi.h>
#include <combaseapi.h>
#include <iostream>
#include <windows.foundation.h>
#include <windows.foundation.collections.h>
#include <wrl\wrappers\corewrappers.h>
#include <wrl\client.h>
#include <stdio.h>
using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
int dummy;
ComPtr<IUriRuntimeClassFactory> uriFactory;
ComPtr<IUriRuntimeClass> uri;
HRESULT hr, hr2;
int main()
{
// Initialize the Windows Runtime.
RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
// Get the activation factory for the IUriRuntimeClass interface.
hr = GetActivationFactory(HStringReference(L"Windows.Foundation.Uri").Get(), &uriFactory);
hr2 = ActivateInstance (HStringReference(L"Windows.Foundation.Uri").Get(), &uri);
dummy = 1;
}
What happens is hr returns as S_OK. (Creating the factory. I don't use it here, but it is apparently a valid factory as it works when I leave in the rest of the Microsoft WRL example.)
But, what is confusing me is that hr2 is returning "E_NOTIMPl (not implemented)", and I thought it would get me a smart pointer to the uri class.
(Referencing this MS documentation for ActivateInstance:
and observing that the argument types are the same as
for GetActivationFactory
Thanks
(This is the next iterative question so I can figure out how to use WRL, after this one was answered I believe correctly.)
So I'm trying to build up to being able to access Bluetooth LE devices through WinRT via WRL.
Continuing in the pattern of a Microsoft example (which is for the uri WinRT class), I am trying at this point just to get the class factory for the DeviceWatcher Class. ( Documentation for that class seems to be here ), this is my pared-down example code:
#include <roapi.h>
#include <combaseapi.h>
#include <iostream>
#include <windows.foundation.h>
#include <windows.foundation.collections.h>
#include <wrl\wrappers\corewrappers.h>
#include <wrl\client.h>
#include <stdio.h>
#include <windows.devices.enumeration.h>
using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::Windows::Devices::Enumeration;
int dummy;
ComPtr<IUriRuntimeClassFactory> uriFactory;
ComPtr<IUriRuntimeClass> uri;
ComPtr<IDeviceWatcherRuntimeClassFactory> devWatcherFactory; //This line produces the only error, "IDeviceWatcherRuntimeClassFactory undefined"
//(When the line is omitted, the code compiles, links, and produces the smart pointer to a uri class)
HRESULT hr, hr2, hr3;
int main()
{
// Initialize the Windows Runtime.
RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
// Get the activation factory for the IUriRuntimeClass interface.
ComPtr<IUriRuntimeClassFactory> uriFactory;
HRESULT hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Foundation_Uri).Get(), &uriFactory);
// Create a string that represents a URI.
HString uriHString;
hr = uriHString.Set(L"http://www.microsoft.com");
// Create the IUriRuntimeClass object.
ComPtr<IUriRuntimeClass> uri;
hr2 = uriFactory->CreateUri(uriHString.Get(), &uri);
dummy = 1;
}
It is the MS example, up to the point of its uri WinRT class construction, and compiles and links and correctly constructs the uri class smart pointer when I leave out my added line that declares the ComPtr for IDeviceWatcherRuntimeClassFactory
The line is my attempt to just create a smart-pointer for the DeviceWatcher class factory, and it fails with identified "IDeviceWatcherRuntimeClassFactory undefined". (It also fails if I use small "d" as the second letter of the type argument.
In using "IDeviceWatcherRuntimeClassFactory", I'm trying to proceed by exact analogy to the MS example.
Besides the MS online documentation for the DeviceWatcher class (3), which doesn't seem to help me, I've also tried looking at what VS2022 solution explorer shows as the expansion of the header windows.devices.enumeration.h (which also does not seem to be telling me what name to use as far as I can figure out).
I've also tried using the VS2022 Object Browser, pointed to a custom component set of all .winmd files in C:\Windows\System32\WinMetaData, and again the information is not helping me, given my level of knowledge.
Can someone give me a sound method, for an arbitrary WinRT class, to figure out the type to use for the smart pointer to the class factory?
And, to save another iteration, once I can make a smart pointer to the factory, I will
need to make a smart pointer to the class itself (in my case, to DeviceWatcher). Can someone tell me what exact name to use for the ComPtr type?
Thanks.
I am trying to create a packet and attach a custom object. I read through the manual and tried following their suggestions but I am stuck.
According to the manual: Non-cObject data can be attached to messages by wrapping them into cObject, for example into cMsgPar which has been designed expressly for this purpose.
cMsgPar has the function: setObjectValue(), so I attempted to add the class via this code:
// b is a pointer to a custom object
auto packet = createPacket("Msg");
packet->addPar("data");
packet->par("data").setObjectValue(b);
but I get a 'no matching function for call' error for the setObject value function. I checked the function declaration, which is:
cMsgPar & setObjectValue (cOwnedObject *obj)
which brings me back to square one. Trying to convert my custom class into something acceptable by Omnet to send to other nodes in my network.
Any help would be appreciated.
The recommended way of carrying own classes (objects) via message in OMNeT++ is to add this to definition of a message. For example:
cplusplus {{
#include "MyClass.h" // assuming that MyClass is declared here
typedef MyClass *MyClassPtr;
}};
class noncobject MyClassPtr;
packet MyPacket {
int x;
MyClassPtr ptr;
}
Reference: OMNeT++ Simulation Manual - 6.6 Using C++ Types
this is how i do it as an easy solution. Omnet++ already gave alot of ways to do it.
msg->addPar("preamble");
msg->par("preamble").setLongValue(0b01010101010101);
send(msg,"phyout");
i hope it will helpout
I'm trying to run this repo for curiosity: https://github.com/jzeimen/PuzzleSolver/tree/master/PuzzleSolver
Eclipse throws the title error "'MSize' is not a member of cv::Mat' whenever I try to run the following line of code from PuzzleDisjointSet.cpp:
cv::Mat::MSize size_of_a = sets[rep_a].locations.size;
Where locations is defined like so:
struct forest{
cv::Mat_<int> locations;
cv::Mat_<int> rotations;
int representative;
int id;
};
and sets is a vector version of the forest structure. I'm mainly confused as to why this is occurring, when documentation clearly refutes this.
I believe the header files I am including are the correct ones (PuzzleDisjointSet.h includes the above forest structure definition as well as the sets definition.
#include "PuzzleDisjointSet.h"
#include <algorithm>
#include <opencv2/core.hpp>
#include <opencv/cv.h>
#include <opencv2/core/mat.hpp>
the struct was removed in this commit
https://github.com/Itseez/opencv/commit/d8c8339bec83b77978d2a0e1a62b764fb9d9c599#diff-bc1d784738cd852f5b1e95ce10a56d06
maybe you can checkout a version before that and use it, or i suspect it may have been moved to a different class, you can try looking for that
OpenCV version: 4.3.0
cv::MatSize size_of_a = sets[rep_a].locations.size;