{app.exe!_com_error::`vector deleting destructor'(unsigned int)} - c++

I am getting exception while creating MSMQqueue in Visual Studio 2017, find the code and exception details below:
Exception details :
app.exe!`queue::CreateQueue'::`1'::catch$3() Line 56 C++ Symbols loaded.
Please suggest the queue for implementing serial port read and write.
queue.cpp
#include "stdafx.h"
#include "MSMQ_Queue.h"
#import "mqoa.dll"
using namespace MSMQ;
queue::queue() {}
queue::~queue() {}
HRESULT queue::CreateQueue(WCHAR *wszPathName)
{
HRESULT hr = S_OK;
if (wszPathName == NULL)
{
return MQ_ERROR_INVALID_PARAMETER;
}
try
{
IMSMQQueueInfoPtr pInfo("MSMQ.MSMQQueueInfo");
// Set the queue's path name and label.
pInfo->PathName = wszPathName;
pInfo->Label = "TestQueue";
// Create the queue.
**pInfo->Create();**//Hitting exception at this point
WCHAR wszMessage[1024] = { 0 };
}
catch (const _com_error& comerr)
{
hr = comerr.Error();
WCHAR wszMessage[2048] = { 0 };
}
return hr;
}
main.cpp
#include "stdafx.h"
#include"queue.h"
#include <stdio.h> // for printf
int main()
{
wchar_t name[] = L".\\vniqueue";
queue msmqueue;
//CoInitialize(0);
OleInitialize(NULL);
HRESULT returnValue = msmqueue.CreateQueue(name);
getchar();
return 0;
}
Exception create queue

Finally I found solutions for this..
I have given public path instead of private pat. Changed “.//queuename” to .//private$//queuename”.

Related

ISimpleAudioVolume G/SetMute not updating

Solution: I reference the pointer of a variable instead of the variable itself. Thank you #RomanR.
I'm trying to use GetMute/SetMute through ISimpleAudioVolume, and I'm having trouble with what I'm seeing. When I run GetMute I can see that it's not muted (which is good), but when I mute my audio output, or run SetMute(false) it fails to update anything. I'm not sure if I'm setting up AudioClient correctly, but don't know how to check it.
Thanks!
Edit: I think my issue is somewhere near the top of the initialization chain. When I run check the volume it says it's 100% which isn't true. When I check the device IDs & states, the beginning of the two IDs are a bunch of 0s, and the state says they're both inactive. If I check the AudioSessionControl, there's no name, but it says the session is also inactive.
My guess is that it's somewhere in this stack of init():
check(CoInitialize(NULL));
check(CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID*)&m_deviceEnumerator));
check(m_deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &m_device));
MainVolumeControl.h
#pragma once
#include <cstdio>
#include <windows.h>
#include <audioclient.h>
#include <audiopolicy.h>
#include <Mmdeviceapi.h>
class MainVolumeControl
{
public:
MainVolumeControl();
void init();
void destroy();
void toggleMute();
void GetMute(BOOL* o_mute);
IMMDeviceEnumerator* m_deviceEnumerator;
IMMDevice* m_device;
IAudioClient* m_audioClient;
ISimpleAudioVolume* m_audioVolume;
WAVEFORMATEX* m_pwfx;
};
MainVolumeControl.cpp
MainVolumeControl::MainVolumeControl()
{
m_deviceEnumerator = nullptr;
m_device = nullptr;
m_audioClient = nullptr;
m_audioVolume = nullptr;
m_pwfx = nullptr;
}
void MainVolumeControl::init()
{
// Get Device
check(CoInitialize(NULL));
check(CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID*)&m_deviceEnumerator));
check(m_deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &m_device));
// Get Audio Client
m_device->Activate(__uuidof(IAudioClient), CLSCTX_ALL, NULL, (void**)&m_audioClient);
// Activate Audio Client & Get Service
check(m_audioClient->GetMixFormat(&m_pwfx));
check(m_audioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, 0, 10000000, 0, m_pwfx, NULL));
check(m_audioClient->GetService(__uuidof(ISimpleAudioVolume), (void**)&m_audioVolume));
}
void MainVolumeControl::destroy()
{
// Release the resources
m_audioVolume->Release();
m_audioClient->Release();
m_device->Release();
m_deviceEnumerator->Release();
CoUninitialize();
}
void MainVolumeControl::toggleMute()
{
BOOL mute = 0;
// Getting the mute value
check(m_audioVolume->GetMute(&mute));
check(m_audioVolume->SetMute(!&mute, NULL));
}
void MainVolumeControl::GetMute(BOOL* o_mute)
{
// Finally getting the mute value
check(m_audioVolume->GetMute(o_mute));
}
Main.cpp
int main(int argc, CHAR* argv[])
{
MainVolumeControl mvc;
BOOL mute = 1;
mvc.init();
mvc.GetMute(&mute);
printf("Mute state: %d\n", mute);
printf("Toggling mute\n");
mvc.toggleMute();
mvc.GetMute(&mute);
printf("Mute state: %d\n", mute);
mvc.destroy();
return 0;
}
Output
Mute state: 0
Toggling mute
Mute state: 0
I reference the pointer of a variable instead of the variable itself. Thank you #RomanR.
Should be:
void MainVolumeControl::toggleMute()
{
BOOL mute = 0;
// Getting the mute value
check(m_audioVolume->GetMute(&mute));
check(m_audioVolume->SetMute(!mute, NULL));
}

