I want to write a WMI application using windows API and COM library in Qt.
I include <qt_windows.h> to access windows API , I tried this before in Visual Studio.
But when I include Wbemidl.h to declare a IWbemLocator variable, the compiler give me the following error :
error: Wbemidl.h: No such file or directory
This is a section of my code :
HRESULT hResult = S_OK; // Result of initializing com library
BOOL bIsComLibUninit = FALSE; // A flag that determine if com library is loaded
// Initialize COM library
hResult = CoInitializeEx(0, COINIT_MULTITHREADED);
// If a previous call of CoInitializeEx occured in this thread
if(hResult == RPC_E_CHANGED_MODE)
{
OleUninitialize();
bIsComLibUninit = TRUE;
}
else if(hResult == S_OK)
{
bIsComLibUninit = TRUE;
}
// If COM library uninitialized
if(bIsComLibUninit == TRUE)
{
// Initialize COM library
hResult = CoInitializeEx(0, COINIT_MULTITHREADED);
if(hResult == S_OK)
{
// Initialize security
hResult = CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, EOAC_NONE, NULL);
if(hResult == S_OK)
{
IWbemLocator *pLoc = NULL;
CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLoc);
// Do stuffs
}
}
// Uninitialize COM library
CoUninitialize();
}
Error message tells that compiler can't find the header file.
Try to find the "Wbemidl.h" in your location(e.g. the Path in my local: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um), and add the PATH to your compiler. Also don't forget the .lib reference.
If you can't find this header file, try to download sdk from here, select one which suits you:
Related
In a Visual Studio extension I need to iterate through all the projects in the loaded solution and find all Dependencies (both NuGet packages as well as assemblies). The following code works fine for old non-SDK style projects but not for the new SDK-style projects.
var dte = ApplicationObject; // DTE object
if (dte == null || dte.Solution == null || !dte.Solution.IsOpen)
{
return;
}
foreach (Project project in dte.Solution.Projects)
{
var vsProj = project.Object as VSProject;
if (vsProj == null || vsProj.References == null)
{
// Project not loaded
continue;
}
foreach (Reference reference in vsProj.References)
{
if (reference.SourceProject != null
|| reference.Type != prjReferenceType.prjReferenceTypeAssembly)
{
// Skip over non assembly references
continue;
}
// reference.Name contains the reference name
}
}
In the new SDK-style projects "references" is now called Dependencies but there is no such property on VSProject. So what is the way to get this for SDK-style projects?
So what is the way to get this for SDK-style projects?
I'm afraid the answer is negative. This could be one issue related to VS2019 SDK and new SDK project system.
And this issue occurs specifically in IVsSolutionEvents.OnAfterOpenSolutionevent. I tried to invoke similar code in OnQueryCloseSolution event or in a Command Item's click event but it all works well for same solution with one .net core applications in it.
I think it could be one issue cause the solution and project are not null(I output the xx.sln and xx.csproj), but it just can't get reference.Name from vsProj.References. And it works when close solution, but get empty list when open solution.For now, I've found no valid workaround which makes it work.
Issue reported to DC, if anyone's interested in it, you can track the issue here.
The VS2019 project is a .net core 3.1 library project and the following code while the solution is open. is in fact retrieving the path location of a reference stored in the nuget location:
C:\Users\xxxxx\.nuget\packages\subsonic.core.dal\4.2.1\lib\netstandard2.1\SubSonic.Core.DataAccessLayer.dll
public string ResolveAssemblyReference(string assemblyReference)
{
ThreadHelper.ThrowIfNotOnUIThread();
string path = EngineHost.ResolveAssemblyReference(assemblyReference);
if (path.Equals(assemblyReference, StringComparison.Ordinal) &&
!foundAssembly.IsMatch(path))
{ // failed to find the assembly, could it be referenced via a project reference?
if (GetService(typeof(DTE)) is DTE dTE)
{
foreach (Project project in dTE.Solution.Projects)
{
if (project.Object is VSProject vsProject)
{
path = ResolveAssemblyReferenceByProject(assemblyReference, vsProject.References);
}
else if (project.Object is VsWebSite.VSWebSite vsWebSite)
{
path = ResolveAssemblyReferenceByProject(assemblyReference, vsWebSite.References);
}
}
}
if (!foundAssembly.IsMatch(path))
{
LogError(false, SubSonicCoreErrors.FileNotFound, -1, -1, $"{assemblyReference}.dll");
}
}
return path;
}
private string ResolveAssemblyReferenceByProject(string assemblyReference, References references)
{
foreach (Reference reference in references)
{
if (reference.Name.Equals(assemblyReference, StringComparison.OrdinalIgnoreCase))
{ // found the reference
return reference.Path;
}
}
return assemblyReference;
}
private string ResolveAssemblyReferenceByProject(string assemblyReference, VsWebSite.AssemblyReferences references)
{
foreach (VsWebSite.AssemblyReference reference in references)
{
if (reference.Name.Equals(assemblyReference, StringComparison.OrdinalIgnoreCase))
{ // found the reference
return reference.FullPath;
}
}
return assemblyReference;
}
I'm trying to create and implement a DDE dll with Qt but as for now I'm being unable to properly connect to a service which I know to be working after testing it with Excel.
The dll connection function is as following:
UINT respTemp;
respTemp = DdeInitializeA(&pidInst, NULL, APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0L);
//handle error messages here
//...
//![]
hszService = DdeCreateStringHandleA(pidInst, (LPCSTR)service.utf16(), CP_WINANSI); //service.toLatin1().toStdString().c_str()
hszTopic = DdeCreateStringHandleA(pidInst, (LPCSTR)topic.utf16(), CP_WINANSI); //topic.toLatin1().toStdString().c_str()
hConv = DdeConnect(pidInst, hszService, hszTopic, NULL);
DdeFreeStringHandle(pidInst, hszService);
DdeFreeStringHandle(pidInst, hszTopic);
if (!hConv)
{
UINT ddeLastError = DdeGetLastError(pidInst);
switch (ddeLastError)
{
case DMLERR_DLL_NOT_INITIALIZED: return DDEConn_DLLNotInitialized;
case DMLERR_INVALIDPARAMETER: return DDEConn_InvalidParameter;
case DMLERR_NO_CONV_ESTABLISHED: return DDEConn_NoConvEstablished;
default: return DDEConn_NoConnectionStablished;
}
}
connStatus = true;
return DDEConn_NoError;
The test function is as follows:
void MainWindow::on_start_clicked()
{
const QString application = "profitchart"; //=profitchart|COT!VALE5.ult
const QString topic = "COT";
const QString item = "VALE5.ult";
test = CommDDE::instance();
CommDDE::DDEConnectionErrorList resp = test->connect(application,topic);
if (resp == CommDDE::DDEConn_NoError)
{
qDebug() << "request RESULT: " << test->request(item);
}
else
qDebug() << "Can't connect to application" << resp;
}
Always when I try to connect I get error DMLERR_NO_CONV_ESTABLISHED after the call to DdeConnect. I couldn't find guidence on what to do when such error occurs. I don't know too much about the details of configuring such functions so I used the default configuration used by a working dll from which I got part of the raw material for this dll. Should I try a different configuration I'm not aware of? Remembering that the call is working on Excel.
It would seem I found the answer: the commented way of writting the service and topic names were the right ways of passing the parameters to DdeCreateStringHandleA and DdeCreateStringHandleA.
i was trying to write a plugin for return RGB image stream from ASUS Xtion PRO LIVE using openni.
So in my Dll program i implement getdata() function of VideoFrameRef class to return pointer from image data. when i call this function from my test program it throws an exception.
hear is my dll code
void* MyRgbStrem::GetStream()
{
Device device;
VideoStream color;
VideoFrameRef vframeRef;
VideoMode vmode;
Status status = STATUS_OK;
status = openni::OpenNI::initialize ();
status = device.open(openni::ANY_DEVICE);
status = color.create (device, SENSOR_COLOR);
status = color.start();
while (true)
{
if (device.getSensorInfo(SENSOR_COLOR) != NULL)
{
status = color. readFrame(&vframeRef);
if (vframeRef.isValid())
{
return ( uint16_t*) vframeRef.getData();
}
}
}
}
and in the header file i declar class MyRgbStrem
namespace Rgbstream
{
class MyRgbStrem
{
public:
static __declspec(dllexport) void* GetStream();
};
}
in my test program i use opencv for image processing and to get frame width, height and size i declae few more functions in dll program and call them in test application
this is the program i use to call dll
{
Mat rgb,bgr;
int height, width, size;
height = Rgbstream::MyRgbStrem::GetFrameSize_H();
width = Rgbstream::MyRgbStrem::GetFrameSize_W();
size = Rgbstream::MyRgbStrem::getSizeOfData();
bgr.create ( height,width, CV_8UC3);
rgb.create (height,width, CV_8UC3);
while (true)
{
const void* imgbuff = Rgbstream::MyRgbStrem::GetStream();
memcpy (bgr.data, imgbuff, size );
cvtColor(rgb,bgr, CV_RGB2BGR);
namedWindow ("Color Video",CV_WINDOW_AUTOSIZE);
imshow ("Color Video", bgr);
char key = waitKey (10);
if (key == 27) break;
}
return 0;
}
when i run this program it throws an exception like this
Unhandled exception at 0x0F97E89A (msvcr110d.dll) in CallRgbStream.exe: 0xC0000005: Access violation reading location 0x00268000.
The program '[9544] CallRgbStream.exe' has exited with code 0 (0x0).
any help is appreciate. thanks
On my embedded system I don't have X11, Mac, Win, S60, etc. I keep getting a NULL ( 0 ) pointer returned from the create method of the QInputContextFactory class. I verified that QT_NO_LIBRARY is not defined.
On my Desktop Qt Build this works just fine.
I also verified that my custom key and parent are being passed to the method.
What could cause this to fail? -->
if (QInputContextFactoryInterface *factory =
qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key))) {
result = factory->create(key);
}
Here is the entire method:
QInputContext *QInputContextFactory::create( const QString& key, QObject *parent )
{
QInputContext *result = 0;
#if defined(Q_WS_X11) && !defined(QT_NO_XIM)
if (key == QLatin1String("xim")) {
result = new QXIMInputContext;
}
#endif
#if defined(Q_WS_WIN)
if (key == QLatin1String("win")) {
result = new QWinInputContext;
}
#endif
#if defined(Q_WS_MAC)
if (key == QLatin1String("mac")) {
result = new QMacInputContext;
}
#endif
#if defined(Q_WS_S60)
if (key == QLatin1String("coefep")) {
result = new QCoeFepInputContext;
}
#endif
#ifdef QT_NO_LIBRARY
Q_UNUSED(key);
#else
qDebug() << "Here we are";
if (QInputContextFactoryInterface *factory =
qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key))) {
result = factory->create(key);
}
#endif
if (result)
result->setParent(parent);
return result;
}
Within Qt, the QInputContextFactory class is front-end on loading input context plug-ins. It will fail to load an input context plug-in if it fails to exist, or hasn't been deployed properly. Input context plug-ins are typically stored under $QT_PLUGIN_PATH/inputmethods. As such, if there is no plug-in within that directory, the create method of the QInputContextFactory will return NULL.
Of note, Qt does provide a few mechanisms for customizing the location of plug-ins. Refer to the following for more detail on this:
http://qt-project.org/doc/qt-4.8/deployment-plugins.html
I'm a student programmer and I am using Qt to build some GUI applications for work and I have been running into moc issues over and over again. I was hoping for a solution to the current problem that I am having; however, if anyone more veteraned in Qt could shed some light on how to properly handle these files while making changes to your cpp file(s) I'd appreciate any help. In my most recent change (sorry I can't post what it did look like, because it's obviously been restructured) I was validating data by nesting a function inside of my checkData function. Because I would like a specific error to appear for each field that might be invalid I began to create a function for each QLineEdit. I realized that this would not work (or at least make more work) then instead of just providing sequenced checks of information. Below is the new code without the original nested function:
void InjectionDialog::checkData() {
bool validateFluidVelocity;
QString tempStrFluidVelocity;
tempStrFluidVelocity = ui->lineEditFluidVelocity->text();
double convertedFluidVelocity =
tempStrFluidVelocity.toDouble(&validateFluidVelocity);
if (validateFluidVelocity == false) {
QErrorMessage validateErrorFluidVelocityError;
validateErrorFluidVelocityError.
showMessage("Fluid velocity input is invalid");
validateErrorFluidVelocityError.exec();
}
else {
transData.lineEditFluidVelocity = convertedFluidVelocity;
}
bool validateFluidMassFlow;
QString tempStrFluidMassFlow;
tempStrFluidMassFlow = ui->lineEditFluidMassFlow->text();
double convertedFluidMassFlow =
tempStrFluidMassFlow.toDouble(&validateFluidMassFlow);
if (validateFluidMassFlow == false) {
QErrorMessage validateErrorFluidMassFlowError;
validateErrorFluidMassFlowError.
showMessage("Fluid mass flow input is invalid");
validateErrorFluidMassFlowError.exec();
}
else {
transData.lineEditFluidMassFlow = convertedFluidMassFlow;
}
bool validateParticleVelocity;
QString tempStrParticleVelocity;
tempStrParticleVelocity = ui->lineEditParticleVelocity->text();
double convertedParticleVelocity =
tempStrParticleVelocity.toDouble(&validateParticleVelocity);
if (validateParticleVelocity == false) {
QErrorMessage validateErrorParticleVelocity;
validateErrorParticleVelocity.
showMessage("Particle velocity input is invalid");
validateErrorParticleVelocity.exec();
}
else {
transData.lineEditParitcle_sic_Velocity = convertedParticleVelocity;
}
bool validateParticleMassFlow;
QString tempStrParticleMassFlow;
tempStrParticleMassFlow = ui->lineEditParticleMassFlow->text();
double convertedParticleMassFlow =
tempStrParticleMassFlow.toDouble(&validateParticleMassFlow);
if (validateParticleMassFlow == false) {
QErrorMessage validateErrorParticleMassFlow;
validateErrorParticleMassFlow.
showMessage("Particle mass flow input is invalid");
validateErrorParticleMassFlow.exec();
}
else {
transData.lineEditParticleMassFlow = convertedParticleMassFlow;
}
}
Initially I had InjectionDialog::checkFluidVelociy for the first check but decided against it pretty quickly. Now with the code restructured I receive the error:
In function 'InjectionDialog::checkFluidVelocity(QMetaObject::Call, int, void**)':
this error is referenced to moc_injectionDialog.o
unidentified reference to 'InjectionDialog::checkFluidVelocity()'
this error is referenced to moc_injectiondialog.cpp
In moc_injectiondialog I have the following I have the following listed:
/****************************************************************************
** Meta object code from reading C++ file 'injectiondialog.h'
**
** Created: Sat Jan 7 21:58:22 2012
** by: The Qt Meta Object Compiler version 62 (Qt 4.7.4)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include "../InjectionGUI/injectiondialog.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'injectiondialog.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 62
#error "This file was generated using the moc from 4.7.4. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
static const uint qt_meta_data_InjectionDialog[] = {
// content:
5, // revision
0, // classname
0, 0, // classinfo
2, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount
// slots: signature, parameters, type, tag, flags
17, 16, 16, 16, 0x08,
29, 16, 16, 16, 0x08,
0 // eod
};
static const char qt_meta_stringdata_InjectionDialog[] = {
"InjectionDialog\0\0checkData()\0"
"checkFluidVelocity()\0"
};
const QMetaObject InjectionDialog::staticMetaObject = {
{ &QDialog::staticMetaObject, qt_meta_stringdata_InjectionDialog,
qt_meta_data_InjectionDialog, 0 }
};
#ifdef Q_NO_DATA_RELOCATION
const QMetaObject &InjectionDialog::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION
const QMetaObject *InjectionDialog::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
}
void *InjectionDialog::qt_metacast(const char *_clname)
{
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_InjectionDialog))
return static_cast<void*>(const_cast< InjectionDialog*>(this));
return QDialog::qt_metacast(_clname);
}
int InjectionDialog::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QDialog::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
switch (_id) {
case 0: checkData(); break;
case 1: checkFluidVelocity(); break;
default: ;
}
_id -= 2;
}
return _id;
}
QT_END_MOC_NAMESPACE
I have looked over some of the other moc_file posts and most of them say to have Qt clean and rebuild the project. I have ran a project clean up and rebuild all to try to overhaul this moc file but have not had any success in getting rid of the error. It seems like a bug but I couldn't find anything online about it so maybe it's something I don't know about. Thanks in advance for any help you can offer.
Whenever I have MOC problems, I Build->Clean All and then Build->Run qmake (Qt Creator IDE). If that doesn't solve my problem, I go into my project folder and delete moc_* files and any other junk that Clean doesn't remove - basically leaving nothing but headers, source and resources.
Go to you moc file which is throwing the error. At the top, there will be an include statement, which includes the header file for that window, NOT ui_.h, just .h
check in that file if there is a reference to the widget which is causing the error.