• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2188
  • Last Modified:

C++ Com Problem

Hi,

I have a piece code which I wrote several years ago. This code was written on a XP system with VS2005.

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

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.

Now, this code seems to work on some machines and not on others.  I suspect the difference between target machines in 32 or 64 bit, though that may be totally wrong...

On machines where it does not work I get an E_NOINTERFACE error.

The code will 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 also attached a listing of CLSID's on my development machine, a machine on which it works and a machine in which it fails.   My development machine is XP, 32 bit.   The machine on which it fails is Windows 2008 Server R2 64-Bit.

Thanks for all help in advance
Phil webres-ole-Gimli.txt webres-ole-Gimli.txt webres-ole-spider.txt  webres-ole-target.txt
#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
BeerFizz
Asked:
BeerFizz
  • 6
  • 4
1 Solution
 
QlemoC++ DeveloperCommented:
0x80004002 is "No Interface", which seems to be an issue wth the CLSID registration, though I only found reference in conjunction with ADODB::Connection, not ADODB::Recordset. Maybe this pointer helps:
http://blogs.msdn.com/b/farukcelik/archive/2011/03/16/regdb-e-classnotreg-0x80040154-e-pointer-0x80004003-e-nointerface-0x80004002-unable-to-cast-com-object-of-type-system-comobject-to-interface-type-adodb-connection-error-codes-messages.aspx.
0
 
BeerFizzAuthor Commented:
Hi Qlemo,

Thanks for the response.    Looked at the link and its not much help.

I have attached the CLSID's for my dev machine, a machine that works and the machine which does not.  They seem to be the same or similar.

The other thing that no-interface may be about is the service that is offered, "in proc" or 'out proc", but I'm not sure what that means.

Phil
0
 
QlemoC++ DeveloperCommented:
"in proc" means that it is hosted by the service shell itself, as for example the network services are (in svchost). "out proc" will start a new process.
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
BeerFizzAuthor Commented:
"in proc" means that it is hosted by the service shell itself, as for example the network services are (in svchost). "out proc" will start a new process.

Ok... not sure how that might affect the no-interface.


In the code the 'cocreateinstance' works fine, and the 'logging in' also works.

But then the createinstance of the recordset fails.

Any thoughts on how i might track this down?
0
 
QlemoC++ DeveloperCommented:
Not the slightest idea else what could be the issue. As a first step I would try to track the __uuidof(Recordset) - does it return a valid CLSID?
0
 
BeerFizzAuthor Commented:
Ok, will try that and report back.
0
 
BeerFizzAuthor Commented:

OK.

I made the code changes as follows:

	CLSID rs;
	LPOLESTR lpolestr;
	
	WriteTrace(TraceXDetail, "Performing CreateInstance(__uuidof(Recordset)");

	rs = __uuidof(Recordset);
	WriteTrace(TraceError, "    recordset: data1 '%d'", rs.Data1);
	
	StringFromCLSID(rs, &lpolestr);
	strcpy_s(mess, (W2A(lpolestr)));
	WriteTrace(TraceError, "    StringFromCLSID '%s'", mess);
	CoTaskMemFree(lpolestr);


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

Open in new window



and I ran it on two of my machines, with pretty much the same result...

XP machine on which the code was developed:

11:42:40_857_1620: Starting GEX Server (Version 1.9.13)
11:42:40_857_1620: 		for ttext.dll Version (DLL 7303.001)
11:42:40_857_1620: 		dbAccess Version (1.004)
11:42:40_857_1620: Application name c:\Documents and Settings\phild\My Documents\Visual Studio 2005\Projects\gex\server\Debug\server.exe
11:42:40_857_1620: Parameter: Server listening port:'999'
11:42:40_857_1620: Parameter: Server trace option: 'trace'
11:42:42_466_1620: CoInitialize returned 0
11:42:42_466_1620: Performing CreateInstance(__uuidof(Recordset)
11:42:42_466_1620:     recordset: data1 '1333'
11:42:42_466_1620:     StringFromCLSID '{00000535-0000-0010-8000-00AA006D2EA4}'
11:42:42_622_1620: CreateInstance(__uuidof(Recordset) was successful

Open in new window



and then on a Windows 7 machine:

12:19:25_607_2D94: Starting GEX Server (Version 1.9.13)
12:19:25_608_2D94: 		for ttext.dll Version (DLL 7303.001)
12:19:25_608_2D94: 		dbAccess Version (1.004)
12:19:25_608_2D94: Application name gexServer
12:19:25_608_2D94: Parameter: Server listening port:'999'
12:19:25_608_2D94: Parameter: Server trace option: 'trace'
12:19:25_611_2D94: CoInitialize returned 0
12:19:25_611_2D94: Performing CreateInstance(__uuidof(Recordset)
12:19:25_611_2D94:     recordset: data1 '1333'
12:19:25_611_2D94:     StringFromCLSID '{00000535-0000-0010-8000-00AA006D2EA4}'
12:19:26_321_2D94: CreateInstance(__uuidof(Recordset) was successful

Open in new window



Both of these machines appear to return a valid record set.

I am still awaiting the results from the target machine where it fails.   As soon as I have those I will post them.

Thanks again for your continued assistance.
Phil


0
 
BeerFizzAuthor Commented:

ok, this is from the target machine which is a Windows 2008 Server....  BUT, see my next post.

12:29:25_122_280: Starting GEX Server (Version 1.9.13)
12:29:25_122_280: 		for ttext.dll Version (DLL 7303.001)
12:29:25_122_280: 		dbAccess Version (1.004)
12:29:25_122_280: Application name gexserver.exe
12:29:25_122_280: Parameter: Server listening port:'9999'
12:29:25_122_280: Parameter: Server trace option: 'trace'
12:29:25_122_280: CoInitialize returned 0
12:29:25_122_280: Performing CreateInstance(__uuidof(Recordset)
12:29:25_122_280:     recordset: data1 '1333'
12:29:25_122_280:     StringFromCLSID '{00000535-0000-0010-8000-00AA006D2EA4}'
12:29:25_122_280: CreateInstance(__uuidof(Recordset) was successful
12:29:25_122_280: CLSIDFromProgID returned 0
12:29:25_122_280: CoCreateInstance returned 80040154
12:29:25_122_280: ****  CoCreateInstance Failed -- Class not registered
12:29:25_122_280: ****  IBS Server connect Failed -- exiting
12:29:25_122_280: Exiting GEX Server

Open in new window


Here again the CLSID looks good... see next post
0
 
BeerFizzAuthor Commented:

I think this may be the problem and the solution:

http://support.microsoft.com/kb/2517589



Consider the following scenario. On a computer that is running Windows 7 Service Pack 1 (SP1) or Windows Server 2008 R2 SP 1 or that has KB9823246 installed, you recompile a Microsoft ActiveX Data Objects (ADO) application by using one of the following applications:

    Microsoft Visual C++


This issue occurs because some ADO interfaces were changed in Windows 7 SP1 to be associated with new instance identifiers (IIDs). The older IID interfaces were assigned the following suffix:
_Deprecated
For example, the interface _Connection was updated as follows:

    In Windows 7 and in earlier versions of Windows, the _Connection IID is 00000550-0000-0010-8000-00AA006D2EA4.
    In Windows 7 SP1, the _Connection IID is 00001550-0000-0010-8000-00AA006D2EA4, and the IID for _Connection_Deprecated is 00000550-0000-0010-8000-00AA006D2EA4.
0
 
QlemoC++ DeveloperCommented:
That is what I pointed to indirectly in http:#a36910354, and I thought you've dismissed that already.
0
 
LeeTutorretiredCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now