Invalid Handle when using SetConsoleWindowInfo

I'm new to C++ and decided to challenge myself with a small console game. To avoid typical flickering.
Fromm what I got from MSDN docs I should be using a Console Buffer, but I took it easy and started from simple things like changing Window title and resizing it.
The small program I wrote was meant to do just that, but for some reason I get Error Code 6 (should be "invalid handle") when I execute the SetConsoleWindowInfo.
Anyone who can point me in the right direction with this? Thank you in advance
#include <windows.h>
#include <stdio.h>
#include <iostream>
HANDLE wHandle, bHandle;
SMALL_RECT wSize = { 0,0,100,100 };
int main() {
wHandle = GetConsoleWindow();
if (wHandle == NULL) {
printf("Handle is Null");
}
SetConsoleTitle(L"NewTitle");
if (!SetConsoleWindowInfo(wHandle, TRUE, &wSize)) {
printf("SetConsoleWindowInfo (%d)\n", GetLastError());
}
getchar();
return 0;
}
Maybe this will help:
#include <windows.h>
#include <stdio.h>
#include <iostream>
HANDLE wHandle, bHandle;
//SMALL_RECT wSize = { 0,0,100,100 }; // If SetConsoleWindow fails with code 87, then this is too big!
SMALL_RECT wSize = { 0,0,60,20 }; // Works on my screen!
int main() {
// wHandle = GetConsoleWindow();
wHandle = GetStdHandle(STD_OUTPUT_HANDLE); // See comment by RbMm
if (wHandle == NULL) {
printf("Handle is Null");
}
// SetConsoleTitle(L"NewTitle"); // Don't use a wide character string!
SetConsoleTitle("NewTitle");
if (!SetConsoleWindowInfo(wHandle, TRUE, &wSize)) {
printf("SetConsoleWindowInfo (%d)\n", GetLastError());
}
getchar();
return 0;
}
Feel free to ask, if you don't understand anything I've changed (or why I've changed it), but the comments address some of the issues.

error C2079 uses undefined class - WinRT/UWP?

So here is my code:
// wrl-consume-component.cpp
// compile with: runtimeobject.lib
#include <Windows.Foundation.h>
#include <wrl\wrappers\corewrappers.h>
#include <wrl\client.h>
#include <stdio.h>
#include <windows.networking.vpn.h>
using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::Networking::Vpn;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
// Prints an error string for the provided source code line and HRESULT
// value and returns the HRESULT value as an int.
int PrintError(unsigned int line, HRESULT hr)
{
wprintf_s(L"ERROR: Line:%d HRESULT: 0x%X\n", line, hr);
return hr;
}
int wmain()
{
// Initialize the Windows Runtime.
RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
if (FAILED(initialize))
{
return PrintError(__LINE__, initialize);
}
// Get the activation factory for the IUriRuntimeClass interface.
ComPtr<VpnManagementAgent> uriFactory;
HRESULT hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Networking_Vpn_VpnManagementAgent).Get(), &uriFactory);
if (FAILED(hr))
{
return PrintError(__LINE__, hr);
}
// VpnManagementAgent vpn;
auto profiles = uriFactory->GetProfilesAsync().get();
wprintf(L"Found %d profiles\n", profiles.Size());
for (auto vp : profiles)
{
wprintf(L"Found profile %s\n", vp.ProfileName().c_str());
}}
/*
Output:
Domain name: microsoft.com
*/
It's basically copy paste from msdn and the answer to that question.
I'm compiling like this:
cl /diagnostics:column wrl-consume-component.cpp /link RuntimeObject.lib windows.networking.lib
Obviously I'm missing something huge here.
The error message is:
wrl-consume-component.cpp(40,27): error C2027: use of undefined type 'ABI::Windows::Networking::Vpn::VpnManagementAgent'

Windows Explorer: self implemented Overlay Icons do not work

