fungi8210
asked on
data conversion error when assigning function to function pointer
Hi Experts,
I am trying to assign a function to a function pointer member in CFactoryTemplate, which is a class from directshow SDK
this is the class that i wrote:
class CMYFilter: public CTransInPlaceFilter
{
public:
CUnknown * WINAPI CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr);
};
What i am trying to do is assign CreateInstance to a member of type
LPFNNewCOMObject
which has its original declaration as
typedef CUnknown *(CALLBACK *LPFNNewCOMObject)(LPUNKNO WN pUnkOuter, HRESULT *phr);
the assignment is shown here:
CFactoryTemplate g_Templates[1] =
{
{
g_wszName,
&CLSID_CMYFilter,
CMYFilter::CreateInstance, // line with error
NULL,
NULL
}
};
I kept receiving this error message at the line CMYFilter::CreateInstance.
error C2440: 'initializing' : cannot convert from 'CUnknown *(__cdecl
CMYFilter::* )(LPUNKNOWN,HRESULT *)' to 'LPFNNewCOMObject'
1> None of the functions with this name in scope match the target type
This is very strange since all the sample codes, including those came with
SDK, were written like this.
Is there any reason why this is happening?
thanks!
I am trying to assign a function to a function pointer member in CFactoryTemplate, which is a class from directshow SDK
this is the class that i wrote:
class CMYFilter: public CTransInPlaceFilter
{
public:
CUnknown * WINAPI CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr);
};
What i am trying to do is assign CreateInstance to a member of type
LPFNNewCOMObject
which has its original declaration as
typedef CUnknown *(CALLBACK *LPFNNewCOMObject)(LPUNKNO
the assignment is shown here:
CFactoryTemplate g_Templates[1] =
{
{
g_wszName,
&CLSID_CMYFilter,
CMYFilter::CreateInstance,
NULL,
NULL
}
};
I kept receiving this error message at the line CMYFilter::CreateInstance.
error C2440: 'initializing' : cannot convert from 'CUnknown *(__cdecl
CMYFilter::* )(LPUNKNOWN,HRESULT *)' to 'LPFNNewCOMObject'
1> None of the functions with this name in scope match the target type
This is very strange since all the sample codes, including those came with
SDK, were written like this.
Is there any reason why this is happening?
thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
BTW, a factory function also does not need to be a non-static member.
ASKER
i just added static to it, now i am getting these errors
error LNK2001: unresolved external symbol "public: static class CUnknown * __cdecl CFPSFilter::CreateInstance (struct IUnknown *,long *)" (?CreateInstance@CFPSFilte r@@SAPAVCU nknown@@PA UIUnknown@ @PAJ@Z)
error LNK2001: unresolved external symbol CLSID_FPSFilter
1>Windows Mobile 6 Professional SDK (ARMV4I)\Debug/MyFilter.dl l : fatal error LNK1120: 2 unresolved externals
just incase you are wondering, i'm trying to write a directshow filter, and CLSID_FPSFilter is my classid defined at the top
// {033104B2-2AA9-4476-992E-A B504F9F1F1 E}
DEFINE_GUID(CLSID_FPSFilte r,
0x33104b2, 0x2aa9, 0x4476, 0x99, 0x2e, 0xab, 0x50, 0x4f, 0x9f, 0x1f, 0x1e);
btw, you answered my question correctly, you'll get the points, just wondering if you know how to solve my second problem, thanks!
error LNK2001: unresolved external symbol "public: static class CUnknown * __cdecl CFPSFilter::CreateInstance
error LNK2001: unresolved external symbol CLSID_FPSFilter
1>Windows Mobile 6 Professional SDK (ARMV4I)\Debug/MyFilter.dl
just incase you are wondering, i'm trying to write a directshow filter, and CLSID_FPSFilter is my classid defined at the top
// {033104B2-2AA9-4476-992E-A
DEFINE_GUID(CLSID_FPSFilte
0x33104b2, 0x2aa9, 0x4476, 0x99, 0x2e, 0xab, 0x50, 0x4f, 0x9f, 0x1f, 0x1e);
btw, you answered my question correctly, you'll get the points, just wondering if you know how to solve my second problem, thanks!
You'll need to provide an implementation also, e.g.
static CUnknown * WINAPI CMYFilter::CreateInstance( LPUNKNOWN pUnk, HRESULT *pHr) {
CMYFilter* p = NULL;
// other code to create a 'CMYFilter' here...
return p;
}
static CUnknown * WINAPI CMYFilter::CreateInstance(
CMYFilter* p = NULL;
// other code to create a 'CMYFilter' here...
return p;
}
Sorry, that should have been
CUnknown * WINAPI CMYFilter::CreateInstance( LPUNKNOWN pUnk, HRESULT *pHr) {
CMYFilter* p = NULL;
// other code to create a 'CMYFilter' here...
return (CUnknown*) p;
}
CUnknown * WINAPI CMYFilter::CreateInstance(
CMYFilter* p = NULL;
// other code to create a 'CMYFilter' here...
return (CUnknown*) p;
}
ASKER
thanks, one last error
CMYFilter.obj : error LNK2001: unresolved external symbol CLSID_CMYFilter
1>Windows Mobile 6 Professional SDK (ARMV4I)\Debug/MyFilter.dl l : fatal error LNK1120: 1 unresolved externals
its weird because i defined CLSID_CMYFilter at the top
// {033104B2-2AA9-4476-992E-A B504F9F1F1 E}
DEFINE_GUID(CLSID_CMYFilte r,
0x33104b2, 0x2aa9, 0x4476, 0x99, 0x2e, 0xab, 0x50, 0x4f, 0x9f, 0x1f, 0x1e);
CMYFilter.obj : error LNK2001: unresolved external symbol CLSID_CMYFilter
1>Windows Mobile 6 Professional SDK (ARMV4I)\Debug/MyFilter.dl
its weird because i defined CLSID_CMYFilter at the top
// {033104B2-2AA9-4476-992E-A
DEFINE_GUID(CLSID_CMYFilte
0x33104b2, 0x2aa9, 0x4476, 0x99, 0x2e, 0xab, 0x50, 0x4f, 0x9f, 0x1f, 0x1e);
>>its weird because i defined CLSID_CMYFilter at the top
Yes, but for that to be expanded to also an implementation (not just a declaration) you'll need to
#define INITGUID
before
#include <objbase.h>
Yes, but for that to be expanded to also an implementation (not just a declaration) you'll need to
#define INITGUID
before
#include <objbase.h>