activex控件调用dll问题

做一个网页端写RF卡的功能,RF卡厂方只提供了个dll文件,这个dll是个activex,

但返回值是通过引用参数返回的,所以js没法拿到结果(方法是可以调用成功的),

所以想自己再写个activex对其封装下,将结果通过return返回

自己的activex控件采用MFC ActiveX框架建的,写的测试方法也OK了,但在调用厂方的dll时不成功,

BSTR CRFCardCtrl::test(LPCTSTR inStr, LONG inInt)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
BSTR v = NULL;

HINSTANCE hDllInst = LoadLibraryEx(L"C:\\Users\\admin\\Desktop\\ActiveX\\RFCard\\Debug\\XX.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
DWORD dw = 0;
if(hDllInst){
    typedef long (__stdcall *MYFUNC)(BSTR*);
    MYFUNC youFuntionNameAlias = NULL; // youFuntionNameAlias 函数别名
    youFuntionNameAlias = (MYFUNC)GetProcAddress(hDllInst,"GetDLLVersion_U");
    // youFuntionName 在DLL中声明的函数名
    if(youFuntionNameAlias)
    {
        youFuntionNameAlias(&v);
    }
    else
    {
        CString str;
        str.Format(L"error=%d",dw);
        v = str.AllocSysString();
    }
    FreeLibrary(hDllInst);
}
else
{
    CString str;
    str.Format(L"error=%d",dw);
    v = str.AllocSysString();
}
return v;

}

这是自己activex控件里的测试方法,GetDLLVersion_U是dll中的方法,com接口中的名字叫GetDLLVersion(这儿多了个_U不知为什么)

错位在youFuntionNameAlias(&v);这个语句

调用堆栈:

mfc110ud.dll!AFX_MAINTAIN_STATE2::~AFX_MAINTAIN_STATE2() 行 101    C++
RFCard.ocx!CRFCardCtrl::test(const wchar_t * inStr, long inInt) 行 228 C++
mfc110ud.dll!_AfxDispatchCall(void (void) * __formal, void * __formal, unsigned int __formal) 行 40    C++
mfc110ud.dll!CCmdTarget::CallMemberFunc(const AFX_DISPMAP_ENTRY * pEntry, unsigned short wFlags, tagVARIANT * pvarResult, tagDISPPARAMS * pDispParams, unsigned int * puArgErr) 行 1070    C++
mfc110ud.dll!COleDispatchImpl::Invoke(long dispid, const _GUID & riid, unsigned long lcid, unsigned short wFlags, tagDISPPARAMS * pDispParams, tagVARIANT * pvarResult, tagEXCEPINFO * pexcepinfo, unsigned int * puArgErr) 行 1518    C++

报错语句:

afxstate.cpp

#ifdef _AFXDLL
// Not a good place to report errors here, so just be safe
if(m_pThreadState)
{
m_pThreadState->m_pModuleState = m_pPrevModuleState;(调试定位在这一句)
}
#endif

请教大神这个问题怎么解决?或者我的调用方法错了,要用调用COM组件的调用方法或者其他调用方法?

com组件是用CoCreateInstance来创建实例,然后QueryInterface获取接口来调用

要用com的方式,需要先初始化