Solved

C++ CreateInstance(__uuidof(Recordset))  returns E_NOINTERFACE

Posted on 2011-09-15
3
2,145 Views
Last Modified: 2012-05-12

Hi,

I have a piece code which I wrote several years ago.

This code was written on a XP system and most likely with VS2003 or possibly VS2005.

The code worked fine and in fact the existing .exe still works fine.

The code was designed to sit on a remote machine and act as a server.   Based upon requests, it would communicate with a third party database interface on the remote machine and respond with data to its clients.

The portion of code which does the ADO resides in a dll.   The main portion of the code manages the communications with the clients and calls functions in the ADO dll as required.



I recently moved this code over to a windows 7 machine and compiled the main portion of the code using VS2005 and linking with the dll which does the ADO.   I did not at this time recompile the ADO dll.

When I moved the .exe over to the target machine, the code worked just fine as expected.

I then recompiled the ADO dll as well as the main code again and linked.   I move the code over to the target machine and this time I get an E_NOINTERFACE error.

The code still still CoInitialize's and connects just fine.  Its the call to:

      hresult = ptrRS.CreateInstance(__uuidof(Recordset));

which fails.

I have included what I think are the relevant portions of code as well as the output from my trace calls.

I have checked the folder and I have the msado15 tlh and tli as well as the tlh and tli for ttext.

in stdafx.h I have:

#import "..\IBS DLL's\dll7303\TTExt.dll" no_namespace

Can anyone give me any ideas as to what is wrong or guide me in finding a solution?

Thanks for all help in advance
Phil



#include "stdafx.h"


#include <string>

using namespace std;

#include "dbAccess.h"

#include "XYTrace.h"
#pragma comment(lib,"trace.lib")


#include "ATLComTime.h"
#include <comdef.h>
#include "Afxdisp.h"

#include <ole2.h>

#import "C:\Program Files\Common Files\System\ADO\msado15.dll" rename("EOF", "ADOEOF") rename("Property", "PProperty")


/////////////////////////////////////////////////////////////////////////////
//
//	Globals
//
/////////////////////////////////////////////////////////////////////////////
_WebRes			*wr;
HRESULT			hresult;
using			namespace ADODB;
_RecordsetPtr	ptrRS;

.....
.....
.....


/////////////////////////////////////////////////////////////////////////////
//
//	ibsConnect
//
/////////////////////////////////////////////////////////////////////////////
bool ibsConnect(char *userid, char *iniPath)
{
	CLSID clsid;

	hresult = CoInitialize(NULL);
	WriteTrace(TraceXDetail, "CoInitialize returned %x", hresult);
	if(FAILED(hresult)) {
		WriteTrace(TraceError, "****  CoInitialize Failed ");
		return false;
	}
	hresult=CLSIDFromProgID(OLESTR("TTExt.WebRes"), &clsid);
	WriteTrace(TraceXDetail, "CLSIDFromProgID returned %x", hresult);
	if(FAILED(hresult))
	{
		switch (hresult) {
			case CO_E_CLASSSTRING:
				WriteTrace(TraceError, "****  CLSID Failed -- registered CLSID for the ProgID is invalid");
				return false;
				break;
			case REGDB_E_WRITEREGDB:
				WriteTrace(TraceError, "****  CLSID Failed -- error occurred writing the CLSID to the registry.");
				return false;
				break;
			default:
				WriteTrace(TraceError, "****  CLSID Failed -- unknown reason");
				return false;
				break;
		}
	}
		
	hresult=CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, __uuidof(_WebRes), (LPVOID *)&wr);
	WriteTrace(TraceXDetail, "CoCreateInstance returned %x", hresult);
	if(FAILED(hresult))
	{
		switch (hresult) {
			case REGDB_E_CLASSNOTREG:
				WriteTrace(TraceError, "****  CoCreateInstance Failed -- Class not registered");
				return false;
				break;
			case CLASS_E_NOAGGREGATION:
				WriteTrace(TraceError, "****  CoCreateInstance Failed -- class cannot be created as part of an aggregate.");
				return false;
				break;
			case E_NOINTERFACE:
				WriteTrace(TraceError, "****  CoCreateInstance Failed -- class does not implement the requested interface");
				return false;
				break;
			case E_POINTER:
				WriteTrace(TraceError, "****  CoCreateInstance Failed -- ppv parameter is NULL");
				return false;
				break;
			case 0x8007007e:
				WriteTrace(TraceError, "****  CoCreateInstance Failed -- the specified module could not be found");
				return false;
			default:
				WriteTrace(TraceError, "****  CoCreateInstance Failed -- unknown reason - hresult |%x|", hresult);
				return false;
				break;
		}
		return true;
	}

	
	BSTR	bstrMess = NULL;
	char	cStr[256];
	strcpy(cStr, "OK");
	bstrMess = A2BSTR(cStr);

	strcpy(iniPath, "");
	WriteTrace(TraceInfo, "Connecting to IBS database with userid '%s' and ini path '%s'", userid, iniPath);
