Click here to Skip to main content
15,890,185 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Help needed with Alphablend function Pin
PJ Arends28-Jun-09 19:48
professionalPJ Arends28-Jun-09 19:48 
QuestionSetting font.. [modified] Pin
kumar sanghvi26-Jun-09 9:53
kumar sanghvi26-Jun-09 9:53 
AnswerRe: Setting font.. Pin
CPallini26-Jun-09 10:06
mveCPallini26-Jun-09 10:06 
GeneralRe: Setting font.. Pin
kumar sanghvi26-Jun-09 10:10
kumar sanghvi26-Jun-09 10:10 
GeneralRe: Setting font.. Pin
CPallini26-Jun-09 10:25
mveCPallini26-Jun-09 10:25 
GeneralRe: Setting font.. Pin
kumar sanghvi26-Jun-09 17:55
kumar sanghvi26-Jun-09 17:55 
GeneralRe: Setting font.. Pin
kumar sanghvi27-Jun-09 2:26
kumar sanghvi27-Jun-09 2:26 
QuestionUsing CoCreateInstance from C to use class in VB DLL [modified] Pin
BeerFizz26-Jun-09 8:08
BeerFizz26-Jun-09 8:08 
Hi all,

I've beating this around for a few days now and I'm totally lost.

I was given a DLL written in VB by a client with the idea of instantiating a class and calling some of the methods. I created a small test app (from code I found here) and attempted to use CoCreateInstance. This worked fine in the code shown below. The client then gave me a more up-to-date version of the DLL and with this new version, CoCreateInstance failed with a E_NOINTERFACE.

I've gone back and forth with the client about this and they have said that it was compiled with the same compiler (really old was the comment) and that all that was changed with the new release was couple of lines of code. They said they had recompiled the DLL under the highest compatibility. A couple of years has gone by since releases, so there may be underlying OS changes, if that would make a difference. They have said they have other users using the DLL without issues, though perhaps not with C/C++.

I modified the code so that instead of using CoCreateInstance, it uses CoGetClassObject and CreateInstance. CreateInstance fails with E_NOINTERFACE, the same error.

I would appreciate all help in understanding how to debug this, bearing in mind that I'm unfamiliar with COM.


This is a snippet from stdafx.h:

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#import "TTExt.dll" no_namespace


This is a snippet from the area where I do the CoCreateInstance:

void CVCClientDlg::OnButton1() 
{
	HRESULT hresult;
	CLSID clsid;

		CoInitialize(NULL);

		hresult=CLSIDFromProgID(OLESTR("TTExt.WebRes"), &clsid);
		if(FAILED(hresult))
		{
			switch (hresult) {
				case CO_E_CLASSSTRING:
					AfxMessageBox("CLSID Failed -- registered CLSID for the ProgID is invalid");
					break;
				case REGDB_E_WRITEREGDB:
					AfxMessageBox("CLSID Failed -- error occurred writing the CLSID to the registry.");
					break;
				default:
					AfxMessageBox("CLSID Failed -- unknown reason");
					break;
			}
		}
		
		_WebRes *wr;
		IClassFactory *pCF;

		hresult=CoGetClassObject(clsid, CLSCTX_INPROC_SERVER, NULL, IID_IClassFactory, (LPVOID *)&pCF);	
		hresult = pCF->CreateInstance(NULL, __uuidof(_WebRes), (LPVOID *)&wr);

		//hresult=CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, __uuidof(_WebRes), (LPVOID *)&wr);
		
		if(FAILED(hresult))
		{
			switch (hresult) {
				case REGDB_E_CLASSNOTREG:
					AfxMessageBox("Creation Failed -- Class not registered");
					break;
				case CLASS_E_NOAGGREGATION:
					AfxMessageBox("Creation Failed -- class cannot be created as part of an aggregate.");
					break;
				case E_NOINTERFACE:
					AfxMessageBox("Creation Failed -- class does not implement the requested interface");
					break;
				case E_POINTER:
					AfxMessageBox("Creation Failed -- ppv parameter is NULL");
					break;
				default:
					AfxMessageBox("Creation Failed -- unknown reason");
					break;
			}
			return;
		}

		//bool bCon = wr->Connect("GEX", "./TeeTimes.ini");
		bool bCon = wr->Connect("GEX", "");

		if (bCon)
			MessageBox("Connect Succceded\n");
		else 
			MessageBox("Connect Failed **********\n");

		wr->Release ();

		CoUninitialize();

}


This is a snippet from the top of the .tlh file:

// Created by Microsoft (R) C/C++ Compiler Version 14.00.50727.42 (2ecf2b05).
//
// c:\documents and settings\phild\my documents\visual studio code\vbdll\vcclient\debug\ttext.tlh
//
// C++ source equivalent of Win32 type library TTExt.dll
// compiler-generated file created 06/24/09 at 17:14:13 - DO NOT EDIT!

#pragma once
#pragma pack(push, 8)

