How do I make use of HRESULT and cast it into my own Object?

In the class StubRequest, I have a method doSomething().

1. How do I convert HRESULT into StubRequest
2. How do I call the doSomething() method?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <string>
#include <windows.h>
#include "tchar.h"
#include "Initialiser.h"

#import "TestZ.tlb" raw_interfaces_only

using namespace TestZ;


int _tmain(int argc, _TCHAR* argv[])
{
	// Initialize COM.
	HRESULT hr = CoInitialize(NULL);

	// Create the interface pointer.
	_StubRequestPtr stubPtr(__uuidof(StubRequest));
	_StubRequestPtr stubRequest = stubPtr.CreateInstance(__uuidof(StubRequest));
	
	stubRequest->doSomething();//causes error. when all it does is to print to console.
	CoUninitialize();
	return 0;
}
Last edited on
An HRESULT is just an integer indicating whether the function failed and, if it did, what the error was.

I recommend searching for a tutorial on COM programming.
Topic archived. No new replies allowed.