Click here to Skip to main content
15,885,366 members
Home / Discussions / COM
   

COM

 
AnswerRe: call to a com sometimes fails Pin
Md. Marufuzzaman11-Sep-09 4:07
professionalMd. Marufuzzaman11-Sep-09 4:07 
GeneralRe: call to a com sometimes fails Pin
morefalt11-Sep-09 5:17
morefalt11-Sep-09 5:17 
AnswerRe: call to a com sometimes fails Pin
Md. Marufuzzaman11-Sep-09 6:08
professionalMd. Marufuzzaman11-Sep-09 6:08 
QuestionRegistering .NET DLL without regasm [Solved] Pin
hasan03050699-Sep-09 19:29
hasan03050699-Sep-09 19:29 
AnswerRe: Registering .NET DLL without regasm Pin
Md. Marufuzzaman10-Sep-09 6:01
professionalMd. Marufuzzaman10-Sep-09 6:01 
GeneralRe: Registering .NET DLL without regasm Pin
hasan030506911-Sep-09 22:46
hasan030506911-Sep-09 22:46 
GeneralRe: Registering .NET DLL without regasm Pin
Md. Marufuzzaman12-Sep-09 3:46
professionalMd. Marufuzzaman12-Sep-09 3:46 
QuestionCOM Connection Points: Problem to call an function out of an sink class Pin
Juergen_809-Sep-09 2:04
Juergen_809-Sep-09 2:04 
Hi All,

I’m an absolutely newbie in the COM technology and I have a little tricky question. I hope there’s someone out there who can help me with my problem. I have an .idl / .h / .c file and I integrated them in my VisualStudio 2005 C++ project. After that I’ve searched on the MSDN Library how I can connect an COM Server from my project. I’ve found a little example (http://msdn.microsoft.com/en-us/magazine/cc163361.aspx) and tried to do it on the same way. I’ve created an Csink class and tried to create an instance of this sink object to pass to the server. Now I want to call an function „ OnShowMessageDlg “ out of this Csink class and after that I’ll become the following error message from my compiler:
Linker error: LNK2001: unresolved external symbol public: __thiscall ""public: void __thiscall CSink::OnShowMessageDlg(struct IMsgDlg *,short *)" (?OnShowMessageDlg@CSink@@QAEXPAUIMsgDlg@@PAF@Z)".

Can someone give me a hint what there could be wrong? Or what I must do to use these function? Is the .idl file and the .h file correct? I didn’t find the functions OnShowMessageDlg and OnConfigurationApply in the .h file?

I know, this should be basics I must know. I hope the two books I’ve ordered will arrive as soon as possible.

Please let me know if you need any other information.

Thanks for ANY help.

Juergen



*************************************************************************************************
.idl file
.
.
.
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");

// Forward declare all types defined in this typelib
interface ITEST2;
dispinterface ITESTEvents;
.
.
.
[
uuid(6775FB91-B5BE-11D6-A996-0050BA24C7B9),
version(1.1),
helpstring("Event dispatch interface for TEST")
]
dispinterface ITESTEvents {
properties:
methods:
[id(0x00000001)]
void OnConfigurationApply([in, out] VARIANT_BOOL* pAccept);
[id(0x00000002)]
void OnShowMessageDlg(
[in] IMsgDlg* pIMsg,
[out, retval] VARIANT_BOOL* Result);
};
.
.
.
.
coclass TESTv2 {
[default] interface ITEST2;
[default, source] dispinterface ITESTEvents;
};
*************************************************************************************************


.h file
.
.
.
EXTERN_C const IID DIID_ITESTEvents;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("6775FB91-B5BE-11D6-A996-0050BA24C7B9")
ITESTEvents : public IDispatch
{
};

#else /* C style interface */
typedef struct ITESTEventsVtbl
{
BEGIN_INTERFACE

HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
ITESTEvents * This,
/* [in] */ REFIID riid,
/* [iid_is][out] */ void **ppvObject);

.
.
.
*************************************************************************************************

.c file
.
.
.
MIDL_DEFINE_GUID(IID, IID_ITEST2,0xF560F761,0x2948,0x11D7,0xA9,0xBF,0x00,0x50,0xBA,0x24,0xC7,0xB9);

MIDL_DEFINE_GUID(IID, DIID_ITESTEvents,0x6775FB91,0xB5BE,0x11D6,0xA9,0x96,0x00,0x50,0xBA,0x24,0xC7,0xB9);

MIDL_DEFINE_GUID(CLSID, CLSID_TESTv2,0xF560F763,0x2948,0x11D7,0xA9,0xBF,0x00,0x50,0xBA,0x24,0xC7,0xB9);
.
.
.

*************************************************************************************************

.c++ file

class CSink : public ITESTEvents
{
public:

CSink::CSink() {m_cRef = 0;}
CSink::~CSink() {}

HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObject)
{
*ppvObject = NULL;

if (IsEqualGUID(riid, IID_IUnknown))
*ppvObject = reinterpret_cast<void **> (this);

if (IsEqualGUID(riid, DIID_ITESTEvents))
*ppvObject = reinterpret_cast<void **> (this);

if (*ppvObject)
{
((IUnknown*)*ppvObject)->AddRef();
return S_OK;
}
else return E_NOINTERFACE;
}

DWORD __stdcall AddRef()
{
return InterlockedIncrement(&m_cRef);
}

DWORD __stdcall Release()
{
if (InterlockedDecrement(&m_cRef) == 0)
{
delete this;
return 0;
}
return m_cRef;
}

STDMETHOD(GetTypeInfoCount)(unsigned int FAR* pctinfo)
{ return E_NOTIMPL; }
STDMETHOD(GetTypeInfo)(unsigned int iTInfo, LCID lcid,
ITypeInfo FAR* FAR* ppTInfo)
{ return E_NOTIMPL; }
STDMETHOD(GetIDsOfNames)(REFIID riid, OLECHAR FAR* FAR* rgszNames,
unsigned int cNames, LCID lcid, DISPID FAR* rgDispId)
{ return S_OK; }
STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid,
WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
EXCEPINFO * pExcepInfo, UINT * puArgErr)
{

return S_OK;
}



