_com_error at memory location 0x00BCF818 due to HRESULT initialization
I am very new to C++ programming and I have to run the below code in order to achieve communication via a COM port to an external device. Most of the below code is regarding what to do once the communication is established ( I assume). I am unable to get the desired output out of the code due to a series of exceptions starting with the following.
Exception thrown by comip.h
Unhandled exception at 0x7597A6F2 in UnmanagedC++Example.exe: Microsoft C++ exception: _com_error at memory location 0x00DBFE48.
Starting part of the code that is actually causing all these errors is :
#include "stdafx.h"
#include "tchar.h"
#include "windows.h"
#include "comip.h"
#import "D:\PhD_Work\NanoPro\CommandsPD4I.tlb" raw_interfaces_only
using namespace CommandsPD4I;
int _tmain(int argc, _TCHAR* argv[])
{
**// Initialize COM.
HRESULT hr = CoInitialize(NULL);**
//And the code goes on....
Kindly give me your inputs. I am working in Visual Studio 2019
Cheers
Prashanth