I'm trying to simply display some overlay icons in the Windows Explorer.
Since I'm relatively new to programming for Windows (I just have some experience in Mac programming), I used this article to start.
So this is my code:
Icon.h
#pragma once
#include "resource.h"
#include "ExplorerSync_i.h"
using namespace ATL;
class ATL_NO_VTABLE CIcon :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CIcon, &CLSID_Icon>,
public IShellIconOverlayIdentifier,
public IDispatchImpl<IIcon, &IID_IIcon, &LIBID_ExplorerSyncLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
CIcon();
STDMETHOD(GetOverlayInfo)(LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD* pdwFlags);
STDMETHOD(GetPriority)(int* pPriority);
STDMETHOD(IsMemberOf)(LPCWSTR pwszPath, DWORD dwAttrib);
DECLARE_REGISTRY_RESOURCEID(IDR_ICON)
BEGIN_COM_MAP(CIcon)
COM_INTERFACE_ENTRY(IIcon)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IShellIconOverlayIdentifier)
END_COM_MAP()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
protected:
};
Icon.cpp
#include "stdafx.h"
#include "Icon.h"
#using <system.dll>
using namespace System;
using namespace System::Diagnostics;
STDMETHODIMP CIcon::GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, int * pIndex, DWORD * pdwFlags)
{
GetModuleFileNameW(_AtlBaseModule.GetModuleInstance(), pwszIconFile, cchMax);
*pIndex = 0;
*pdwFlags = ISIOI_ICONFILE | ISIOI_ICONINDEX;
return S_OK;
}
STDMETHODIMP CIcon::GetPriority(int * pPriority)
{
*pPriority = 0;
return S_OK;
}
STDMETHODIMP CIcon::IsMemberOf(LPCWSTR pwszPath, DWORD dwAttrib)
{
wchar_t *s = _wcsdup(pwszPath);
HRESULT r = S_FALSE;
_wcslwr_s(s, 1);
r = S_OK;
free(s);
return r;
}
CIcon::CIcon() {
}
ExplorerSync.cpp
#include "stdafx.h"
#include "resource.h"
#include "ExplorerSync_i.h"
#include "dllmain.h"
#include "Icon.h"
#using <system.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace ATL;
STDAPI DllCanUnloadNow(void)
{
return _AtlModule.DllCanUnloadNow();
}
_Check_return_
STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID* ppv)
{
return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}
STDAPI DllRegisterServer(void)
{
HRESULT hr = _AtlModule.DllRegisterServer();
// not possible to instantiate, because it is abstract according to error message
//CIcon *cIcon = new (std::nothrow) CIcon();
return hr;
}
STDAPI DllUnregisterServer(void)
{
HRESULT hr = _AtlModule.DllUnregisterServer();
return hr;
}
STDAPI DllInstall(BOOL bInstall, _In_opt_ LPCWSTR pszCmdLine)
{
HRESULT hr = E_FAIL;
static const wchar_t szUserSwitch[] = L"user";
if (pszCmdLine != NULL)
{
if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0)
{
ATL::AtlSetPerUserRegistration(true);
}
}
if (bInstall)
{
hr = DllRegisterServer();
if (FAILED(hr))
{
DllUnregisterServer();
}
}
else
{
hr = DllUnregisterServer();
}
return hr;
}
So I used primarily the code from the example mentioned above and because it did not work, I changed the code a bit according to my thoughts.
The problem is not the compiling. This works and registration via regsvr32 as well without any errors. But with some event log entries I found out, that DllRegisterServer is the only method which is called. All the other functions (especially the interface implementations for the icons) are not called at all. Although it's not done in the example, I tried to instantiate the Icon class in the DllRegisterServer method in the hope it helps, but I cannot do that (error message: Icon is abstract and cannot be instantiated).
So can anybody tell me, what's going wrong, please?
Thank you so much in advance!

Advanced Installer serial validation DLL

I am working on an installer project in Advanced Installer 10.2. I found out that I can use a DLL for serial validation then I found this resource on their website.
I succeeded in building that DLL, here is my code:
// SerialValidationLib.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "SerialValidationLib.h"
#include <Msi.h>
#include <MsiQuery.h>
#include <MsiDefs.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
HMODULE hModule = ::GetModuleHandle(NULL);
if (hModule != NULL)
{
// initialize MFC and print and error on failure
if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
}
}
else
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
nRetCode = 1;
}
return nRetCode;
}
UINT __stdcall ValidateSerial_Sample(MSIHANDLE hInstall)
{
TCHAR szPidKey[256];
DWORD dwLen = sizeof(szPidKey)/sizeof(szPidKey[0]);
//retrive the text entered by the user
UINT res = MsiGetProperty(hInstall, _T("PIDKEY"), szPidKey, &dwLen);
if(res != ERROR_SUCCESS)
{
//fail the installation
return 1;
}
bool snIsValid = false;
//validate the text from szPidKey according to your algorithm
//put the result in snIsValid
TCHAR * serialValid;
if(snIsValid)
serialValid = _T("TRUE");
else
{
//eventually say something to the user
MessageBox(0, _T("Serial invalid!"), _T("Message"), MB_ICONSTOP);
serialValid = _T("FALSE");
}
res = MsiSetProperty(hInstall, _T("SERIAL_VALIDATION"), serialValid);
if(res != ERROR_SUCCESS)
{
return 1;
}
//the validation succeeded - even the serial is wrong
//if the SERIAL_VALIDATION was set to FALSE the installation
//will not continue
return 0;
}
I also imported it to Advanced Installer, look here:
But when I run the installer, and try to proceed with the installation, after serial insertion point, I get this error message:
Where is my mistake? Does anybody know a good tutorial about this? I searched on the internet, but nothing helps me...
You could have two problems:
either you have typed the method name instead of picking it from the combo loaded by Advanced Installer. In this case the installer fails to call the method from the DLL, as it cannot find it.
or, there is a problem with your code, in which case you need to debug it, as you would do with a normal custom action, attaching from VS (add a mesagebox with a breakpoint after it).