#	ifdef gt_DLL7302
	if (!wr->Connect(LPCSTR(userid), LPCSTR(iniPath), &bstrMess)) {
#	else
	if (!wr->Connect(LPCSTR(userid), "")) {
#	endif
		WriteTrace(TraceError, "****  TTExt Connect Failed");
		USES_CONVERSION;
		strcpy(errorMess, (W2A(bstrMess)));
		WriteTrace(TraceError, "CONNECT:  return message - '%s'", errorMess);
		SysFreeString(bstrMess);
		return false;
	}

	WriteTrace(TraceXDetail, "CONNECT:  returned");
	USES_CONVERSION;
	strcpy(errorMess, (W2A(bstrMess)));
	WriteTrace(TraceXDetail, "CONNECT:  return message - '%s'", errorMess);
	SysFreeString(bstrMess);


	if (!wr->SetUser(LPCSTR(userid))) {
		WriteTrace(TraceError, "****  TTExt SetUser Failed");
		return false;
	}
	WriteTrace(TraceXDetail, "IBS TTExt SetUser succeeded with userid='%s'", userid);


	hresult = ptrRS.CreateInstance(__uuidof(Recordset));
	if(FAILED(hresult)) {
		WriteTrace(TraceError, "****  ptrRS.CreateInstance Recordset Failed '%x'", hresult);
		return false;
	}

	return true;
}

......
......



//  output from the Trace....


17:45:59_472_D20: Starting GEX Server (Version 1.9.13)
17:45:59_472_D20: 		for ttext.dll Version (DLL 7303)
17:45:59_472_D20: Application name gexServer
17:45:59_472_D20: Parameter: Server listening port:'999'
17:45:59_472_D20: Parameter: Server trace option: 'trace'
17:45:59_492_D20: CoInitialize returned 0
17:45:59_492_D20: CLSIDFromProgID returned 0
17:45:59_502_D20: CoCreateInstance returned 0
17:45:59_502_D20: Connecting to IBS database with userid 'GEX' and ini path ''
17:46:00_013_D20: CONNECT:  returned
17:46:00_013_D20: CONNECT:  return message - 'OK'
17:46:00_013_D20: IBS TTExt SetUser succeeded with userid='GEX'
17:46:00_013_D20: ****  ptrRS.CreateInstance Recordset Failed '80004002'
17:46:00_013_D20: ****  IBS Server connect Failed -- exiting
17:46:00_013_D20: Exiting GEX Server

Open in new window

0
Comment
Question by:BeerFizz
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
senad earned 500 total points
ID: 36593674
is this x32 or x64 windows 7 system ?
could be UAC,could be unregistered dll ...
also visual studio 2005 needs  a service pack
http://www.microsoft.com/download/en/details.aspx?id=7524
to function under W7.
0
 

Author Comment

by:BeerFizz
ID: 36816203

Hi Senad,

I apologize for taking so long to get back to you.

I downloaded and installed the service pack for VS2005.  I ran VS2005 as admin and recompiled my code.   Same error.

The installation of win7 on my development machine is indeed a 64bit install.   The code I am developing is 32bit and the target machine is 32bit.   Is there a switch I need to turn on or off?

Thanks for you help
Phil



0
 

Author Closing Comment

by:BeerFizz
ID: 36910015
senad,

thank you for your response and I apologize for how long it took me to get back.  I had to get info of the target machine and there were issues with that.

I am going to reframe my question and ask it again, if you would be so kind to look.

I will call it "C++ Com Problem".

Thanks
Phil
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now