_com_error at memory location 0x00BCF818 due to HRESULT initialization

Sai Prashanth Josyula 1 Reputation point
2021-06-15T03:49:13.12+00:00

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

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,581 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,685 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.