#include <comdef.h>

//
// Forward references and typedefs
//

struct __declspec(uuid("f5171c2c-b846-47bc-8c7f-19658cfc0086"))
/* LIBID */ __TTExt;
struct __declspec(uuid("787d47a3-020f-4b1f-912e-003523277942"))
/* dual interface */ _WebRes;
struct /* coclass */ WebRes;

//
// Smart pointer typedef declarations
//

_COM_SMARTPTR_TYPEDEF(_WebRes, __uuidof(_WebRes));

//
// Type library items
//

struct __declspec(uuid("787d47a3-020f-4b1f-912e-003523277942"))
_WebRes : IDispatch
{
    //
    // Property data
    //


I did a comparison of the .tlh files from the two different versions of the DLL and this is the result:

Compare: (<)C:\Documents and Settings\phild\My Documents\Visual Studio Code\VBDll\VCClient\Debug\tmp\v7.ttext.tlh (10755 bytes)
   with: (>)C:\Documents and Settings\phild\My Documents\Visual Studio Code\VBDll\VCClient\Debug\tmp\v6.ttext.tlh (10755 bytes)

6c6
< // compiler-generated file created 06/26/09 at 13:23:52 - DO NOT EDIT!
---
> // compiler-generated file created 06/26/09 at 13:25:49 - DO NOT EDIT!
17,19c17,19
< struct __declspec(uuid("e897466c-75b0-459f-9512-21d42e1f5703"))
< /* LIBID */ __TTExt;
< struct __declspec(uuid("dc8718c4-d07f-4542-a799-f2015a0614cf"))
---
> struct __declspec(uuid("f5171c2c-b846-47bc-8c7f-19658cfc0086"))
> /* LIBID */ __TTExt;
> struct __declspec(uuid("787d47a3-020f-4b1f-912e-003523277942"))
33c33
< struct __declspec(uuid("dc8718c4-d07f-4542-a799-f2015a0614cf"))
---
> struct __declspec(uuid("787d47a3-020f-4b1f-912e-003523277942"))
311c311
< struct __declspec(uuid("d00de9f1-98eb-4cd9-8685-0ea4f283971f"))
---
> struct __declspec(uuid("0cab506a-1b4d-473f-9a8b-051277ae5603"))


modified on Friday, June 26, 2009 2:32 PM

QuestionRe: Using CoCreateInstance from C to use class in VB DLL Pin
CPallini26-Jun-09 8:58
mveCPallini26-Jun-09 8:58 
AnswerRe: Using CoCreateInstance from C to use class in VB DLL Pin
BeerFizz26-Jun-09 9:30
BeerFizz26-Jun-09 9:30 
GeneralRe: Using CoCreateInstance from C to use class in VB DLL Pin
CPallini26-Jun-09 9:38
mveCPallini26-Jun-09 9:38 
General[Message Deleted] Pin
BeerFizz26-Jun-09 10:00
BeerFizz26-Jun-09 10:00 
GeneralRe: Using CoCreateInstance from C to use class in VB DLL Pin
BeerFizz26-Jun-09 10:06
BeerFizz26-Jun-09 10:06 
QuestionRe: Using CoCreateInstance from C to use class in VB DLL Pin
CPallini26-Jun-09 10:17
mveCPallini26-Jun-09 10:17 
AnswerRe: Using CoCreateInstance from C to use class in VB DLL Pin
BeerFizz26-Jun-09 10:41
BeerFizz26-Jun-09 10:41 
GeneralRe: Using CoCreateInstance from C to use class in VB DLL Pin
CPallini26-Jun-09 11:00
mveCPallini26-Jun-09 11:00 
GeneralRe: Using CoCreateInstance from C to use class in VB DLL Pin
BeerFizz26-Jun-09 11:11
BeerFizz26-Jun-09 11:11 
GeneralRe: Using CoCreateInstance from C to use class in VB DLL Pin
CPallini26-Jun-09 11:21
mveCPallini26-Jun-09 11:21 
GeneralRefresh a form in C++ Builder Pin
David21u226-Jun-09 6:12
David21u226-Jun-09 6:12 
QuestionRe: Refresh a form in C++ Builder Pin
David Crow26-Jun-09 7:29
David Crow26-Jun-09 7:29 
AnswerRe: Refresh a form in C++ Builder Pin
David21u226-Jun-09 7:42
David21u226-Jun-09 7:42 
QuestionRe: Refresh a form in C++ Builder Pin
David Crow26-Jun-09 7:47
David Crow26-Jun-09 7:47 
AnswerRe: Refresh a form in C++ Builder Pin
David21u226-Jun-09 7:55
David21u226-Jun-09 7:55 
AnswerRe: Refresh a form in C++ Builder Pin
David Crow26-Jun-09 7:57
David Crow26-Jun-09 7:57 
GeneralRe: Refresh a form in C++ Builder Pin
David21u226-Jun-09 8:01
David21u226-Jun-09 8:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.