Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-15
3
Medium Priority
?
2,419 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
senad earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
IF you are either unfamiliar with rootkits, or want to know more about them, read on ....
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Suggested Courses

719 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