public:
void OnConfigurationApply(VARIANT_BOOL *pAccept);
void OnShowMessageDlg(IMsgDlg *pIMsg, VARIANT_BOOL *Result);

private:
DISPID m_id;
long m_cRef;
};


void main(){
.
.
.
CComPtr<ITEST2> tTEST;
HRESULT hr;
hr = CoInitialize(0);
if(FAILED(hr)){
CoUninitialize();
return false;
}

hr = CoCreateInstance(CLSID_TESTv2, 0, CLSCTX_LOCAL_SERVER, IID_ITEST2, (void**)&tTEST);
IConnectionPointContainer * ICPointContainer;
hr = tTEST->QueryInterface(IID_IConnectionPointContainer,(void **)&ICPointContainer);
if(SUCCEEDED(hr)){
//CComPtr<IConnectionPoint> ICPoint;
hr = ICPointContainer->FindConnectionPoint(DIID_ITESTEvents, &ICPoint);
if(SUCCEEDED(hr)){
ICPointContainer->Release();

CSink *pSink;
IUnknown *pSinkUnk;
pSink = new CSink;


hr = pSink->QueryInterface (IID_IUnknown,(void **)&pSinkUnk);
hr = ICPoint->Advise(pSinkUnk,&dwAdvise);

VARIANT_BOOL *tDLGResult;
pSink->AddRef();
pSink->OnShowMessageDlg(tMsgDlg, tDLGResult); // ERROR MESSAGE
.
.
}

*************************************************************************************************
AnswerRe: COM Connection Points: Problem to call an function out of an sink class Pin
Jürgen Jung9-Sep-09 3:38
Jürgen Jung9-Sep-09 3:38 
QuestionRe: COM Connection Points: Problem to call an function out of an sink class Pin
Juergen_809-Sep-09 4:59
Juergen_809-Sep-09 4:59 
AnswerRe: COM Connection Points: Problem to call an function out of an sink class Pin
Stuart Dootson9-Sep-09 10:31
professionalStuart Dootson9-Sep-09 10:31 
QuestionShell Extension + COM permission Pin
Kedrr8-Sep-09 2:25
Kedrr8-Sep-09 2:25 
QuestionCOM Connection Points: Problem to create an instance of an sink object. Pin
Juergen_808-Sep-09 0:01
Juergen_808-Sep-09 0:01 
AnswerRe: COM Connection Points: Problem to create an instance of an sink object. Pin
Stuart Dootson8-Sep-09 3:34
professionalStuart Dootson8-Sep-09 3:34 
AnswerRe: COM Connection Points: Problem to create an instance of an sink object. Pin
Juergen_808-Sep-09 4:07
Juergen_808-Sep-09 4:07 
QuestionHow to control Hide/Show of Custom Toolbar in Windows 2000 OS Pin
am 20096-Sep-09 23:59
am 20096-Sep-09 23:59 
QuestionHow to pass session to a new IE window in the method OnNewWindow2 Pin
sun_key6-Sep-09 17:10
sun_key6-Sep-09 17:10 
QuestionHow to Hide Custome Toolbar from IE6, IE7 ,IE8 Pin
am 20093-Sep-09 21:23
am 20093-Sep-09 21:23 
QuestionHow to use #import for different Windows OS version Pin
am 200931-Aug-09 23:34
am 200931-Aug-09 23:34 
AnswerRe: How to use #import for different Windows OS version Pin
Stuart Dootson1-Sep-09 2:15
professionalStuart Dootson1-Sep-09 2:15 
GeneralRe: How to use #import for different Windows OS version Pin
am 20091-Sep-09 2:48
am 20091-Sep-09 2:48 
GeneralRe: How to use #import for different Windows OS version Pin
Stuart Dootson1-Sep-09 2:54
professionalStuart Dootson1-Sep-09 2:54 
GeneralRe: How to use #import for different Windows OS version Pin
am 20091-Sep-09 3:25
am 20091-Sep-09 3:25 
GeneralRe: How to use #import for different Windows OS version Pin
Stuart Dootson1-Sep-09 4:46
professionalStuart Dootson1-Sep-09 4:46 
QuestionGetting crash while copying a VARIANT type to _variant_t type, Pin
Kundan Kumar Bharti30-Aug-09 20:14
Kundan Kumar Bharti30-Aug-09 20:14 

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.